44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/x/exp/teatest"
|
|
|
|
"gitlab.hive-brain.de/MDietermann/Archduino/internal/engine"
|
|
"gitlab.hive-brain.de/MDietermann/Archduino/internal/tui"
|
|
)
|
|
|
|
// TestModelEndToEnd drives the Model through teatest, feeding in the same
|
|
// message sequence that the TeaReporter + engine goroutine would produce.
|
|
func TestModelEndToEnd(t *testing.T) {
|
|
m := NewModel([]string{"alpha"}, map[string]string{"alpha": "Alpha"})
|
|
tm := teatest.NewTestModel(t, m, teatest.WithInitialTermSize(80, 24))
|
|
|
|
tm.Send(tui.ProgressMsg{ModuleID: "alpha", Current: 1, Total: 1, Message: "installing"})
|
|
tm.Send(DoneMsg{Summary: engine.Summary{Results: []engine.ModuleResult{
|
|
{ID: "alpha", Status: engine.StatusSucceeded},
|
|
}}})
|
|
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}})
|
|
|
|
tm.WaitFinished(t, teatest.WithFinalTimeout(3*time.Second))
|
|
|
|
out := readAll(t, tm.FinalOutput(t))
|
|
if !bytes.Contains(out, []byte("alpha")) || !bytes.Contains(out, []byte("summary:")) {
|
|
t.Fatalf("unexpected final output:\n%s", out)
|
|
}
|
|
}
|
|
|
|
func readAll(t *testing.T, r io.Reader) []byte {
|
|
t.Helper()
|
|
b, err := io.ReadAll(r)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return b
|
|
}
|