Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package cmdmodel_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
cmdmodel "git.cw.tr/mukan-network/mukan-ignite/ignite/cmd/bubblemodel"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/cmd/bubblemodel/testdata"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/cliui/colors"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/cliui/icons"
|
|
cliuimodel "git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/cliui/model"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/errors"
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/events"
|
|
)
|
|
|
|
func TestChainDebugErrorView(t *testing.T) {
|
|
// Arrange
|
|
var model tea.Model
|
|
|
|
err := errors.New("Test error")
|
|
model = cmdmodel.NewChainDebug(testdata.ModelContext{}, testdata.DummyEventsProvider{}, testdata.FooCmd)
|
|
want := fmt.Sprintf("%s %s\n", icons.NotOK, colors.Error(err.Error()))
|
|
|
|
// Arrange: Update model with an error message
|
|
model, _ = model.Update(cliuimodel.ErrorMsg{Error: err})
|
|
|
|
// Act
|
|
view := model.View()
|
|
|
|
// Assert
|
|
require.Equal(t, want, view)
|
|
}
|
|
|
|
func TestChainDebugStartView(t *testing.T) {
|
|
// Arrange
|
|
var model tea.Model
|
|
|
|
spinner := cliuimodel.NewSpinner()
|
|
queue := []string{"Event 1...", "Event 2..."}
|
|
model = cmdmodel.NewChainDebug(testdata.ModelContext{}, testdata.DummyEventsProvider{}, testdata.FooCmd)
|
|
|
|
want := fmt.Sprintf("\n%s%s\n", spinner.View(), queue[1])
|
|
want = cliuimodel.FormatView(want)
|
|
|
|
// Arrange: Update model with status events
|
|
for _, s := range queue {
|
|
model, _ = model.Update(cliuimodel.EventMsg{
|
|
Event: events.New(s, events.ProgressStart()),
|
|
})
|
|
}
|
|
|
|
// Act
|
|
view := model.View()
|
|
|
|
// Assert
|
|
require.Equal(t, want, view)
|
|
}
|
|
|
|
func TestChainDebugRunView(t *testing.T) {
|
|
// Arrange
|
|
var model tea.Model
|
|
|
|
evt := "Debug server: tcp://127.0.0.1:30500"
|
|
actions := colors.Faint("Press the 'q' key to stop debug server")
|
|
model = cmdmodel.NewChainDebug(testdata.ModelContext{}, testdata.DummyEventsProvider{}, testdata.FooCmd)
|
|
|
|
want := fmt.Sprintf("Blockchain is running\n\n%s\n\n%s\n", evt, actions)
|
|
want = cliuimodel.FormatView(want)
|
|
|
|
// Arrange: Update model with a server running event
|
|
model, _ = model.Update(cliuimodel.EventMsg{
|
|
Event: events.New(evt, events.ProgressFinish()),
|
|
})
|
|
|
|
// Act
|
|
view := model.View()
|
|
|
|
// Assert
|
|
require.Equal(t, want, view)
|
|
}
|