diff --git a/src/pages/Dashboard/index.tsx b/src/pages/Dashboard/index.tsx index 94dc4225..437b8f82 100644 --- a/src/pages/Dashboard/index.tsx +++ b/src/pages/Dashboard/index.tsx @@ -108,7 +108,7 @@ export default function Dashboard() {

{issue.title}

- {issue.domain} | {new Date(issue.created_at).toLocaleDateString()} + {issue.category} | {new Date(issue.created_at).toLocaleDateString()}

diff --git a/src/pages/NewIssue/index.tsx b/src/pages/NewIssue/index.tsx index 2fa5242a..48969331 100644 --- a/src/pages/NewIssue/index.tsx +++ b/src/pages/NewIssue/index.tsx @@ -53,7 +53,7 @@ export default function NewIssue() { try { const issue = await createIssueCmd({ title: title.trim(), domain: selectedDomain, severity }); startSession(issue); - navigate(`/issue/${issue.id}/triage`); + navigate(`/issue/${issue.id}/logs`); } catch (err) { setError(String(err)); setIsSubmitting(false); diff --git a/tests/unit/historyStore.test.ts b/tests/unit/historyStore.test.ts new file mode 100644 index 00000000..2b88e62e --- /dev/null +++ b/tests/unit/historyStore.test.ts @@ -0,0 +1,97 @@ +import { describe, it, expect, beforeEach, vi } from "vitest"; +import { invoke } from "@tauri-apps/api/core"; +import { useHistoryStore } from "@/stores/historyStore"; +import type { IssueSummary } from "@/lib/tauriCommands"; + +const mockInvoke = vi.mocked(invoke); + +const makeIssue = (overrides: Partial = {}): IssueSummary => ({ + id: "issue-001", + title: "Test issue", + severity: "P3", + status: "open", + category: "linux", + log_count: 0, + step_count: 0, + created_at: new Date().toISOString(), + updated_at: new Date().toISOString(), + ...overrides, +}); + +describe("History Store", () => { + beforeEach(() => { + useHistoryStore.setState({ issues: [], isLoading: false, error: null, searchQuery: "" }); + mockInvoke.mockReset(); + }); + + it("loadIssues populates the issues array", async () => { + const issues = [makeIssue(), makeIssue({ id: "issue-002", title: "Another issue" })]; + mockInvoke.mockResolvedValueOnce(issues); + + await useHistoryStore.getState().loadIssues(); + + expect(useHistoryStore.getState().issues).toHaveLength(2); + expect(useHistoryStore.getState().isLoading).toBe(false); + }); + + it("loadIssues sets error on failure without clearing existing issues", async () => { + const existing = [makeIssue()]; + useHistoryStore.setState({ issues: existing }); + mockInvoke.mockRejectedValueOnce(new Error("DB locked")); + + await useHistoryStore.getState().loadIssues(); + + expect(useHistoryStore.getState().error).toContain("DB locked"); + expect(useHistoryStore.getState().isLoading).toBe(false); + }); + + it("open issue count includes status=open and status=triaging", () => { + useHistoryStore.setState({ + issues: [ + makeIssue({ status: "open" }), + makeIssue({ id: "002", status: "triaging" }), + makeIssue({ id: "003", status: "resolved" }), + makeIssue({ id: "004", status: "open" }), + ], + }); + + const { issues } = useHistoryStore.getState(); + const openCount = issues.filter( + (i) => i.status === "open" || i.status === "triaging" + ).length; + + expect(openCount).toBe(3); + }); + + it("newly created issue with status=open is counted as active", () => { + useHistoryStore.setState({ issues: [makeIssue({ status: "open" })] }); + + const { issues } = useHistoryStore.getState(); + const openCount = issues.filter( + (i) => i.status === "open" || i.status === "triaging" + ).length; + + expect(openCount).toBe(1); + }); + + it("resolved issues are not counted as active", () => { + useHistoryStore.setState({ + issues: [makeIssue({ status: "resolved" }), makeIssue({ id: "002", status: "resolved" })], + }); + + const { issues } = useHistoryStore.getState(); + const openCount = issues.filter( + (i) => i.status === "open" || i.status === "triaging" + ).length; + + expect(openCount).toBe(0); + }); + + it("issue category field is present (not domain)", () => { + const issue = makeIssue({ category: "kubernetes" }); + useHistoryStore.setState({ issues: [issue] }); + + const stored = useHistoryStore.getState().issues[0]; + expect(stored.category).toBe("kubernetes"); + }); +});