diff --git a/internal/tui/views/leaderboard_test.go b/internal/tui/views/leaderboard_test.go index 9d41fe7..9ffc083 100644 --- a/internal/tui/views/leaderboard_test.go +++ b/internal/tui/views/leaderboard_test.go @@ -3,7 +3,6 @@ package views import ( "database/sql" "fmt" - "io" "testing" "time" @@ -14,7 +13,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestLeaderboardCapacity(t *testing.T) { +func TestLeaderboard_TableEntries(t *testing.T) { db := setupInMemoryDB(t) repo := data.NewLeaderboardRepository(db) @@ -37,7 +36,7 @@ func TestLeaderboardCapacity(t *testing.T) { for i := range tc.count { _, err := repo.Save(&data.Score{ GameMode: t.Name(), - Name: fmt.Sprintf("testuser-%d", i), + Name: fmt.Sprintf("user-%d", i), Time: time.Second * time.Duration(i*2), Score: i * 100, Lines: i, @@ -54,22 +53,20 @@ func TestLeaderboardCapacity(t *testing.T) { tm := teatest.NewTestModel(t, m) tm.Send(tea.Quit()) - outBytes, err := io.ReadAll(tm.FinalOutput(t)) - require.NoError(t, err) - + outBytes := []byte(tm.FinalModel(t).View()) teatest.RequireEqualOutput(t, outBytes) }) } } -func TestLeaderboardNewEntry(t *testing.T) { +func TestLeaderboard_NewEntryInEmptyTable(t *testing.T) { db := setupInMemoryDB(t) m, err := NewLeaderboardModel(&tui.LeaderboardInput{ GameMode: t.Name(), NewEntry: &data.Score{ GameMode: t.Name(), - Name: "testuser-new", + Name: "user-new", Time: time.Minute, Score: 1000, Lines: 2, @@ -81,20 +78,18 @@ func TestLeaderboardNewEntry(t *testing.T) { tm := teatest.NewTestModel(t, m) tm.Send(tea.Quit()) - outBytes, err := io.ReadAll(tm.FinalOutput(t)) - require.NoError(t, err) - + outBytes := []byte(tm.FinalModel(t).View()) teatest.RequireEqualOutput(t, outBytes) } -func TestLeaderboardNavigation(t *testing.T) { +func TestLeaderboard_KeyboardNavigation(t *testing.T) { db := setupInMemoryDB(t) repo := data.NewLeaderboardRepository(db) for i := range 50 { _, err := repo.Save(&data.Score{ GameMode: t.Name(), - Name: fmt.Sprintf("testuser-%d", i), + Name: fmt.Sprintf("user-%d", i), Time: time.Second * time.Duration(i*2), Score: i * 100, Lines: i, @@ -107,7 +102,7 @@ func TestLeaderboardNavigation(t *testing.T) { GameMode: t.Name(), NewEntry: &data.Score{ GameMode: t.Name(), - Name: "testuser-new", + Name: "user-new", Time: time.Minute, Score: 2001, Lines: 2, @@ -117,13 +112,13 @@ func TestLeaderboardNavigation(t *testing.T) { require.NoError(t, err) tm := teatest.NewTestModel(t, m) - tm.Send(tea.KeyMsg{Type: tea.KeyDown}) - time.Sleep(10 * time.Millisecond) + for range 3 { + tm.Send(tea.KeyMsg{Type: tea.KeyDown}) + time.Sleep(10 * time.Millisecond) + } tm.Send(tea.Quit()) - outBytes, err := io.ReadAll(tm.FinalOutput(t)) - require.NoError(t, err) - + outBytes := []byte(tm.FinalModel(t).View()) teatest.RequireEqualOutput(t, outBytes) } diff --git a/internal/tui/views/menu_test.go b/internal/tui/views/menu_test.go index 0c7c758..7547ab4 100644 --- a/internal/tui/views/menu_test.go +++ b/internal/tui/views/menu_test.go @@ -11,7 +11,33 @@ import ( "github.com/stretchr/testify/require" ) -func TestMenuFormCompletion(t *testing.T) { +func TestMenu_Output(t *testing.T) { + m := NewMenuModel(&tui.MenuInput{}) + tm := teatest.NewTestModel(t, m) + + // Input username + tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("testuser")}) + tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) + time.Sleep(10 * time.Millisecond) + + // Select game mode + tm.Send(tea.KeyMsg{Type: tea.KeyDown}) + time.Sleep(10 * time.Millisecond) + tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) + time.Sleep(10 * time.Millisecond) + + // Select level + for range 3 { + tm.Send(tea.KeyMsg{Type: tea.KeyDown}) + time.Sleep(10 * time.Millisecond) + } + + tm.Send(tea.Quit()) + outBytes := []byte(tm.FinalModel(t).View()) + teatest.RequireEqualOutput(t, outBytes) +} + +func TestMenu_SwitchModeMsg(t *testing.T) { modeToMoveDownCount := func(mode tui.Mode) int { switch mode { case tui.ModeMarathon: diff --git a/internal/tui/views/testdata/TestLeaderboardCapacity/50_(overfull).golden b/internal/tui/views/testdata/TestLeaderboardCapacity/50_(overfull).golden deleted file mode 100644 index 86c3342..0000000 --- a/internal/tui/views/testdata/TestLeaderboardCapacity/50_(overfull).golden +++ /dev/null @@ -1,23 +0,0 @@ -[?25l[?2004h Rank Name Time Score Lines Level -──────────────────────────────────────────────────────── - 1 testuser-… 1m38s 4900 49 51 - 2 testuser-… 1m36s 4800 48 50 - 3 testuser-… 1m34s 4700 47 49 - 4 testuser-… 1m32s 4600 46 48 - 5 testuser-… 1m30s 4500 45 47 - 6 testuser-… 1m28s 4400 44 46 - 7 testuser-… 1m26s 4300 43 45 - 8 testuser-… 1m24s 4200 42 44 - 9 testuser-… 1m22s 4100 41 43 - 10 testuser-… 1m20s 4000 40 42 - 11 testuser-… 1m18s 3900 39 41 - 12 testuser-… 1m16s 3800 38 40 - 13 testuser-… 1m14s 3700 37 39 - 14 testuser-… 1m12s 3600 36 38 - 15 testuser-… 1m10s 3500 35 37 - 16 testuser-… 1m8s 3400 34 36 - 17 testuser-… 1m6s 3300 33 35 - 18 testuser-… 1m4s 3200 32 34 - 19 testuser-… 1m2s 3100 31 33 - 20 testuser-… 1m0s 3000 30 32 -escape exit • ? help [?2004l[?25h[?1002l[?1003l[?1006l \ No newline at end of file diff --git a/internal/tui/views/testdata/TestLeaderboardNavigation.golden b/internal/tui/views/testdata/TestLeaderboardNavigation.golden deleted file mode 100644 index b6aea4c..0000000 --- a/internal/tui/views/testdata/TestLeaderboardNavigation.golden +++ /dev/null @@ -1,23 +0,0 @@ -[?25l[?2004h Rank Name Time Score Lines Level -──────────────────────────────────────────────────────── - 12 testuser-… 1m16s 3800 38 40 - 13 testuser-… 1m14s 3700 37 39 - 14 testuser-… 1m12s 3600 36 38 - 15 testuser-… 1m10s 3500 35 37 - 16 testuser-… 1m8s 3400 34 36 - 17 testuser-… 1m6s 3300 33 35 - 18 testuser-… 1m4s 3200 32 34 - 19 testuser-… 1m2s 3100 31 33 - 20 testuser-… 1m0s 3000 30 32 - 21 testuser-… 58s 2900 29 31 - 22 testuser-… 56s 2800 28 30 - 23 testuser-… 54s 2700 27 29 - 24 testuser-… 52s 2600 26 28 - 25 testuser-… 50s 2500 25 27 - 26 testuser-… 48s 2400 24 26 - 27 testuser-… 46s 2300 23 25 - 28 testuser-… 44s 2200 22 24 - 29 testuser-… 42s 2100 21 23 - 30 testuser-… 1m0s 2001 2 3 - 31 testuser-… 40s 2000 20 22 -escape exit • ? help [?2004l[?25h[?1002l[?1003l[?1006l \ No newline at end of file diff --git a/internal/tui/views/testdata/TestLeaderboard_KeyboardNavigation.golden b/internal/tui/views/testdata/TestLeaderboard_KeyboardNavigation.golden new file mode 100644 index 0000000..671bdbb --- /dev/null +++ b/internal/tui/views/testdata/TestLeaderboard_KeyboardNavigation.golden @@ -0,0 +1,23 @@ + Rank Name Time Score Lines Level +──────────────────────────────────────────────────────── + 14 user-36 1m12s 3600 36 38 + 15 user-35 1m10s 3500 35 37 + 16 user-34 1m8s 3400 34 36 + 17 user-33 1m6s 3300 33 35 + 18 user-32 1m4s 3200 32 34 + 19 user-31 1m2s 3100 31 33 + 20 user-30 1m0s 3000 30 32 + 21 user-29 58s 2900 29 31 + 22 user-28 56s 2800 28 30 + 23 user-27 54s 2700 27 29 + 24 user-26 52s 2600 26 28 + 25 user-25 50s 2500 25 27 + 26 user-24 48s 2400 24 26 + 27 user-23 46s 2300 23 25 + 28 user-22 44s 2200 22 24 + 29 user-21 42s 2100 21 23 + 30 user-new 1m0s 2001 2 3 + 31 user-20 40s 2000 20 22 + 32 user-19 38s 1900 19 21 + 33 user-18 36s 1800 18 20 +escape exit • ? help \ No newline at end of file diff --git a/internal/tui/views/testdata/TestLeaderboardNewEntry.golden b/internal/tui/views/testdata/TestLeaderboard_NewEntryInEmptyTable.golden similarity index 86% rename from internal/tui/views/testdata/TestLeaderboardNewEntry.golden rename to internal/tui/views/testdata/TestLeaderboard_NewEntryInEmptyTable.golden index 949bf78..db87ac7 100644 --- a/internal/tui/views/testdata/TestLeaderboardNewEntry.golden +++ b/internal/tui/views/testdata/TestLeaderboard_NewEntryInEmptyTable.golden @@ -1,6 +1,6 @@ -[?25l[?2004h Rank Name Time Score Lines Level + Rank Name Time Score Lines Level ──────────────────────────────────────────────────────── - 1 testuser-… 1m0s 1000 2 3 + 1 user-new 1m0s 1000 2 3 @@ -20,4 +20,4 @@ -escape exit • ? help [?2004l[?25h[?1002l[?1003l[?1006l \ No newline at end of file +escape exit • ? help \ No newline at end of file diff --git a/internal/tui/views/testdata/TestLeaderboardCapacity/0_(empty).golden b/internal/tui/views/testdata/TestLeaderboard_TableEntries/0_(empty).golden similarity index 57% rename from internal/tui/views/testdata/TestLeaderboardCapacity/0_(empty).golden rename to internal/tui/views/testdata/TestLeaderboard_TableEntries/0_(empty).golden index 3a5f552..feb1f08 100644 --- a/internal/tui/views/testdata/TestLeaderboardCapacity/0_(empty).golden +++ b/internal/tui/views/testdata/TestLeaderboard_TableEntries/0_(empty).golden @@ -1,4 +1,4 @@ -[?25l[?2004h Rank Name Time Score Lines Level + Rank Name Time Score Lines Level ──────────────────────────────────────────────────────── @@ -20,4 +20,4 @@ -escape exit • ? help [?2004l[?25h[?1002l[?1003l[?1006l \ No newline at end of file +escape exit • ? help \ No newline at end of file diff --git a/internal/tui/views/testdata/TestLeaderboardCapacity/3_(partial).golden b/internal/tui/views/testdata/TestLeaderboard_TableEntries/3_(partial).golden similarity index 78% rename from internal/tui/views/testdata/TestLeaderboardCapacity/3_(partial).golden rename to internal/tui/views/testdata/TestLeaderboard_TableEntries/3_(partial).golden index 3de5b59..7057052 100644 --- a/internal/tui/views/testdata/TestLeaderboardCapacity/3_(partial).golden +++ b/internal/tui/views/testdata/TestLeaderboard_TableEntries/3_(partial).golden @@ -1,8 +1,8 @@ -[?25l[?2004h Rank Name Time Score Lines Level + Rank Name Time Score Lines Level ──────────────────────────────────────────────────────── - 1 testuser-2 4s 200 2 4 - 2 testuser-1 2s 100 1 3 - 3 testuser-0 0s 0 0 2 + 1 user-2 4s 200 2 4 + 2 user-1 2s 100 1 3 + 3 user-0 0s 0 0 2 @@ -20,4 +20,4 @@ -escape exit • ? help [?2004l[?25h[?1002l[?1003l[?1006l \ No newline at end of file +escape exit • ? help \ No newline at end of file diff --git a/internal/tui/views/testdata/TestLeaderboard_TableEntries/50_(overfull).golden b/internal/tui/views/testdata/TestLeaderboard_TableEntries/50_(overfull).golden new file mode 100644 index 0000000..85987c8 --- /dev/null +++ b/internal/tui/views/testdata/TestLeaderboard_TableEntries/50_(overfull).golden @@ -0,0 +1,23 @@ + Rank Name Time Score Lines Level +──────────────────────────────────────────────────────── + 1 user-49 1m38s 4900 49 51 + 2 user-48 1m36s 4800 48 50 + 3 user-47 1m34s 4700 47 49 + 4 user-46 1m32s 4600 46 48 + 5 user-45 1m30s 4500 45 47 + 6 user-44 1m28s 4400 44 46 + 7 user-43 1m26s 4300 43 45 + 8 user-42 1m24s 4200 42 44 + 9 user-41 1m22s 4100 41 43 + 10 user-40 1m20s 4000 40 42 + 11 user-39 1m18s 3900 39 41 + 12 user-38 1m16s 3800 38 40 + 13 user-37 1m14s 3700 37 39 + 14 user-36 1m12s 3600 36 38 + 15 user-35 1m10s 3500 35 37 + 16 user-34 1m8s 3400 34 36 + 17 user-33 1m6s 3300 33 35 + 18 user-32 1m4s 3200 32 34 + 19 user-31 1m2s 3100 31 33 + 20 user-30 1m0s 3000 30 32 +escape exit • ? help \ No newline at end of file diff --git a/internal/tui/views/testdata/TestMenu_Output.golden b/internal/tui/views/testdata/TestMenu_Output.golden new file mode 100644 index 0000000..24a6169 --- /dev/null +++ b/internal/tui/views/testdata/TestMenu_Output.golden @@ -0,0 +1,34 @@ + + ______________________ ______________ + /_ __/ ____/_ __/ __ \/ _/ ____/ __ \ + / / / __/ / / / /_/ // // / __/ / / / + / / / /___ / / / _, _// // /_/ / /_/ / + /_/ /_____/ /_/ /_/ |_/___/\____/\____/ + + + Username: + > testuser + + Game Mode: + Marathon + > Sprint (40 Lines) + Ultra (Time Trial) + +┃ Starting Level: +┃ 1 +┃ 2 +┃ 3 +┃ > 4 +┃ 5 +┃ 6 +┃ 7 +┃ 8 +┃ 9 +┃ 10 +┃ 11 +┃ 12 +┃ 13 +┃ 14 +┃ 15 + + ↑ up • ↓ down • / filter • shift+tab back • enter submit \ No newline at end of file