From 1c8d3207a95a544c2438639f7cd414d122a0e118 Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 14:58:14 +0400 Subject: [PATCH] fix: include attachment in test --- tui/composer_test.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tui/composer_test.go b/tui/composer_test.go index 77a32c2dbc7e694ec46469030924e39dbca6fa65..922dcaa5154eacfdab7e1475910598bf3f15f10b 100644 --- a/tui/composer_test.go +++ b/tui/composer_test.go @@ -19,31 +19,38 @@ func TestComposerUpdate(t *testing.T) { } // Simulate pressing Tab to move to the 'Subject' field. - model, _ := composer.Update(tea.KeyMsg{Type: tea.KeyTab}) // model is tea.Model - composer = model.(*Composer) // Cast to *Composer + model, _ := composer.Update(tea.KeyMsg{Type: tea.KeyTab}) + composer = model.(*Composer) if composer.focusIndex != 1 { - t.Errorf("After one Tab, focusIndex should be 1, got %d", composer.focusIndex) + t.Errorf("After one Tab, focusIndex should be 1 (Subject), got %d", composer.focusIndex) } // Simulate pressing Tab again to move to the 'Body' field. - model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) // model is tea.Model - composer = model.(*Composer) // Cast to *Composer + model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) + composer = model.(*Composer) if composer.focusIndex != 2 { - t.Errorf("After two Tabs, focusIndex should be 2, got %d", composer.focusIndex) + t.Errorf("After two Tabs, focusIndex should be 2 (Body), got %d", composer.focusIndex) } - // Simulate pressing Tab again to move to the 'Send' button. - model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) // model is tea.Model - composer = model.(*Composer) // Cast to *Composer + // Simulate pressing Tab again to move to the 'Attachment' field. + model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) + composer = model.(*Composer) if composer.focusIndex != 3 { - t.Errorf("After three Tabs, focusIndex should be 3 (Send), got %d", composer.focusIndex) + t.Errorf("After three Tabs, focusIndex should be 3 (Attachment), got %d", composer.focusIndex) + } + + // Simulate pressing Tab again to move to the 'Send' button. + model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) + composer = model.(*Composer) + if composer.focusIndex != 4 { + t.Errorf("After four Tabs, focusIndex should be 4 (Send), got %d", composer.focusIndex) } // Simulate one more Tab to wrap around to the 'To' field. - model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) // model is tea.Model - composer = model.(*Composer) // Cast to *Composer + model, _ = composer.Update(tea.KeyMsg{Type: tea.KeyTab}) + composer = model.(*Composer) if composer.focusIndex != 0 { - t.Errorf("After four Tabs, focusIndex should wrap to 0, got %d", composer.focusIndex) + t.Errorf("After five Tabs, focusIndex should wrap to 0, got %d", composer.focusIndex) } }) @@ -53,7 +60,7 @@ func TestComposerUpdate(t *testing.T) { composer.subjectInput.SetValue("Test Subject") composer.bodyInput.SetValue("This is the body.") // Set focus to the Send button. - composer.focusIndex = 3 + composer.focusIndex = 4 // Simulate pressing Enter to send the email. _, cmd := composer.Update(tea.KeyMsg{Type: tea.KeyEnter}) @@ -70,9 +77,10 @@ func TestComposerUpdate(t *testing.T) { // Verify the content of the message. expectedMsg := SendEmailMsg{ - To: "recipient@example.com", - Subject: "Test Subject", - Body: "This is the body.", + To: "recipient@example.com", + Subject: "Test Subject", + Body: "This is the body.", + AttachmentPath: "", // Expect empty attachment path in this test } if !reflect.DeepEqual(sendMsg, expectedMsg) { t.Errorf("Mismatched SendEmailMsg.\nGot: %+v\nWant: %+v", sendMsg, expectedMsg)