refine(confidence-engine): clarify portfolio investigation actions

This commit is contained in:
2026-09-03 07:01:18 +01:00
parent 32e1b01767
commit 0da7b63e30
3 changed files with 94 additions and 12 deletions
+56 -5
View File
@@ -1,14 +1,22 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import React from "react";
import { render, screen } from "@testing-library/react";
import { render, screen, fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom";
vi.mock("next/navigation", () => ({
useRouter: () => ({ push: () => {} }),
}));
vi.mock("@/lib/storage/investigation-storage", async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
clearInvestigation: vi.fn(),
};
});
// ---------------------------------------------------------------------------
// Route-level assertions for v0.55 architecture
// Route-level assertions for v0.55 architecture + v0.56 action semantics
// Portfolio = /index ; Investigation Report = dedicated page
// ---------------------------------------------------------------------------
@@ -48,16 +56,34 @@ describe("Portfolio page (v0.55 route architecture)", () => {
localStorage.clear();
render(React.createElement(Portfolio));
expect(await screen.findByText(/Create new investigation/i)).toBeInTheDocument();
// Open/Continue investigation buttons absent when no investigation exists
expect(screen.queryByText(/Open investigation/i)).not.toBeInTheDocument();
expect(screen.queryByText(/Continue investigation/i)).not.toBeInTheDocument();
});
it("shows Open investigation card when one persisted investigation exists", async () => {
it("does not show Restart investigation when no investigation exists", async () => {
localStorage.clear();
render(React.createElement(Portfolio));
expect(screen.queryByText(/Restart investigation/i)).not.toBeInTheDocument();
});
it("shows Continue investigation card when one persisted investigation exists", async () => {
localStorage.setItem(
"confidence-engine-investigation",
JSON.stringify(makeSnapshot()),
);
render(React.createElement(Portfolio));
expect(await screen.findByText(/Open investigation/i)).toBeInTheDocument();
expect(await screen.findByText(/Continue investigation/i)).toBeInTheDocument();
localStorage.removeItem("confidence-engine-investigation");
});
it("does not show Open investigation text when one persisted investigation exists", async () => {
localStorage.setItem(
"confidence-engine-investigation",
JSON.stringify(makeSnapshot()),
);
render(React.createElement(Portfolio));
expect(screen.queryByText(/Open investigation/i)).not.toBeInTheDocument();
localStorage.removeItem("confidence-engine-investigation");
});
@@ -87,6 +113,31 @@ describe("Portfolio page (v0.55 route architecture)", () => {
expect(screen.queryByText(/View report/i)).not.toBeInTheDocument();
localStorage.removeItem("confidence-engine-investigation");
});
it("shows Restart investigation button when one persisted investigation exists", async () => {
localStorage.setItem(
"confidence-engine-investigation",
JSON.stringify(makeSnapshot()),
);
render(React.createElement(Portfolio));
expect(await screen.findByText(/Restart investigation/i)).toBeInTheDocument();
localStorage.removeItem("confidence-engine-investigation");
});
it("card does not contain Create new investigation when one persisted investigation exists", async () => {
localStorage.setItem(
"confidence-engine-investigation",
JSON.stringify(makeSnapshot()),
);
render(React.createElement(Portfolio));
// Portfolio-level "+ Create new investigation" is still present (below card)
expect(await screen.findByText(/Create new investigation/i)).toBeInTheDocument();
// But the investigations section card does NOT contain it (no duplicate)
const card = document.querySelector("section.mb-10");
const btns = Array.from(card.querySelectorAll('a,button'));
expect(btns.some(el => /Create new investigation/i.test(el.textContent))).toBe(false);
localStorage.removeItem("confidence-engine-investigation");
});
});
describe("Investigation Report page (v0.55 route architecture)", () => {