Skip to content

Commit

Permalink
# This is a combination of 51 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

feat: add prompt-ui

# This is the commit message #2:

feat: configure and set algod data directory

# This is the commit message #3:

fix: RX/TX display

# This is the commit message #4:

fix: bit rate display for GB

# This is the commit message #5:

fix: configuration override order

# This is the commit message #6:

feat: handle invalid configuration and token gracefully

# This is the commit message #7:

test: fix test state

# This is the commit message #8:

fix: loading of custom endpoint address

# This is the commit message #9:

fix: loading default port

# This is the commit message #10:

test: clear viper settings

# This is the commit message #11:

fix: finds path to directory and gives cmd instruction

# This is the commit message #12:

feat: adds node start and node stop commands

# This is the commit message #13:

fix: add -y

# This is the commit message #14:

fix: turn script into indivudal commands

# This is the commit message #15:

feat: check if sudo, clarify shell

# This is the commit message #16:

chore: make more go idiomatic

# This is the commit message #17:

fix: fix proper path check

# This is the commit message #18:

fix: interact with systemctl, cleanup prompts

# This is the commit message #19:

fix: remove sudo

# This is the commit message #20:

fix: separate commands

# This is the commit message #21:

fix: proper algorand service name

# This is the commit message #22:

fix: calling with sudo

# This is the commit message #23:

chore: testing systemctl

# This is the commit message #24:

fix: checks algorand system service has been enabled directly

# This is the commit message #25:

feat: implements editAlgorandServiceFile

# This is the commit message #26:

fix: else statement

# This is the commit message #27:

fix: quick check branch

# This is the commit message #28:

fix: string template

# This is the commit message #29:

feat: adds upgrade

# This is the commit message #30:

chore: removeu nnecessary code

# This is the commit message #31:

fix: check that installed and candidate are the same

# This is the commit message #32:

chore: improve print

# This is the commit message #33:

chore: add more output

# This is the commit message #34:

fix: single quote

# This is the commit message #35:

fix: -y

# This is the commit message #36:

fix: systemctl

# This is the commit message #37:

fix: upgrade and sudo text

# This is the commit message #38:

chore: go mod tidy

# This is the commit message #39:

fix: upgrade

# This is the commit message #40:

feat: disable ui elements while syncing

# This is the commit message #41:

feat: skip account loading on syncing
feat: remove offline account expires date

# This is the commit message #42:

feat: installs algod and sets up service on mac

# This is the commit message #43:

feat: refactor, + mac

# This is the commit message #44:

feat: adds uninstall, mac only

# This is the commit message #45:

fix: remove plist file

# This is the commit message #46:

chore: rename

# This is the commit message #47:

test: protocol snapshots and 100%

# This is the commit message #48:

test: status snapshots and 100%

# This is the commit message #49:

test: error page snapshots and 100%

# This is the commit message #50:

test: controls snapshots

# This is the commit message #51:

test: accounts snapshots
  • Loading branch information
HashMapsData2Value committed Nov 25, 2024
1 parent 70456da commit ecf00bd
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 2 deletions.
12 changes: 11 additions & 1 deletion ui/controls/controls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ package controls
import (
"bytes"
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_Controls(t *testing.T) {
func Test_Snapshot(t *testing.T) {
t.Run("Visible", func(t *testing.T) {
model := New(" test ")
got := ansi.Strip(model.View())
golden.RequireEqual(t, []byte(got))
})
}

func Test_Messages(t *testing.T) {
expected := "(q)uit | (d)elete | (g)enerate | (t)xn | (h)ide"
// Create the Model
m := New(expected)
Expand Down
3 changes: 3 additions & 0 deletions ui/controls/testdata/Test_Snapshot/Visible.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╭──────╮
────────────────────────────────────┤ test ├────────────────────────────────────
╰──────╯
52 changes: 52 additions & 0 deletions ui/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ui

import (
"bytes"
"github.com/algorandfoundation/hack-tui/ui/controls"
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_ErrorSnapshot(t *testing.T) {
t.Run("Visible", func(t *testing.T) {
model := ErrorViewModel{
Height: 20,
Width: 40,
controls: controls.New(" Error "),
Message: "a test error",
}
got := ansi.Strip(model.View())
golden.RequireEqual(t, []byte(got))
})
}

func Test_ErrorMessages(t *testing.T) {
tm := teatest.NewTestModel(
t, ErrorViewModel{Message: "a test error"},
teatest.WithInitialTermSize(120, 80),
)

// Wait for prompt to exit
teatest.WaitFor(
t, tm.Output(),
func(bts []byte) bool {
return bytes.Contains(bts, []byte("a test error"))
},
teatest.WithCheckInterval(time.Millisecond*100),
teatest.WithDuration(time.Second*3),
)
// Resize Message
tm.Send(tea.WindowSizeMsg{
Width: 50,
Height: 20,
})

// Send quit key
tm.Send(tea.QuitMsg{})

tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
106 changes: 106 additions & 0 deletions ui/pages/accounts/accounts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package accounts

import (
"bytes"
"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) {
t.Run("Visible", func(t *testing.T) {
model := New(&internal.StateModel{
Status: internal.StatusModel{},
Metrics: internal.MetricsModel{},
Accounts: nil,
ParticipationKeys: nil,
Admin: false,
Watching: false,
})
got := ansi.Strip(model.View())
golden.RequireEqual(t, []byte(got))
})
}

func Test_Messages(t *testing.T) {
var testKeys = []api.ParticipationKey{
{
Address: "ABC",
EffectiveFirstValid: nil,
EffectiveLastValid: nil,
Id: "",
Key: api.AccountParticipation{
SelectionParticipationKey: nil,
StateProofKey: nil,
VoteFirstValid: 0,
VoteKeyDilution: 0,
VoteLastValid: 0,
VoteParticipationKey: nil,
},
LastBlockProposal: nil,
LastStateProof: nil,
LastVote: nil,
},
}
sm := &internal.StateModel{
Status: internal.StatusModel{},
Metrics: internal.MetricsModel{},
Accounts: nil,
ParticipationKeys: &testKeys,
Admin: false,
Watching: false,
}
values := make(map[string]internal.Account)
for _, key := range *sm.ParticipationKeys {
val, ok := values[key.Address]
if !ok {
values[key.Address] = internal.Account{
Address: key.Address,
Status: "Offline",
Balance: 0,
Expires: time.Unix(0, 0),
Keys: 1,
}
} else {
val.Keys++
values[key.Address] = val
}
}
sm.Accounts = values
// Create the Model
m := New(sm)

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("(k)eys"))
},
teatest.WithCheckInterval(time.Millisecond*100),
teatest.WithDuration(time.Second*3),
)

tm.Send(*sm)

tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("enter"),
})

tm.Send(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune("ctrl+c"),
})

tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
26 changes: 26 additions & 0 deletions ui/pages/accounts/testdata/Test_Snapshot/Visible.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@























╭──────────────────────────────────────────╮
──────────────────┤ (g)enerate | (a)ccounts | (k)eys | (t)xn ├──────────────────
╰──────────────────────────────────────────╯
82 changes: 81 additions & 1 deletion ui/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,78 @@ package ui
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"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/exp/teatest"
)

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 @@ -47,8 +110,25 @@ func Test_StatusViewRender(t *testing.T) {
teatest.WithDuration(time.Second*3),
)

<<<<<<< HEAD
// Send quit msg
tm.Send(tea.QuitMsg{})
=======
// 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"),
})
>>>>>>> 967fa6b (test: status snapshots and 100%)

tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
24 changes: 24 additions & 0 deletions ui/testdata/Test_ErrorSnapshot/Visible.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@










a test error










╭───────╮
───────────────────────────────────┤ Error ├───────────────────────────────────
╰───────╯
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 ecf00bd

Please sign in to comment.