diff options
| author | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-22 17:12:01 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-22 17:12:01 +0300 |
| commit | 8a74c22d7a0708c79cbba40ccf85f32f568326e6 (patch) | |
| tree | a7881192a026b8d4b472e5af872db40f8b3b0728 /internal/ui/table_test.go | |
| parent | 97ca49e85034cf6b57a6515407f8a73b440755ee (diff) | |
| parent | 90f2d2efbf374f6ea82a46d2d701a099dbae1c89 (diff) | |
Merge pull request #83 from snonux/codex/fix-task-modification-bug-and-swap-hotkeys
Fix done marking bug and swap hotkeys
Diffstat (limited to 'internal/ui/table_test.go')
| -rw-r--r-- | internal/ui/table_test.go | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go index 4e2679d..365180c 100644 --- a/internal/ui/table_test.go +++ b/internal/ui/table_test.go @@ -162,7 +162,7 @@ func TestDoneHotkey(t *testing.T) { t.Fatalf("New: %v", err) } - mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'D'}}) + mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'d'}}) m = mv.(Model) for i := 0; i < blinkCycles; i++ { mv, _ = m.Update(blinkMsg{}) @@ -211,7 +211,7 @@ func TestUndoHotkey(t *testing.T) { t.Fatalf("New: %v", err) } - mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'D'}}) + mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'d'}}) m = mv.(Model) for i := 0; i < blinkCycles; i++ { mv, _ = m.Update(blinkMsg{}) @@ -269,7 +269,7 @@ func TestDueDateHotkey(t *testing.T) { t.Fatalf("New: %v", err) } - mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'d'}}) + mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'D'}}) m = mv.(Model) for i := 0; i < 3; i++ { mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRight}) @@ -442,6 +442,57 @@ func TestPriorityHotkey(t *testing.T) { } } +func TestAddHotkey(t *testing.T) { + tmp := t.TempDir() + taskPath := filepath.Join(tmp, "task") + addFile := filepath.Join(tmp, "add.txt") + + script := "#!/bin/sh\n" + + "if echo \"$@\" | grep -q export; then\n" + + " echo '{\"id\":1,\"uuid\":\"x\",\"description\":\"d\",\"status\":\"pending\",\"entry\":\"\",\"priority\":\"\",\"urgency\":0}'\n" + + " exit 0\n" + + "fi\n" + + "echo \"$@\" > " + addFile + "\n" + + if err := os.WriteFile(taskPath, []byte(script), 0o755); err != nil { + t.Fatal(err) + } + + origPath := os.Getenv("PATH") + os.Setenv("PATH", tmp+":"+origPath) + t.Cleanup(func() { os.Setenv("PATH", origPath) }) + + os.Setenv("TASKDATA", tmp) + os.Setenv("TASKRC", "/dev/null") + t.Cleanup(func() { + os.Unsetenv("TASKDATA") + os.Unsetenv("TASKRC") + }) + + m, err := New(nil) + if err != nil { + t.Fatalf("New: %v", err) + } + + mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'+'}}) + m = mv.(Model) + for _, r := range "foo due:today" { + mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + m = mv.(Model) + } + mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m = mv.(Model) + + data, err := os.ReadFile(addFile) + if err != nil { + t.Fatalf("read add: %v", err) + } + + if strings.TrimSpace(string(data)) != "add foo due:today" { + t.Fatalf("add not called: %q", data) + } +} + func TestNavigationHotkeys(t *testing.T) { tmp := t.TempDir() taskPath := filepath.Join(tmp, "task") |
