tui_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package pingo
  2. import (
  3. "testing"
  4. "time"
  5. tea "github.com/charmbracelet/bubbletea"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func Test_InitialModel(t *testing.T) {
  9. model := InitialModel([]string{"test"}, time.Duration(time.Second*1), 10)
  10. assert.True(t, len(model.Addresses) == 1)
  11. assert.True(t, model.viewport.Width == 0)
  12. assert.Equal(t, model.UpdateSpeed, time.Duration(time.Second*1))
  13. assert.Equal(t, model.ChartHeight, 10)
  14. }
  15. func Test_Model_Init(t *testing.T) {
  16. testModel := Model{}
  17. result := testModel.Init()
  18. assert.IsType(t, new(tea.Cmd), &result)
  19. result2 := result()
  20. assert.IsType(t, new(tea.Msg), &result2)
  21. _, ok := result2.(tickMsg)
  22. assert.True(t, ok)
  23. }
  24. func Test_Model_Update_window_resize(t *testing.T) {
  25. testMsg := tea.WindowSizeMsg{Width: 10, Height: 10}
  26. model := tea.Model(InitialModel([]string{"test"}, time.Duration(time.Second*1), 10))
  27. assert.Equal(t, 0, model.(Model).width)
  28. assert.Equal(t, 0, model.(Model).viewport.YPosition)
  29. assert.Equal(t, 1, len(model.(Model).Addresses))
  30. assert.Equal(t, 80, model.(Model).Addresses[0].max_results)
  31. model, _ = model.Update(testMsg)
  32. assert.Equal(t, 10, model.(Model).width)
  33. assert.Equal(t, 10, model.(Model).viewport.Width)
  34. assert.Equal(t, 6, model.(Model).viewport.Height)
  35. assert.Equal(t, 1, model.(Model).viewport.YPosition)
  36. assert.Equal(t, 10, model.(Model).Addresses[0].max_results)
  37. }
  38. func Test_Model_Update_keymsg_j(t *testing.T) {
  39. t.Skip()
  40. testKey := tea.Key{Type: tea.KeyRunes, Runes: []rune{'j'}}
  41. testMsg := tea.KeyMsg(testKey)
  42. model := tea.Model(InitialModel([]string{"127.0.0.1", "127.0.0.1"}, time.Duration(time.Second*1), 0))
  43. scrollPercent := model.(Model).viewport.ScrollPercent()
  44. var msgs []tea.Msg
  45. var cmd tea.Cmd
  46. model, cmd = model.Update(tea.WindowSizeMsg{Width: 100, Height: 2000})
  47. if cmd != nil {
  48. msgs = append(msgs, cmd())
  49. }
  50. msgs = append(msgs, testMsg)
  51. model, _ = model.Update(msgs)
  52. assert.NotEqual(t, scrollPercent, model.(Model).viewport.ScrollPercent())
  53. }
  54. func Test_Model_View(t *testing.T) {}
  55. func Test_Model_content(t *testing.T) {}
  56. func Test_Model_Poll(t *testing.T) {}