新增: skills 视图与标题编辑测试(未落库功能批量入库)

This commit is contained in:
lxy
2026-08-23 18:25:02 +08:00
parent 95f349bcd7
commit d54d0c4c63
12 changed files with 985 additions and 37 deletions
+65
View File
@@ -0,0 +1,65 @@
package internal
import (
"testing"
tea "charm.land/bubbletea/v2"
)
// TestEditTitleViaRealKeyPress 用真实 tea.KeyPressMsg 走完整 Update 流程,
// 验证运行时按键是否能真正写入编辑缓冲(用户反馈"界面未能输入名称")。
func TestEditTitleViaRealKeyPress(t *testing.T) {
m := NewModel()
m.history.Projects = []*ProjectDir{
{DirShort: "test", Sessions: []*Session{
{ID: "s1", AISummary: "旧标题"},
}},
}
m.history.DirCursor = 2
m.history.SessCursor = 0
m.history.Loaded = true
send := func(msg tea.Msg) tea.Model {
var cmd tea.Cmd
var model tea.Model = m
model, cmd = m.Update(msg)
_ = cmd
return model
}
// 1. 真实按键 'e' 进入编辑模式(Code+Text 同 ultraviolet 实测构造)
send(tea.KeyPressMsg{Code: 'e', Text: "e"})
if !m.editTitleMode {
t.Fatal("真实 KeyPressMsg(e) 应进入编辑模式")
}
if m.editTitleBuf != "旧标题" {
t.Fatalf("编辑缓冲应预填旧标题, got %q", m.editTitleBuf)
}
// 2. 真实按键 'a'(ASCII 字符)
send(tea.KeyPressMsg{Code: 'a', Text: "a"})
if m.editTitleBuf != "旧标题a" {
t.Fatalf("真实按键 a 应追加, got %q", m.editTitleBuf)
}
// 3. 真实空格键(Code=KeySpace, Text=" ")
send(tea.KeyPressMsg{Code: tea.KeySpace, Text: " "})
if m.editTitleBuf != "旧标题a " {
t.Fatalf("空格应插入, got %q", m.editTitleBuf)
}
// 4. 真实中文输入(多 rune,Code=KeyExtended)
send(tea.KeyPressMsg{Code: tea.KeyExtended, Text: "新"})
if m.editTitleBuf != "旧标题a 新" {
t.Fatalf("中文应追加, got %q", m.editTitleBuf)
}
// 5. 回车确认
send(tea.KeyPressMsg{Code: tea.KeyEnter, Text: ""})
if m.editTitleMode {
t.Fatal("回车应退出编辑模式")
}
if m.launched != "rename: 旧标题a 新" {
t.Fatalf("确认后 launched 应记录改名, got %q", m.launched)
}
}