11package components_test
22
33import (
4- "strings"
54 "testing"
65
76 "tusshi/internal/tui/components"
87 "tusshi/internal/tui/theme"
98
109 tea "github.com/charmbracelet/bubbletea"
10+ "github.com/stretchr/testify/assert"
1111)
1212
1313func TestConfirmComponent (t * testing.T ) {
@@ -22,75 +22,59 @@ func TestConfirmComponent(t *testing.T) {
2222 },
2323 }
2424
25- if c .Title != "Test Confirm" {
26- t .Errorf ("expected Title 'Test Confirm', got %q" , c .Title )
27- }
25+ t .Run ("initial state" , func (t * testing.T ) {
26+ assert .Equal (t , "Test Confirm" , c .Title )
27+ assert .False (t , c .YesSelected )
28+ })
2829
29- if c .YesSelected {
30- t .Error ("expected YesSelected to be false by default" )
31- }
30+ t .Run ("move left" , func (t * testing.T ) {
31+ _ , done := c .Update (tea.KeyMsg {Type : tea .KeyLeft })
32+ assert .False (t , done )
33+ assert .True (t , c .YesSelected )
34+ })
3235
33- // Move left
34- _ , done := c .Update (tea.KeyMsg {Type : tea .KeyLeft })
35- if done {
36- t .Error ("expected navigation to not finalize selection" )
37- }
38- if ! c .YesSelected {
39- t .Error ("expected YesSelected to be true after left key press" )
40- }
41-
42- // Move right
43- _ , done = c .Update (tea.KeyMsg {Type : tea .KeyRight })
44- if done {
45- t .Error ("expected navigation to not finalize selection" )
46- }
47- if c .YesSelected {
48- t .Error ("expected YesSelected to be false after right key press" )
49- }
36+ t .Run ("move right" , func (t * testing.T ) {
37+ _ , done := c .Update (tea.KeyMsg {Type : tea .KeyRight })
38+ assert .False (t , done )
39+ assert .False (t , c .YesSelected )
40+ })
5041
51- // Confirm 'No'
52- _ , done = c .Update (tea.KeyMsg {Type : tea .KeyEnter })
53- if ! done {
54- t .Error ("expected done to be true after enter key press" )
55- }
56- if confirmedCalled {
57- t .Error ("expected confirmedCalled to be false since 'No' was focused" )
58- }
42+ t .Run ("confirm no" , func (t * testing.T ) {
43+ _ , done := c .Update (tea.KeyMsg {Type : tea .KeyEnter })
44+ assert .True (t , done )
45+ assert .False (t , confirmedCalled )
46+ })
5947
60- // Select Yes and Confirm 'Yes'
61- c .YesSelected = true
62- _ , done = c .Update (tea.KeyMsg {Type : tea .KeyEnter })
63- if ! done {
64- t .Error ("expected done to be true after enter key press on Yes" )
65- }
66- if ! confirmedCalled {
67- t .Error ("expected confirmedCalled to be true since 'Yes' was focused" )
68- }
48+ t .Run ("select yes and confirm yes" , func (t * testing.T ) {
49+ c .YesSelected = true
50+ _ , done := c .Update (tea.KeyMsg {Type : tea .KeyEnter })
51+ assert .True (t , done )
52+ assert .True (t , confirmedCalled )
53+ })
6954
70- // Esc test
71- _ , done = c .Update (tea.KeyMsg {Type : tea .KeyEsc })
72- if ! done {
73- t .Error ("expected done to be true after esc key press" )
74- }
55+ t .Run ("esc close" , func (t * testing.T ) {
56+ _ , done := c .Update (tea.KeyMsg {Type : tea .KeyEsc })
57+ assert .True (t , done )
58+ })
7559}
7660
7761func TestConfirmCustomLabels (t * testing.T ) {
7862 c := & components.Confirm {
7963 Theme : theme .Mock ,
8064 }
8165
82- // Verify defaults render when fields are left empty
83- viewEmpty := c .View (40 )
84- if ! strings .Contains (viewEmpty , " Yes " ) || ! strings . Contains ( viewEmpty , " No " ) {
85- t . Error ( "expected view to render default button labels when empty " )
86- }
66+ t . Run ( "default labels" , func ( t * testing. T ) {
67+ viewEmpty := c .View (40 )
68+ assert .Contains (t , viewEmpty , " Yes " )
69+ assert . Contains ( t , viewEmpty , " No " )
70+ })
8771
88- // Apply Option 2 (direct mutation)
89- c .YesStr = " Delete "
90- c .NoStr = " Cancel "
72+ t . Run ( "custom labels" , func ( t * testing. T ) {
73+ c .YesStr = " Delete "
74+ c .NoStr = " Cancel "
9175
92- viewCustom := c .View (40 )
93- if ! strings .Contains (viewCustom , " Delete " ) || ! strings . Contains ( viewCustom , " Cancel " ) {
94- t . Error ( "expected view to render custom button labels after mutation " )
95- }
76+ viewCustom := c .View (40 )
77+ assert .Contains (t , viewCustom , " Delete " )
78+ assert . Contains ( t , viewCustom , " Cancel " )
79+ })
9680}
0 commit comments