Skip to content

Commit acf17ac

Browse files
committed
feat: add navigation test
1 parent 24f772f commit acf17ac

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

states/state.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import (
44
tea "github.com/charmbracelet/bubbletea"
55
)
66

7+
// Example Reset function for all states:
8+
func ResetStates() {
9+
homePageInstance = nil
10+
InitiaInitInstance = nil
11+
runL1NodeInstance = nil
12+
launchNewMinitiaInstance = nil
13+
}
14+
715
type State interface {
816
Init() tea.Cmd
917
Update(msg tea.Msg) (tea.Model, tea.Cmd)
@@ -35,8 +43,3 @@ func (bs *BaseState) CommonUpdate(msg tea.Msg, currentState State) (tea.Model, t
3543
}
3644
return currentState, nil
3745
}
38-
39-
// func (bs *BaseState) GetName() string {
40-
// return "Base state"
41-
42-
// }

states/states_test.go

+71
Original file line numberDiff line numberDiff line change
@@ -1 +1,72 @@
11
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

Comments
 (0)