Browse Source

fix: update Header tests for WorkflowBrowserModal-based open flow

The open button now opens a WorkflowBrowserModal instead of calling
the browse-directory API. Updated the test to assert modal rendering
and removed two obsolete tests that tested the old fetch-based flow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 4 months ago
parent
commit
d49f54931d
  1. 59
      src/components/__tests__/Header.test.tsx

59
src/components/__tests__/Header.test.tsx

@ -24,6 +24,13 @@ vi.mock("@/components/ProjectSetupModal", () => ({
),
}));
// Mock WorkflowBrowserModal
vi.mock("@/components/WorkflowBrowserModal", () => ({
WorkflowBrowserModal: ({ isOpen }: { isOpen: boolean }) => (
isOpen ? <div data-testid="workflow-browser-modal">Workflow Browser</div> : null
),
}));
// Mock CostIndicator
vi.mock("@/components/CostIndicator", () => ({
CostIndicator: () => <div data-testid="cost-indicator">$0.00</div>,
@ -250,18 +257,12 @@ describe("Header", () => {
expect(openButton).toBeInTheDocument();
});
it("should call browse-directory API when open button is clicked", async () => {
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve({ success: true, cancelled: true }),
});
global.fetch = mockFetch;
it("should open WorkflowBrowserModal when open button is clicked", () => {
render(<Header />);
const openButton = screen.getByTitle("Open project");
fireEvent.click(openButton);
expect(mockFetch).toHaveBeenCalledWith("/api/browse-directory");
expect(screen.getByTestId("workflow-browser-modal")).toBeInTheDocument();
});
});
@ -399,48 +400,6 @@ describe("Header", () => {
});
});
describe("File Loading via Directory Picker", () => {
it("should not call loadWorkflow when directory picker is cancelled", async () => {
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve({ success: true, cancelled: true }),
});
global.fetch = mockFetch;
render(<Header />);
const openButton = screen.getByTitle("Open project");
fireEvent.click(openButton);
// Wait for the async handler to settle
await vi.waitFor(() => {
expect(mockFetch).toHaveBeenCalledWith("/api/browse-directory");
});
expect(mockLoadWorkflow).not.toHaveBeenCalled();
});
it("should load workflow from selected directory", async () => {
const mockWorkflow = { version: "1.0", nodes: [], edges: [], name: "Test" };
const mockFetch = vi.fn()
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ success: true, path: "/path/to/project" }),
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ success: true, workflow: mockWorkflow, filename: "Test" }),
});
global.fetch = mockFetch;
render(<Header />);
const openButton = screen.getByTitle("Open project");
fireEvent.click(openButton);
await vi.waitFor(() => {
expect(mockLoadWorkflow).toHaveBeenCalledWith(mockWorkflow, "/path/to/project");
});
});
});
describe("Comments Navigation Icon", () => {
it("should not render comments icon when no comments exist", () => {
mockGetNodesWithComments.mockReturnValue([]);

Loading…
Cancel
Save