Skip to content

Commit

Permalink
test(ui): exception modal 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Nov 19, 2024
1 parent 233968d commit 4e4e9d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ui/modals/exception/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package exception

import (
"bytes"
"errors"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
"github.com/charmbracelet/x/exp/golden"
"github.com/charmbracelet/x/exp/teatest"
"testing"
"time"
)

func Test_Snapshot(t *testing.T) {
t.Run("Visible", func(t *testing.T) {
model := New("Something went wrong")
got := ansi.Strip(model.View())
golden.RequireEqual(t, []byte(got))
})
}

func Test_Messages(t *testing.T) {
// Create the Model
m := New("Something went wrong")
tm := teatest.NewTestModel(
t, m,
teatest.WithInitialTermSize(80, 40),
)

// Wait for prompt to exit
teatest.WaitFor(
t, tm.Output(),
func(bts []byte) bool {
return bytes.Contains(bts, []byte("Something went wrong"))
},
teatest.WithCheckInterval(time.Millisecond*100),
teatest.WithDuration(time.Second*3),
)

tm.Send(errors.New("Something else went wrong"))
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("esc"),
})

tm.Send(tea.QuitMsg{})

tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
1 change: 1 addition & 0 deletions ui/modals/exception/testdata/Test_Snapshot/Visible.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Something went wrong

0 comments on commit 4e4e9d9

Please sign in to comment.