@timmy6942025/cli-timer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ package main
2
+
3
+ import (
4
+ "testing"
5
+
6
+ tea "github.com/charmbracelet/bubbletea"
7
+ )
8
+
9
+ func testPayload() statePayload {
10
+ return statePayload{
11
+ ConfigPath: "/tmp/cli-timer-test-config.json",
12
+ Config: config{
13
+ Font: "Standard",
14
+ CenterDisplay: true,
15
+ ShowHeader: true,
16
+ ShowControls: true,
17
+ TickRateMs: 100,
18
+ CompletionMessage: "Time is up!",
19
+ Keybindings: defaultKeybindings,
20
+ },
21
+ Fonts: []string{"Standard", "Big"},
22
+ }
23
+ }
24
+
25
+ func TestEnterSelectsMainMenuAction(t *testing.T) {
26
+ m := newModel(testPayload())
27
+ if m.screen != screenMain {
28
+ t.Fatalf("expected screenMain at init, got %v", m.screen)
29
+ }
30
+
31
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
32
+ next := updated.(model)
33
+
34
+ if next.screen != screenFontPicker {
35
+ t.Fatalf("expected enter to open font picker, got screen %v", next.screen)
36
+ }
37
+ }
38
+
39
+ func TestEnterSelectsFontInPicker(t *testing.T) {
40
+ m := newModel(testPayload())
41
+ m.screen = screenFontPicker
42
+ m.fontList.Select(1)
43
+
44
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
45
+ next := updated.(model)
46
+
47
+ if next.screen != screenMain {
48
+ t.Fatalf("expected return to main screen, got %v", next.screen)
49
+ }
50
+ if next.payload.Config.Font != "Big" {
51
+ t.Fatalf("expected selected font Big, got %q", next.payload.Config.Font)
52
+ }
53
+ }
54
+
55
+ func TestCtrlMAlsoConfirmsSelection(t *testing.T) {
56
+ m := newModel(testPayload())
57
+
58
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyCtrlM})
59
+ next := updated.(model)
60
+
61
+ if next.screen != screenFontPicker {
62
+ t.Fatalf("expected ctrl+m to open font picker, got %v", next.screen)
63
+ }
64
+ }
65
+
66
+ func TestRuneCarriageReturnConfirmsSelection(t *testing.T) {
67
+ m := newModel(testPayload())
68
+
69
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'\r'}})
70
+ next := updated.(model)
71
+
72
+ if next.screen != screenFontPicker {
73
+ t.Fatalf("expected \\r rune to open font picker, got %v", next.screen)
74
+ }
75
+ }
76
+
77
+ func TestRuneLineFeedConfirmsSelection(t *testing.T) {
78
+ m := newModel(testPayload())
79
+
80
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'\n'}})
81
+ next := updated.(model)
82
+
83
+ if next.screen != screenFontPicker {
84
+ t.Fatalf("expected \\n rune to open font picker, got %v", next.screen)
85
+ }
86
+ }