Skip to content

Commit

Permalink
test: status snapshots and 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Oct 24, 2024
1 parent 88ba5d2 commit 967fa6b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
67 changes: 66 additions & 1 deletion ui/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,74 @@ import (
"bytes"
"github.com/algorandfoundation/hack-tui/internal"
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_StatusViewRender(t *testing.T) {
var statusViewSnapshots = map[string]StatusViewModel{
"Syncing": {
Data: &internal.StateModel{
Status: internal.StatusModel{
LastRound: 1337,
NeedsUpdate: true,
State: "SYNCING",
},
Metrics: internal.MetricsModel{
RoundTime: 0,
TX: 0,
},
},
TerminalWidth: 180,
TerminalHeight: 80,
IsVisible: true,
},
"Hidden": {
Data: &internal.StateModel{
Status: internal.StatusModel{
LastRound: 1337,
NeedsUpdate: true,
State: "SYNCING",
},
Metrics: internal.MetricsModel{
RoundTime: 0,
TX: 0,
},
},
TerminalWidth: 180,
TerminalHeight: 80,
IsVisible: false,
},
"Loading": {
Data: &internal.StateModel{
Status: internal.StatusModel{
LastRound: 1337,
NeedsUpdate: true,
State: "SYNCING",
},
Metrics: internal.MetricsModel{
RoundTime: 0,
TX: 0,
},
},
TerminalWidth: 0,
TerminalHeight: 0,
IsVisible: true,
},
}

func Test_StatusSnapshot(t *testing.T) {
for name, model := range statusViewSnapshots {
t.Run(name, func(t *testing.T) {
got := ansi.Strip(model.View())
golden.RequireEqual(t, []byte(got))
})
}
}

func Test_StatusMessages(t *testing.T) {
state := internal.StateModel{
Status: internal.StatusModel{
LastRound: 1337,
Expand Down Expand Up @@ -45,6 +107,9 @@ func Test_StatusViewRender(t *testing.T) {
teatest.WithDuration(time.Second*3),
)

// Send the state
tm.Send(state)

// Send hide key
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions ui/testdata/Test_StatusSnapshot/Loading.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Loading...





7 changes: 7 additions & 0 deletions ui/testdata/Test_StatusSnapshot/Syncing.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
╭────────────────────────────────────────────────────────────────────────────────────────╮
│ Latest Round: 1337 SYNCING │
│ │
│ -- 0 round average -- │
│ Round time: 0.00s 0 KB/s TX │
│ TPS: 0.00 0 KB/s RX │
╰────────────────────────────────────────────────────────────────────────────────────────╯

0 comments on commit 967fa6b

Please sign in to comment.