-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathProjectSelector.test.tsx
More file actions
83 lines (67 loc) · 2.32 KB
/
ProjectSelector.test.tsx
File metadata and controls
83 lines (67 loc) · 2.32 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
import { setupServer } from "msw/node";
import { render } from "../test-utils";
import { screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import FeastUISansProviders from "../FeastUISansProviders";
import {
projectsListWithDefaultProject,
creditHistoryRegistry,
creditHistoryRegistryDB,
} from "../mocks/handlers";
// declare which API requests to mock
const server = setupServer(
projectsListWithDefaultProject,
creditHistoryRegistry,
creditHistoryRegistryDB,
);
// establish API mocking before all tests
beforeAll(() => server.listen());
// reset any request handlers that are declared as a part of our tests
// (i.e. for testing one-time error scenarios)
afterEach(() => server.resetHandlers());
// clean up once the tests are done
afterAll(() => server.close());
test("in a full App render, it shows the right initial project", async () => {
const user = userEvent.setup();
render(<FeastUISansProviders />);
const select = await screen.findByRole("combobox", {
name: "Select a Feast Project",
});
// Wait for Project List to Load
const options = await within(select).findAllByRole("option");
const topLevelNavigation = await screen.findByRole("navigation", {
name: "Top Level",
});
await within(topLevelNavigation).findByDisplayValue("Credit Score Project");
expect(options.length).toBe(1);
// Wait for Project Data from Registry to Load
await screen.findAllByRole("heading", {
name: /Project: credit_scoring_aws/i,
});
// Before User Event: Heading is the credit scoring project
screen.getByRole("heading", {
name: /credit_scoring_aws/i,
});
// Do the select option user event
// https://stackoverflow.com/a/69478957
await user.selectOptions(
// Find the select element
within(topLevelNavigation).getByRole("combobox"),
// Find and select the Ireland option
within(topLevelNavigation).getByRole("option", {
name: "Credit Score Project",
}),
);
// The selection should updated
expect(
within(topLevelNavigation).getByRole("option", {
name: "Credit Score Project",
selected: true,
}),
).toBeInTheDocument();
// ... and the new heading should appear
// meaning we successfully navigated
await screen.findByRole("heading", {
name: /Project: credit_scoring_aws/i,
});
});