diff --git a/go.mod b/go.mod index 217ad5af..3a8c17d0 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.2.0 // indirect github.com/charmbracelet/x/ansi v0.3.2 - github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b + github.com/charmbracelet/x/exp/golden v0.0.0-20241022174419-46d9bb99a691 github.com/charmbracelet/x/term v0.2.0 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect diff --git a/ui/pages/accounts/accounts_test.go b/ui/pages/accounts/accounts_test.go index d6afa218..6da04a3f 100644 --- a/ui/pages/accounts/accounts_test.go +++ b/ui/pages/accounts/accounts_test.go @@ -2,14 +2,15 @@ package accounts import ( "bytes" + "testing" + "time" + "github.com/algorandfoundation/hack-tui/api" "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_Snapshot(t *testing.T) { @@ -22,6 +23,7 @@ func Test_Snapshot(t *testing.T) { Admin: false, Watching: false, }) + model, _ = model.HandleMessage(tea.WindowSizeMsg{Width: 80, Height: 40}) got := ansi.Strip(model.View()) golden.RequireEqual(t, []byte(got)) }) diff --git a/ui/pages/accounts/testdata/Test_Snapshot/Visible.golden b/ui/pages/accounts/testdata/Test_Snapshot/Visible.golden index 0c6418cd..d3bc0f03 100644 --- a/ui/pages/accounts/testdata/Test_Snapshot/Visible.golden +++ b/ui/pages/accounts/testdata/Test_Snapshot/Visible.golden @@ -1,26 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - ╭──────────────────────────────────────────╮ -──────────────────┤ (g)enerate | (a)ccounts | (k)eys | (t)xn ├────────────────── - ╰──────────────────────────────────────────╯ \ No newline at end of file +╭──Accounts────────────────────────────────────────────────────────────────────╮ +│ Account Keys Status Expires Balance │ +│────────────────────────────────────────────────────────────────────── │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +╰────( (g)enerate )─────────────────────────| (a)ccounts | (k)eys | (t)xn |────╯ diff --git a/ui/protocol_test.go b/ui/protocol_test.go index 99c3e63b..2b04df54 100644 --- a/ui/protocol_test.go +++ b/ui/protocol_test.go @@ -10,6 +10,12 @@ import ( "github.com/charmbracelet/x/ansi" "github.com/charmbracelet/x/exp/golden" "github.com/charmbracelet/x/exp/teatest" + + "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" ) var protocolViewSnapshots = map[string]ProtocolViewModel{ @@ -155,5 +161,11 @@ func Test_ProtocolMessages(t *testing.T) { Runes: []rune("ctrl+c"), }) + // Send quit key + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("ctrl+c"), + }) + tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second)) } diff --git a/ui/status.go b/ui/status.go index ade98da4..57796197 100644 --- a/ui/status.go +++ b/ui/status.go @@ -91,7 +91,7 @@ func (m StatusViewModel) View() string { roundTime = "--" } beginning = style.Blue.Render(" Round time: ") + roundTime - end = fmt.Sprintf("%d KB/s ", m.Data.Metrics.TX/1024) + style.Green.Render("TX ") + end = getBitRate(m.Data.Metrics.TX) + style.Green.Render("TX ") middle = strings.Repeat(" ", max(0, size-(lipgloss.Width(beginning)+lipgloss.Width(end)+2))) row2 := lipgloss.JoinHorizontal(lipgloss.Left, beginning, middle, end) @@ -101,7 +101,7 @@ func (m StatusViewModel) View() string { tps = "--" } beginning = style.Blue.Render(" TPS: ") + tps - end = fmt.Sprintf("%d KB/s ", m.Data.Metrics.RX/1024) + style.Green.Render("RX ") + end = getBitRate(m.Data.Metrics.RX) + style.Green.Render("RX ") middle = strings.Repeat(" ", max(0, size-(lipgloss.Width(beginning)+lipgloss.Width(end)+2))) row3 := lipgloss.JoinHorizontal(lipgloss.Left, beginning, middle, end) diff --git a/ui/status_test.go b/ui/status_test.go index 823a0202..f0d8d072 100644 --- a/ui/status_test.go +++ b/ui/status_test.go @@ -11,6 +11,8 @@ import ( "time" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/x/ansi" + "github.com/charmbracelet/x/exp/golden" "github.com/charmbracelet/x/exp/teatest" ) @@ -111,6 +113,23 @@ func Test_StatusMessages(t *testing.T) { ) <<<<<<< HEAD +<<<<<<< HEAD +======= + // Send the state + tm.Send(state) + + // Send hide key + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("h"), + }) + + // Send quit key + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("ctrl+c"), + }) +>>>>>>> main // Send quit msg tm.Send(tea.QuitMsg{}) ======= diff --git a/ui/testdata/Test_ErrorSnapshot/Visible.golden b/ui/testdata/Test_ErrorSnapshot/Visible.golden index 80bcfb88..8b89731c 100644 --- a/ui/testdata/Test_ErrorSnapshot/Visible.golden +++ b/ui/testdata/Test_ErrorSnapshot/Visible.golden @@ -1,24 +1,22 @@ - - - - - - - - - - - a test error - - - - - - - - - - - ╭───────╮ -───────────────────────────────────┤ Error ├─────────────────────────────────── - ╰───────╯ \ No newline at end of file +╭──System Error──────────────────────────╮ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ a test error │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +╰─────────( Waiting for recovery... )────╯ diff --git a/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgrade.golden b/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgrade.golden index 6eca90f5..f942f810 100644 --- a/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgrade.golden +++ b/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgrade.golden @@ -1,4 +1,8 @@ +<<<<<<< HEAD ╭──────────────────────────────────────────────────────────────────────────────╮ +======= +╭──Protocol────────────────────────────────────────────────────────────────────╮ +>>>>>>> main │ Node: v0.0.0-test │ │ │ │ Network: test-v1 │ diff --git a/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgradeSmall.golden b/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgradeSmall.golden index a0cc43b9..87910af8 100644 --- a/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgradeSmall.golden +++ b/ui/testdata/Test_ProtocolSnapshot/NoVoteOrUpgradeSmall.golden @@ -1,4 +1,8 @@ +<<<<<<< HEAD ╭──────────────────────────────────────────────────────────────────────────────╮ +======= +╭──Protocol────────────────────────────────────────────────────────────────────╮ +>>>>>>> main │ Node: v0.0.0-test │ │ Network: test-v1 │ │ Protocol Voting: false │ diff --git a/ui/testdata/Test_ProtocolSnapshot/Visible.golden b/ui/testdata/Test_ProtocolSnapshot/Visible.golden index a8adee3f..c06766db 100644 --- a/ui/testdata/Test_ProtocolSnapshot/Visible.golden +++ b/ui/testdata/Test_ProtocolSnapshot/Visible.golden @@ -1,4 +1,8 @@ +<<<<<<< HEAD ╭──────────────────────────────────────────────────────────────────────────────╮ +======= +╭──Protocol────────────────────────────────────────────────────────────────────╮ +>>>>>>> main │ Node: v0.0.0-test [UPDATE AVAILABLE] │ │ │ │ Network: test-v1 │ diff --git a/ui/testdata/Test_ProtocolSnapshot/VisibleSmall.golden b/ui/testdata/Test_ProtocolSnapshot/VisibleSmall.golden index 10a5f701..b0c57bcf 100644 --- a/ui/testdata/Test_ProtocolSnapshot/VisibleSmall.golden +++ b/ui/testdata/Test_ProtocolSnapshot/VisibleSmall.golden @@ -1,4 +1,4 @@ -╭──────────────────────────────────────────────────────────────────────────────╮ +╭──Protocol────────────────────────────────────────────────────────────────────╮ │ Node: v0.0.0-test │ │ Network: test-v1 │ │ Protocol Voting: true │ diff --git a/ui/testdata/Test_StatusSnapshot/Syncing.golden b/ui/testdata/Test_StatusSnapshot/Syncing.golden index 7edf0f7e..0004a66d 100644 --- a/ui/testdata/Test_StatusSnapshot/Syncing.golden +++ b/ui/testdata/Test_StatusSnapshot/Syncing.golden @@ -1,7 +1,7 @@ -╭────────────────────────────────────────────────────────────────────────────────────────╮ +╭──Status────────────────────────────────────────────────────────────────────────────────╮ │ Latest Round: 1337 SYNCING │ │ │ │ -- 0 round average -- │ -│ Round time: 0.00s 0 KB/s TX │ -│ TPS: 0.00 0 KB/s RX │ +│ Round time: -- 0 B/s TX │ +│ TPS: -- 0 B/s RX │ ╰────────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file