-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathJobStateFilters.test.tsx
More file actions
67 lines (54 loc) · 1.8 KB
/
JobStateFilters.test.tsx
File metadata and controls
67 lines (54 loc) · 1.8 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
import { JobState } from "@services/types";
import {
createMemoryHistory,
createRootRoute,
createRoute,
createRouter,
Outlet,
RouterProvider,
stripSearchParams,
} from "@tanstack/react-router";
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";
import { defaultValues, jobSearchSchema } from "../routes/jobs/index.schema";
import { JobStateFilters } from "./JobStateFilters";
const rootRoute = createRootRoute({
component: () => <Outlet />,
});
const jobsRoute = createRoute({
component: () => <JobStateFilters />,
getParentRoute: () => rootRoute,
path: "/jobs",
search: {
middlewares: [stripSearchParams(defaultValues)],
},
validateSearch: jobSearchSchema,
});
const routeTree = rootRoute.addChildren([jobsRoute]);
const renderWithLocation = async (location: string) => {
const history = createMemoryHistory({
initialEntries: [location],
});
const router = createRouter({
history,
routeTree,
});
await router.load();
return render(<RouterProvider router={router} />);
};
describe("JobStateFilters", () => {
test("only the selected state link is active", async () => {
await renderWithLocation(`/jobs?state=${JobState.Discarded}`);
const discardedLink = await screen.findByRole("link", {
name: "Discarded",
});
const runningLink = screen.getByRole("link", { name: "Running" });
expect(discardedLink).toHaveAttribute("data-status", "active");
expect(runningLink).not.toHaveAttribute("data-status", "active");
});
test("running is active when no state is explicitly selected", async () => {
await renderWithLocation("/jobs");
const runningLink = await screen.findByRole("link", { name: "Running" });
expect(runningLink).toHaveAttribute("data-status", "active");
});
});