test: rewrite Task 5 tests for the naming-dialog contract
143ab56f3d03d1021d8d3e3636e570ef52af9b33
humdrum-tiv <45084903+humdrum-tiv@users.noreply.github.com> · 2026-07-30 19:33
parent 76b76232
test: rewrite Task 5 tests for the naming-dialog contract Five app_test.go tests still asserted the old synchronous save-as/ create flow (type a name, Enter, expect a file on disk). That flow no longer exists: Ctrl+N/Ctrl+B/Ctrl+S now open the naming dialog and confirm is a stub until Task 6. Rewrote each to assert what Task 5 actually establishes — the dialog opens, in the right mode, targeting the right directory, with the right prefill — so the suite is green between tasks (TASK-046).
1 files changed
internal/app/app_test.go +36 −49
@@ -331,7 +331,7 @@ t.Errorf("after two Ctrl+T = %q, want charm", a.theme.Name)
}
}
-func TestCtrlNCreatesNoteFromQuery(t *testing.T) {
+func TestCtrlNFromQueryOpensPromptInPickerRoot(t *testing.T) {
dir := t.TempDir()
cfg := config.Default()
t.Setenv("GLINT_VAULT", dir)
@@ -345,15 +345,14 @@ // Type a name into the picker query.
a.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("ideas")})
a.Update(tea.KeyMsg{Type: tea.KeyCtrlN})
- if a.mode != ModeEditor {
- t.Errorf("Ctrl+N should open the new note in the editor, mode = %d", a.mode)
+ if a.mode != ModeNamePrompt {
+ t.Fatalf("Ctrl+N from a picker query: mode = %d, want ModeNamePrompt", a.mode)
}
- want := filepath.Join(dir, "ideas.md")
- if a.path != want {
- t.Errorf("a.path = %q, want %q", a.path, want)
+ if a.dialogDir != dir {
+ t.Errorf("dialogDir = %q, want the picker root %q", a.dialogDir, dir)
}
- if _, err := os.Stat(want); err != nil {
- t.Errorf("new note should exist on disk: %v", err)
+ if a.dialog.Value() != "ideas" {
+ t.Errorf("dialog prefill = %q, want %q", a.dialog.Value(), "ideas")
}
}
@@ -433,7 +432,7 @@ t.Errorf("inbox note not created: %v", err)
}
}
-func TestSaveAsPromptOnPathlessBuffer(t *testing.T) {
+func TestCtrlSOnPathlessBufferOpensPrompt(t *testing.T) {
dir := t.TempDir()
cfg := config.Default()
t.Setenv("GLINT_VAULT", dir)
@@ -443,29 +442,16 @@ a.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
a.StartNew("") // blank unnamed buffer
a.editor.HandleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("hello")})
- a.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) // pathless → save-as prompt
+ a.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) // pathless → naming prompt
if a.mode != ModeNamePrompt {
t.Fatalf("Ctrl+S on pathless buffer: mode = %d, want ModeNamePrompt", a.mode)
}
- a.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("idea")})
- a.Update(tea.KeyMsg{Type: tea.KeyEnter}) // confirm
-
- want := filepath.Join(dir, "idea.md")
- if a.path != want {
- t.Errorf("path = %q, want %q", a.path, want)
- }
- data, err := os.ReadFile(want)
- if err != nil {
- t.Fatalf("file not written: %v", err)
+ if a.dialogDir != dir {
+ t.Errorf("dialogDir = %q, want the buffer's target dir %q", a.dialogDir, dir)
}
- if string(data) != "hello" {
- t.Errorf("saved content = %q, want hello", string(data))
- }
- if a.editor.Dirty {
- t.Error("buffer should be clean after save")
- }
- if a.mode != ModeEditor {
- t.Errorf("after save mode = %d, want ModeEditor", a.mode)
+ entries, _ := os.ReadDir(dir)
+ if len(entries) != 0 {
+ t.Errorf("Ctrl+S wrote to disk before confirm: %d entries in %q, want 0", len(entries), dir)
}
}
@@ -484,12 +470,15 @@ a.Update(tea.KeyMsg{Type: tea.KeyCtrlN}) // first press: arm, do not discard
if a.path != src {
t.Errorf("first Ctrl+N discarded without confirm; path = %q", a.path)
}
- a.Update(tea.KeyMsg{Type: tea.KeyCtrlN}) // second press: new blank
- if a.path != "" {
- t.Errorf("after confirm, path = %q, want empty", a.path)
+ if a.mode == ModeNamePrompt {
+ t.Fatal("first Ctrl+N on a dirty buffer opened the prompt; want a discard confirmation")
}
- if got := string(a.editor.Bytes()); got != "" {
- t.Errorf("editor not blank: %q", got)
+ a.Update(tea.KeyMsg{Type: tea.KeyCtrlN}) // second press: opens the naming dialog
+ if a.mode != ModeNamePrompt {
+ t.Errorf("second Ctrl+N: mode = %d, want ModeNamePrompt", a.mode)
+ }
+ if a.dialogDir != dir {
+ t.Errorf("dialogDir = %q, want the source file's directory %q", a.dialogDir, dir)
}
}
@@ -581,7 +570,7 @@ t.Errorf("note not created: %v", err)
}
}
-func TestCtrlNNewInSameDirSaveAs(t *testing.T) {
+func TestCtrlNTargetsSourceDirectory(t *testing.T) {
dir := t.TempDir()
src := filepath.Join(dir, "sub", "a.md")
os.MkdirAll(filepath.Dir(src), 0o755)
@@ -590,17 +579,16 @@ a := newApp()
a.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
a.Load(src)
a.Update(tea.KeyMsg{Type: tea.KeyCtrlN}) // new in the source's directory
- a.editor.HandleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("hi")})
- a.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) // unnamed → save-as prompt
- a.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("new")})
- a.Update(tea.KeyMsg{Type: tea.KeyEnter})
- want := filepath.Join(dir, "sub", "new.md")
- if a.path != want {
- t.Errorf("Ctrl+N note saved to %q, want %q (same dir as source)", a.path, want)
+ if a.mode != ModeNamePrompt {
+ t.Fatalf("Ctrl+N: mode = %d, want ModeNamePrompt", a.mode)
+ }
+ want := filepath.Join(dir, "sub")
+ if a.dialogDir != want {
+ t.Errorf("dialogDir = %q, want %q (same dir as source)", a.dialogDir, want)
}
}
-func TestCtrlBNewInInbox(t *testing.T) {
+func TestCtrlBTargetsInbox(t *testing.T) {
dir := t.TempDir()
t.Setenv("GLINT_VAULT", dir)
cfg := config.Default()
@@ -608,13 +596,12 @@ cfg.InboxDir = "Inbox"
a := New(cfg)
a.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
a.Update(tea.KeyMsg{Type: tea.KeyCtrlB}) // new in inbox
- a.editor.HandleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x")})
- a.Update(tea.KeyMsg{Type: tea.KeyCtrlS})
- a.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("note")})
- a.Update(tea.KeyMsg{Type: tea.KeyEnter})
- want := filepath.Join(dir, "Inbox", "note.md")
- if a.path != want {
- t.Errorf("Ctrl+B note saved to %q, want %q (inbox)", a.path, want)
+ if a.mode != ModeNamePrompt {
+ t.Fatalf("Ctrl+B: mode = %d, want ModeNamePrompt", a.mode)
+ }
+ want := filepath.Join(dir, "Inbox")
+ if a.dialogDir != want {
+ t.Errorf("dialogDir = %q, want %q (inbox)", a.dialogDir, want)
}
}