11
This commit is contained in:
commit
e6f1776d4f
264 files changed
+54215
No files matched your search
@@ -0,0 +1,102 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNKey_EntersCreateState(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
m2, _ := sendKey(m, "n")
|
||||
if m2.state != stateCreate {
|
||||
t.Errorf("state = %v, want stateCreate", m2.state)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateEsc_Cancels(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
m, _ = sendKey(m, "n")
|
||||
if m.state != stateCreate {
|
||||
t.Fatal("precondition: should be stateCreate")
|
||||
}
|
||||
m2, cmd := sendEsc(m)
|
||||
if m2.state != stateLoaded {
|
||||
t.Errorf("state = %v, want stateLoaded after esc", m2.state)
|
||||
}
|
||||
if cmd != nil {
|
||||
t.Error("cmd should be nil after esc cancel")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateCtrlSEmpty_Cancels(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
m, _ = sendKey(m, "n")
|
||||
m2, cmd := sendKey(m, "ctrl+s")
|
||||
if m2.state != stateLoaded {
|
||||
t.Errorf("state = %v, want stateLoaded after empty ctrl+s", m2.state)
|
||||
}
|
||||
if cmd != nil {
|
||||
t.Error("cmd should be nil after empty ctrl+s")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateCtrlSWithText_DispatchesCmd(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
m, _ = sendKey(m, "n")
|
||||
m = typeInto(m, "add dark mode")
|
||||
m2, cmd := sendKey(m, "ctrl+s")
|
||||
if m2.state != stateLoaded {
|
||||
t.Errorf("state = %v, want stateLoaded after ctrl+s with text", m2.state)
|
||||
}
|
||||
if cmd == nil {
|
||||
t.Error("cmd should be non-nil when text entered")
|
||||
}
|
||||
if m2.statusMsg != "创建中…" {
|
||||
t.Errorf("statusMsg = %q, want '创建中…'", m2.statusMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateState_BlocksOtherKeys(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
m, _ = sendKey(m, "n")
|
||||
m2, _ := sendKey(m, "q")
|
||||
if m2.state != stateCreate {
|
||||
t.Errorf("state = %v after 'q' in create mode, want stateCreate", m2.state)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateResultMsg_Error_SetsStatusMsg(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
next, _ := m.Update(createResultMsg{err: errors.New("spawn failed")})
|
||||
m2 := next.(Model)
|
||||
if m2.statusMsg == "" {
|
||||
t.Error("statusMsg should be set on createResult error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateResultMsg_Success_ReloadsBoard(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
next, cmd := m.Update(createResultMsg{})
|
||||
m2 := next.(Model)
|
||||
if m2.state != stateLoading {
|
||||
t.Errorf("state = %v, want stateLoading after successful create", m2.state)
|
||||
}
|
||||
if cmd == nil {
|
||||
t.Error("cmd should be non-nil to trigger board reload")
|
||||
}
|
||||
if m2.statusMsg != "创建成功,刷新看板…" {
|
||||
t.Errorf("statusMsg = %q", m2.statusMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateView_ShowsModal(t *testing.T) {
|
||||
m := makeLoadedModel(nil, 0, 0)
|
||||
m, _ = sendKey(m, "n")
|
||||
out := m.viewString()
|
||||
for _, want := range []string{"新建工单", "Markdown", "Ctrl+S 确认"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("create modal missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user