Skip to content

Commit

Permalink
test: protocol snapshots and 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Oct 24, 2024
1 parent 554cea8 commit 88ba5d2
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 2 deletions.
104 changes: 102 additions & 2 deletions ui/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,105 @@ 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_ProtocolViewRender(t *testing.T) {
var protocolViewSnapshots = map[string]ProtocolViewModel{
"Hidden": {
Data: internal.StatusModel{
State: "SYNCING",
Version: "v0.0.0-test",
Network: "test-v1",
Voting: true,
NeedsUpdate: true,
LastRound: 0,
},
TerminalWidth: 60,
TerminalHeight: 40,
IsVisible: false,
},
"HiddenHeight": {
Data: internal.StatusModel{
State: "SYNCING",
Version: "v0.0.0-test",
Network: "test-v1",
Voting: true,
NeedsUpdate: true,
LastRound: 0,
},
TerminalWidth: 70,
TerminalHeight: 20,
IsVisible: true,
},
"Visible": {
Data: internal.StatusModel{
State: "SYNCING",
Version: "v0.0.0-test",
Network: "test-v1",
Voting: true,
NeedsUpdate: true,
LastRound: 0,
},
TerminalWidth: 160,
TerminalHeight: 80,
IsVisible: true,
},
"VisibleSmall": {
Data: internal.StatusModel{
State: "SYNCING",
Version: "v0.0.0-test",
Network: "test-v1",
Voting: true,
NeedsUpdate: true,
LastRound: 0,
},
TerminalWidth: 80,
TerminalHeight: 40,
IsVisible: true,
},
"NoVoteOrUpgrade": {
Data: internal.StatusModel{
State: "SYNCING",
Version: "v0.0.0-test",
Network: "test-v1",
Voting: false,
NeedsUpdate: false,
LastRound: 0,
},
TerminalWidth: 160,
TerminalHeight: 80,
IsVisible: true,
},
"NoVoteOrUpgradeSmall": {
Data: internal.StatusModel{
State: "SYNCING",
Version: "v0.0.0-test",
Network: "test-v1",
Voting: false,
NeedsUpdate: false,
LastRound: 0,
},
TerminalWidth: 80,
TerminalHeight: 40,
IsVisible: true,
},
}

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

// Test_ProtocolMessages handles any additional tests like sending messages
func Test_ProtocolMessages(t *testing.T) {
state := internal.StateModel{
Status: internal.StatusModel{
LastRound: 1337,
Expand Down Expand Up @@ -41,7 +134,14 @@ func Test_ProtocolViewRender(t *testing.T) {
teatest.WithCheckInterval(time.Millisecond*100),
teatest.WithDuration(time.Second*3),
)

tm.Send(internal.StatusModel{
State: "",
Version: "",
Network: "",
Voting: false,
NeedsUpdate: false,
LastRound: 0,
})
// Send hide key
tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Expand Down
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgrade.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
╭──────────────────────────────────────────────────────────────────────────────╮
│ Node: v0.0.0-test │
│ │
│ Network: test-v1 │
│ │
│ Protocol Voting: false │
╰──────────────────────────────────────────────────────────────────────────────╯
7 changes: 7 additions & 0 deletions ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgradeSmall.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
╭──────────────────────────────────────────────────────────────────────────────╮
│ Node: v0.0.0-test │
│ Network: test-v1 │
│ Protocol Voting: false │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
7 changes: 7 additions & 0 deletions ui/testdata/Test_ProtocolSnapshot/Visible.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
╭──────────────────────────────────────────────────────────────────────────────╮
│ Node: v0.0.0-test [UPDATE AVAILABLE] │
│ │
│ Network: test-v1 │
│ │
│ Protocol Voting: true │
╰──────────────────────────────────────────────────────────────────────────────╯
7 changes: 7 additions & 0 deletions ui/testdata/Test_ProtocolSnapshot/VisibleSmall.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
╭──────────────────────────────────────────────────────────────────────────────╮
│ Node: v0.0.0-test │
│ Network: test-v1 │
│ Protocol Voting: true │
│ Upgrade Available: true │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯

0 comments on commit 88ba5d2

Please sign in to comment.