diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-01-25 17:05:49 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-01-25 17:09:41 -1000 |
| commit | dedda31d064ddcb4f857f2db851c5a8c1e19deba (patch) | |
| tree | 2f76f41806727afa54449cdac8672056a5f8615c /internal/store/sqlite_test.go | |
| parent | ec8a9c0ea46dec7d26caa763e3adefcaf3fc7552 (diff) | |
Implement architectural refactors for feature requests #28, #30, #31, #33-38
Phase 1: Bugs as First-Class Atoms (#28)
- Add resolved_at column to bugs table (migration 007)
- Add GetUnresolvedBugs(), ResolveBug(), UnresolveBug() store methods
- Include bugs in Tasks tab via BugToAtom() with completion toggle
- Add unit tests for bug resolution
Phase 2: Timeline as Default + Enhancements (#35, #37)
- Change default tab from tasks to timeline
- Add IsCompleted, DaySection, Source fields to TimelineItem
- Group timeline items by today/tomorrow/later sections
- Add completion checkboxes for tasks/cards, grey completed items
- Collapse tomorrow/later sections by default
Phase 3: Shopping Quick-Add (#33)
- Add user_shopping_items table (migration 008)
- Add SaveUserShoppingItem(), GetUserShoppingItems(), ToggleUserShoppingItem()
- Add HandleShoppingQuickAdd() and HandleShoppingToggle() handlers
- Add quick-add form to shopping tab
Phase 4: Mobile Swipe Navigation (#38)
- Add touch event handlers for swipe left/right tab switching
- 50px threshold triggers tab change
Phase 5: Consistent Background Opacity (#30)
- Add CSS variables for panel/card/input/modal backgrounds
- Update templates to use consistent opacity classes
Phase 6: Tab Reorganization (#37)
- Reorganize tabs: Timeline, Shopping, Conditions as main tabs
- Move Tasks, Planning, Meals under Details dropdown
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/store/sqlite_test.go')
| -rw-r--r-- | internal/store/sqlite_test.go | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/internal/store/sqlite_test.go b/internal/store/sqlite_test.go index 5719e24..fc8a3b7 100644 --- a/internal/store/sqlite_test.go +++ b/internal/store/sqlite_test.go @@ -569,3 +569,123 @@ func TestGetCardsByDateRange(t *testing.T) { t.Errorf("Expected card1, got %s", results[0].ID) } } + +// setupTestStoreWithBugs creates a test store with bugs table +func setupTestStoreWithBugs(t *testing.T) *Store { + t.Helper() + + tempDir := t.TempDir() + dbPath := filepath.Join(tempDir, "test.db") + + db, err := sql.Open("sqlite3", dbPath) + if err != nil { + t.Fatalf("Failed to open test database: %v", err) + } + + db.SetMaxOpenConns(1) + + store := &Store{db: db} + + schema := ` + CREATE TABLE IF NOT EXISTS bugs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + description TEXT NOT NULL, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + resolved_at DATETIME DEFAULT NULL + ); + ` + if _, err := db.Exec(schema); err != nil { + t.Fatalf("Failed to create schema: %v", err) + } + + return store +} + +func TestBugResolution(t *testing.T) { + store := setupTestStoreWithBugs(t) + defer store.Close() + + // Save some bugs + if err := store.SaveBug("Bug 1"); err != nil { + t.Fatalf("Failed to save bug 1: %v", err) + } + if err := store.SaveBug("Bug 2"); err != nil { + t.Fatalf("Failed to save bug 2: %v", err) + } + if err := store.SaveBug("Bug 3"); err != nil { + t.Fatalf("Failed to save bug 3: %v", err) + } + + // Verify all 3 bugs are unresolved + unresolved, err := store.GetUnresolvedBugs() + if err != nil { + t.Fatalf("GetUnresolvedBugs failed: %v", err) + } + if len(unresolved) != 3 { + t.Errorf("Expected 3 unresolved bugs, got %d", len(unresolved)) + } + + // Resolve bug 2 + if err := store.ResolveBug(2); err != nil { + t.Fatalf("ResolveBug failed: %v", err) + } + + // Verify only 2 unresolved bugs remain + unresolved, err = store.GetUnresolvedBugs() + if err != nil { + t.Fatalf("GetUnresolvedBugs after resolve failed: %v", err) + } + if len(unresolved) != 2 { + t.Errorf("Expected 2 unresolved bugs, got %d", len(unresolved)) + } + + // Verify bug 2 is not in the unresolved list + for _, bug := range unresolved { + if bug.ID == 2 { + t.Error("Bug 2 should have been resolved but is still in unresolved list") + } + } + + // Verify all bugs still exist in GetBugs (including resolved) + allBugs, err := store.GetBugs() + if err != nil { + t.Fatalf("GetBugs failed: %v", err) + } + if len(allBugs) != 3 { + t.Errorf("Expected 3 total bugs, got %d", len(allBugs)) + } + + // Verify bug 2 has resolved_at set + for _, bug := range allBugs { + if bug.ID == 2 { + if bug.ResolvedAt == nil { + t.Error("Bug 2 should have resolved_at set") + } + } + } + + // Unresolve bug 2 + if err := store.UnresolveBug(2); err != nil { + t.Fatalf("UnresolveBug failed: %v", err) + } + + // Verify all 3 bugs are unresolved again + unresolved, err = store.GetUnresolvedBugs() + if err != nil { + t.Fatalf("GetUnresolvedBugs after unresolve failed: %v", err) + } + if len(unresolved) != 3 { + t.Errorf("Expected 3 unresolved bugs after unresolve, got %d", len(unresolved)) + } +} + +func TestResolveBug_NonExistent(t *testing.T) { + store := setupTestStoreWithBugs(t) + defer store.Close() + + // Resolving a non-existent bug should not error (no rows affected is fine) + err := store.ResolveBug(999) + if err != nil { + t.Errorf("ResolveBug on non-existent bug should not error, got: %v", err) + } +} |
