forked from DIRACGrid/diracx-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobMonitor.test.tsx
More file actions
105 lines (89 loc) · 2.94 KB
/
JobMonitor.test.tsx
File metadata and controls
105 lines (89 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {
act,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { composeStories } from "@storybook/react";
import { VirtuosoMockContext } from "react-virtuoso";
import * as stories from "../stories/JobMonitor.stories";
// Compose Storybook stories (includes all decorators/args)
const { Default, Loading, Empty, WithError } = composeStories(stories);
describe("JobMonitor", () => {
it("renders the job monitor component", async () => {
const { getByTestId, getByText } = render(<Default />);
await waitFor(() => {
expect(getByTestId("search-bar")).toBeInTheDocument();
// Verify job data is displayed
expect(getByText("List of Jobs")).toBeInTheDocument();
});
});
it("renders loading state while fetching data", async () => {
const { getByTestId } = render(<Loading />);
// Verify loading state
await waitFor(() => {
expect(getByTestId("loading-skeleton")).toBeInTheDocument();
});
});
it("renders error state when data fetch fails", async () => {
const { getByText } = render(<WithError />);
// Verify error message
await waitFor(() => {
expect(getByText("Custom error message here")).toBeInTheDocument();
});
});
it("renders empty state when no jobs are found", async () => {
const { getByText } = render(<Empty />);
// Verify empty state message
await waitFor(() => {
expect(
getByText("No data or no results match your filters."),
).toBeInTheDocument();
});
});
});
describe("JobDataTable", () => {
it("displays job data with correct columns", async () => {
const { getByText } = render(
<VirtuosoMockContext.Provider
value={{ viewportHeight: 300, itemHeight: 100 }}
>
<Default />
</VirtuosoMockContext.Provider>,
);
// Verify table headers
expect(getByText("ID")).toBeInTheDocument();
expect(getByText("Status")).toBeInTheDocument();
expect(getByText("Name")).toBeInTheDocument();
// Verify job data is displayed
await waitFor(() => {
expect(getByText("Job 1")).toBeInTheDocument();
expect(getByText("Job accepted")).toBeInTheDocument();
});
});
});
describe("JobHistoryDialog", () => {
it("renders the dialog with correct data", async () => {
const { getByText } = render(
<VirtuosoMockContext.Provider
value={{ viewportHeight: 300, itemHeight: 100 }}
>
<Default />
</VirtuosoMockContext.Provider>,
);
await act(async () => {
fireEvent.contextMenu(getByText("Job 1"));
});
// Now wait for the context menu to appear and click Get history
await act(async () => {
fireEvent.click(getByText("Get history"));
// Allow time for state updates to complete
await new Promise((resolve) => setTimeout(resolve, 0));
});
// Now check for the dialog
await waitFor(() => {
expect(screen.getByText(/Job History:/)).toBeInTheDocument();
});
});
});