|
1 | 1 | package states_test
|
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + tea "github.com/charmbracelet/bubbletea" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + |
| 9 | + "github.com/initia-labs/weave/states" |
| 10 | +) |
| 11 | + |
| 12 | +func TestInitiaInitNavigation(t *testing.T) { |
| 13 | + states.ResetStates() // Optional: Reset at package initialization if needed for all tests |
| 14 | + home := states.GetHomePage() |
| 15 | + |
| 16 | + init, _ := home.Update(tea.KeyMsg{Type: tea.KeyEnter}) |
| 17 | + |
| 18 | + assert.IsType(t, &states.InitiaInit{}, init) |
| 19 | + |
| 20 | + initState, ok := init.(*states.InitiaInit) |
| 21 | + assert.True(t, ok) |
| 22 | + |
| 23 | + assert.Equal(t, 0, initState.Cursor) |
| 24 | + |
| 25 | + _, _ = init.Update(tea.KeyMsg{Type: tea.KeyDown}) |
| 26 | + assert.Equal(t, 1, initState.Cursor) |
| 27 | + |
| 28 | + _, _ = init.Update(tea.KeyMsg{Type: tea.KeyUp}) |
| 29 | + assert.Equal(t, 0, initState.Cursor) |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | +func TestRunL1NodeNavigation(t *testing.T) { |
| 34 | + states.ResetStates() // Optional: Reset at package initialization if needed for all tests |
| 35 | + home := states.GetHomePage() |
| 36 | + |
| 37 | + init, _ := home.Update(tea.KeyMsg{Type: tea.KeyEnter}) |
| 38 | + |
| 39 | + assert.IsType(t, &states.InitiaInit{}, init) |
| 40 | + |
| 41 | + initState, _ := init.(*states.InitiaInit) |
| 42 | + |
| 43 | + _, _ = init.Update(tea.KeyMsg{Type: tea.KeyDown}) |
| 44 | + assert.Equal(t, 1, initState.Cursor) |
| 45 | + |
| 46 | + _, _ = init.Update(tea.KeyMsg{Type: tea.KeyUp}) |
| 47 | + assert.Equal(t, 0, initState.Cursor) |
| 48 | + |
| 49 | + runL1Node, _ := initState.Update(tea.KeyMsg{Type: tea.KeyEnter}) |
| 50 | + |
| 51 | + _, ok := runL1Node.(*states.RunL1Node) |
| 52 | + assert.True(t, ok) |
| 53 | +} |
| 54 | + |
| 55 | +func TestLaunchMinitiaNavigation(t *testing.T) { |
| 56 | + states.ResetStates() // Optional: Reset at package initialization if needed for all tests |
| 57 | + home := states.GetHomePage() |
| 58 | + |
| 59 | + init, _ := home.Update(tea.KeyMsg{Type: tea.KeyEnter}) |
| 60 | + |
| 61 | + assert.IsType(t, &states.InitiaInit{}, init) |
| 62 | + |
| 63 | + initState, _ := init.(*states.InitiaInit) |
| 64 | + |
| 65 | + _, _ = init.Update(tea.KeyMsg{Type: tea.KeyDown}) |
| 66 | + assert.Equal(t, 1, initState.Cursor) |
| 67 | + |
| 68 | + launchMinitia, _ := initState.Update(tea.KeyMsg{Type: tea.KeyEnter}) |
| 69 | + |
| 70 | + _, ok := launchMinitia.(*states.LaunchNewMinitia) |
| 71 | + assert.True(t, ok) |
| 72 | +} |
0 commit comments