Files
fusion/packages/dashboard/app/components/__tests__/GraphWorkflowSwitcherSlot.test.tsx
gsxdsm 6c51bd1d44 FN-6989: make workflow editor float
Make workflow editing open in the shared floating window shell.

- Replace the workflow editor modal overlay with FloatingWindow drag, resize, and geometry persistence.
- Let graph and header workflow switcher callbacks forward the selected workflow id into the editor.
- Update workflow editor sizing styles and mobile full-screen behavior for the floating shell.
- Add regression coverage for floating-window behavior, resize ownership, and workflow id forwarding.

Files changed:
 .../app/components/GraphWorkflowSwitcherSlot.tsx   |   6 +-
 .../app/components/HeaderWorkflowSwitcherSlot.tsx  |   6 +-
 .../app/components/WorkflowNodeEditor.css          |  51 +++++++--
 .../app/components/WorkflowNodeEditor.tsx          |  33 +++---
 .../__tests__/GraphWorkflowSwitcherSlot.test.tsx   |  11 ++
 .../__tests__/HeaderWorkflowSwitcherSlot.test.tsx  |  10 ++
 .../__tests__/WorkflowNodeEditor.css.test.ts       |  21 ++--
 .../__tests__/WorkflowNodeEditor.test.tsx          | 126 +++++++++++++++++----
 8 files changed, 208 insertions(+), 56 deletions(-)

Fusion-Task-Id: FN-6989

Fusion-Task-Lineage: cf762608-37d5-43be-8cbe-20fd1ae56296
2026-06-25 13:27:28 -07:00

185 lines
7.3 KiB
TypeScript

import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { BoardWorkflowDefinition, BoardWorkflowsPayload } from "../../api";
import { filterTasksByGraphWorkflowSelection, GraphWorkflowSwitcherSlot, type GraphWorkflowSelection } from "../GraphWorkflowSwitcherSlot";
const fetchBoardWorkflowsMock = vi.fn();
const subscribeSseMock = vi.fn(() => vi.fn());
vi.mock("../../api", () => ({
fetchBoardWorkflows: (...args: unknown[]) => fetchBoardWorkflowsMock(...args),
}));
vi.mock("../../sse-bus", () => ({
subscribeSse: (...args: unknown[]) => subscribeSseMock(...args),
}));
const DEFAULT_WORKFLOW: BoardWorkflowDefinition = {
id: "builtin:coding",
name: "Coding",
columns: [],
};
const CUSTOM_WORKFLOW: BoardWorkflowDefinition = {
id: "wf-review",
name: "Review",
columns: [],
};
function workflowPayload(overrides: Partial<BoardWorkflowsPayload> = {}): BoardWorkflowsPayload {
return {
flagEnabled: true,
defaultWorkflowId: DEFAULT_WORKFLOW.id,
workflows: [DEFAULT_WORKFLOW, CUSTOM_WORKFLOW],
taskWorkflowIds: {},
...overrides,
};
}
function appendHeaderWorkflowSlot() {
const slot = document.createElement("div");
slot.id = "header-workflow-slot";
slot.className = "header-workflow-slot";
document.body.appendChild(slot);
return slot;
}
beforeEach(() => {
sessionStorage.clear();
fetchBoardWorkflowsMock.mockReset();
subscribeSseMock.mockClear();
fetchBoardWorkflowsMock.mockResolvedValue(workflowPayload());
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null);
});
afterEach(() => {
document.getElementById("header-workflow-slot")?.remove();
vi.restoreAllMocks();
});
describe("filterTasksByGraphWorkflowSelection", () => {
it("uses task workflow assignments with default fallback for graph scoping", () => {
const tasks = [
{ id: "FN-default" },
{ id: "FN-unassigned" },
{ id: "FN-review" },
{ id: "FN-unknown" },
];
const selection: GraphWorkflowSelection = {
boardWorkflows: workflowPayload({
taskWorkflowIds: {
"FN-review": CUSTOM_WORKFLOW.id,
"FN-unknown": "wf-missing",
},
}),
selectedWorkflow: DEFAULT_WORKFLOW,
};
expect(filterTasksByGraphWorkflowSelection(tasks, "project-graph", selection).map((task) => task.id)).toEqual([
"FN-default",
"FN-unassigned",
]);
expect(filterTasksByGraphWorkflowSelection(tasks, "project-graph", { ...selection, selectedWorkflow: CUSTOM_WORKFLOW }).map((task) => task.id)).toEqual([
"FN-review",
]);
});
it("preserves unfiltered graph tasks without a project or workflow payload", () => {
const tasks = [{ id: "FN-a" }, { id: "FN-b" }];
const selection: GraphWorkflowSelection = {
boardWorkflows: workflowPayload({ taskWorkflowIds: { "FN-b": CUSTOM_WORKFLOW.id } }),
selectedWorkflow: CUSTOM_WORKFLOW,
};
expect(filterTasksByGraphWorkflowSelection(tasks, undefined, selection)).toBe(tasks);
expect(filterTasksByGraphWorkflowSelection(tasks, "project-graph", null)).toBe(tasks);
});
});
describe("GraphWorkflowSwitcherSlot", () => {
it("portals the shared workflow switcher into the header workflow slot", async () => {
const headerSlot = appendHeaderWorkflowSlot();
const onWorkflowSelectionChange = vi.fn();
render(<GraphWorkflowSwitcherSlot projectId="project-graph" onWorkflowSelectionChange={onWorkflowSelectionChange} />);
const selector = await screen.findByTestId("workflow-switcher");
expect(headerSlot.contains(selector)).toBe(true);
expect(headerSlot.querySelector(".board-workflow-toolbar")).not.toBeNull();
await waitFor(() => {
expect(onWorkflowSelectionChange).toHaveBeenLastCalledWith({
boardWorkflows: workflowPayload(),
selectedWorkflow: DEFAULT_WORKFLOW,
});
});
});
it("refreshes the board-workflows payload when the dropdown opens", async () => {
appendHeaderWorkflowSlot();
render(<GraphWorkflowSwitcherSlot projectId="project-refresh" />);
const selector = await screen.findByTestId("workflow-switcher");
await waitFor(() => expect(fetchBoardWorkflowsMock).toHaveBeenCalledTimes(1));
fireEvent.click(selector);
await waitFor(() => expect(fetchBoardWorkflowsMock).toHaveBeenCalledTimes(2));
expect(screen.getByRole("listbox", { name: "Workflow" })).toBeInTheDocument();
});
it("reports selection changes so App can scope graph tasks", async () => {
appendHeaderWorkflowSlot();
const onWorkflowSelectionChange = vi.fn();
render(<GraphWorkflowSwitcherSlot projectId="project-select" onWorkflowSelectionChange={onWorkflowSelectionChange} />);
fireEvent.click(await screen.findByTestId("workflow-switcher"));
fireEvent.click(screen.getByTestId("workflow-switcher-option-wf-review"));
await waitFor(() => {
const lastSelection = onWorkflowSelectionChange.mock.calls.at(-1)?.[0] as GraphWorkflowSelection | null;
expect(lastSelection?.selectedWorkflow.id).toBe("wf-review");
});
});
it("forwards dropdown edit workflow ids to the graph editor launcher", async () => {
appendHeaderWorkflowSlot();
const onOpenWorkflowEditor = vi.fn();
render(<GraphWorkflowSwitcherSlot projectId="project-edit" onOpenWorkflowEditor={onOpenWorkflowEditor} />);
fireEvent.click(await screen.findByTestId("workflow-switcher"));
fireEvent.click(screen.getByTestId("workflow-switcher-edit-wf-review"));
expect(onOpenWorkflowEditor).toHaveBeenCalledWith("wf-review");
});
it("renders no dropdown shell when the header slot is absent", async () => {
render(<GraphWorkflowSwitcherSlot projectId="project-no-slot" />);
await waitFor(() => expect(fetchBoardWorkflowsMock).toHaveBeenCalled());
expect(screen.queryByTestId("workflow-switcher")).toBeNull();
expect(document.querySelector(".board-workflow-toolbar")).toBeNull();
});
it("renders no dropdown shell when workflow mode is disabled, empty, or not switchable", async () => {
const headerSlot = appendHeaderWorkflowSlot();
const { rerender } = render(<GraphWorkflowSwitcherSlot projectId="project-disabled" />);
fetchBoardWorkflowsMock.mockResolvedValue(workflowPayload({ flagEnabled: false, workflows: [] }));
rerender(<GraphWorkflowSwitcherSlot projectId="project-disabled-next" />);
await waitFor(() => expect(fetchBoardWorkflowsMock).toHaveBeenCalledWith("project-disabled-next"));
expect(screen.queryByTestId("workflow-switcher")).toBeNull();
expect(headerSlot.childElementCount).toBe(0);
fetchBoardWorkflowsMock.mockResolvedValue(workflowPayload({ workflows: [] }));
rerender(<GraphWorkflowSwitcherSlot projectId="project-empty" />);
await waitFor(() => expect(fetchBoardWorkflowsMock).toHaveBeenCalledWith("project-empty"));
expect(screen.queryByTestId("workflow-switcher")).toBeNull();
expect(headerSlot.childElementCount).toBe(0);
fetchBoardWorkflowsMock.mockResolvedValue(workflowPayload({ workflows: [DEFAULT_WORKFLOW] }));
rerender(<GraphWorkflowSwitcherSlot projectId="project-single" />);
await waitFor(() => expect(fetchBoardWorkflowsMock).toHaveBeenCalledWith("project-single"));
expect(screen.queryByTestId("workflow-switcher")).toBeNull();
expect(headerSlot.childElementCount).toBe(0);
});
});