Skip to content

Commit a845192

Browse files
test(frontend): add tests for BaseSingleWorkflowView
1 parent a238f06 commit a845192

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

frontend/dashboard/src/mocks/responses/workflows/SingleWorkflowViewQueryResponse.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export const singleWorkflowViewQueryResponse = {
88
},
99
templateRef: "conditional-steps",
1010
parameters: {},
11+
creator: {
12+
creatorId: "abc12345",
13+
},
1114
status: {
1215
__typename: "WorkflowSucceededStatus",
1316
startTime: "2025-08-22T10:35:22+00:00",
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { render, screen, waitFor } from "@testing-library/react";
2+
import "@testing-library/jest-dom";
3+
import BaseSingleWorkflowView from "relay-workflows-lib/lib/views/BaseSingleWorkflowView";
4+
import { SingleWorkflowViewQuery } from "relay-workflows-lib/lib/views/SingleWorkflowView";
5+
import { server } from "relay-workflows-lib/tests/mocks/browser.ts";
6+
import { RelayEnvironmentProvider, useLazyLoadQuery } from "react-relay";
7+
import { getRelayEnvironment } from "dashboard/src/RelayEnvironment";
8+
import { MemoryRouter, useSearchParams } from "react-router-dom";
9+
import { SingleWorkflowViewQuery as SingleWorkflowViewQueryType } from "relay-workflows-lib/lib/views/__generated__/SingleWorkflowViewQuery.graphql";
10+
import userEvent from "@testing-library/user-event";
11+
import * as tasksFlowUtils from "workflows-lib/lib/utils/tasksFlowUtils";
12+
import { useMemo } from "react";
13+
14+
const QueryWrappedBaseSingleWorkflowView = () => {
15+
const [searchParams] = useSearchParams();
16+
const taskParam = searchParams.get("tasks");
17+
18+
const taskIds = useMemo(() => {
19+
if (!taskParam) return [];
20+
try {
21+
return JSON.parse(taskParam) as string[];
22+
} catch {
23+
return [];
24+
}
25+
}, [taskParam]);
26+
27+
const data = useLazyLoadQuery<SingleWorkflowViewQueryType>(
28+
SingleWorkflowViewQuery,
29+
{
30+
visit: {
31+
proposalCode: "mg",
32+
proposalNumber: 36964,
33+
number: 1,
34+
},
35+
name: "conditional-steps-first",
36+
},
37+
);
38+
return (
39+
<BaseSingleWorkflowView fragmentRef={data.workflow} taskIds={taskIds} />
40+
);
41+
};
42+
43+
describe("BaseSingleWorkflowView", () => {
44+
const user = userEvent.setup();
45+
const highlightSpy = vi.spyOn(tasksFlowUtils, "addHighlightsAndFills");
46+
47+
beforeAll(() => {
48+
server.listen();
49+
});
50+
51+
beforeEach(async () => {
52+
const environment = await getRelayEnvironment();
53+
54+
render(
55+
<MemoryRouter>
56+
<RelayEnvironmentProvider environment={environment}>
57+
<QueryWrappedBaseSingleWorkflowView />
58+
</RelayEnvironmentProvider>
59+
</MemoryRouter>,
60+
);
61+
});
62+
63+
afterEach(() => {
64+
vi.resetAllMocks();
65+
});
66+
67+
afterAll(() => {
68+
server.close();
69+
});
70+
71+
it("highlights the output tasks", async () => {
72+
expect(
73+
await screen.findByText("conditional-steps-first"),
74+
).toBeInTheDocument();
75+
const outputButton = screen.getByText("OUTPUT");
76+
77+
await user.click(outputButton);
78+
expect(highlightSpy).toHaveBeenLastCalledWith(
79+
expect.anything(),
80+
[
81+
"conditional-steps-first-1223470002",
82+
"conditional-steps-first-2863409095",
83+
"conditional-steps-first-3590043386",
84+
"conditional-steps-first-567981434",
85+
],
86+
null,
87+
);
88+
});
89+
90+
it("clears the output tasks", async () => {
91+
expect(
92+
await screen.findByText("conditional-steps-first"),
93+
).toBeInTheDocument();
94+
await user.click(screen.getByText("CLEAR"));
95+
expect(highlightSpy).toHaveBeenLastCalledWith(expect.anything(), [], null);
96+
});
97+
98+
it("renders the artifact list", async () => {
99+
expect(await screen.findAllByText("main.log")).toHaveLength(2);
100+
});
101+
102+
it("fills the corresponding task node when an artifact is hovered over", async () => {
103+
const artifact = await screen.findByRole("cell", { name: "less-than-5" });
104+
await user.hover(artifact);
105+
await waitFor(() => {
106+
expect(highlightSpy).toHaveBeenLastCalledWith(
107+
expect.anything(),
108+
[],
109+
"conditional-steps-first-2863409095",
110+
);
111+
});
112+
await user.unhover(artifact);
113+
await waitFor(() => {
114+
expect(highlightSpy).toHaveBeenLastCalledWith(
115+
expect.anything(),
116+
[],
117+
null,
118+
);
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)