This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
cairde/ui/input_test.go
decentral1se 88278955b1
All checks were successful
continuous-integration/drone/push Build is passing
test: input types & naming cleanup
2023-12-29 14:59:35 +01:00

54 lines
1.2 KiB
Go

package ui
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandleCommandTypes(t *testing.T) {
tests := []struct {
cmdInput string
hiddenInput string
cmdOutput interface{}
}{
{"help", "", cmdMsg{}},
{"quit", "", turnAcnOffMsg{}},
{"start", "", showGettingStartedGuideMsg{}},
{"profile unlock foo", "", profileUnlockMsg{}},
{"profile info", "", profileInfoMsg{}},
{"profile create foo *** ***", "bar bar", profileCreateMsg{}},
{"acn on", "", turnAcnOnMsg{}},
{"acn off", "", turnAcnOffMsg{}},
{"clear", "", clearScreenMsg{}},
}
for _, test := range tests {
msg := handleCommand(test.cmdInput, test.hiddenInput)
switch msg := msg.(type) {
default:
assert.IsType(t, msg, test.cmdOutput)
}
}
}
func TestHandleCommandUnknownCommand(t *testing.T) {
msg := handleCommand("foo", "")
switch msg := msg.(type) {
case cmdMsg:
assert.Equal(t, msg.output, []string{unknownCmdHelp})
default:
assert.IsType(t, msg, cmdMsg{})
}
}
func TestHandleCommandIncorrectCommand(t *testing.T) {
msg := handleCommand("profile foo", "")
switch msg := msg.(type) {
case cmdMsg:
assert.Contains(t, msg.output, `Unknown "profile" command?`)
default:
assert.IsType(t, msg, cmdMsg{})
}
}