-
Notifications
You must be signed in to change notification settings - Fork 1k
/
FeastUISansProviders.test.tsx
136 lines (105 loc) · 3.76 KB
/
FeastUISansProviders.test.tsx
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React from "react";
import { setupServer } from "msw/node";
import { render } from "./test-utils";
import {
waitFor,
screen,
waitForElementToBeRemoved,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import FeastUISansProviders from "./FeastUISansProviders";
import {
projectsListWithDefaultProject,
creditHistoryRegistry,
} from "./mocks/handlers";
import { readFileSync } from "fs";
import { feast } from "./protos";
import path from "path";
// declare which API requests to mock
const server = setupServer(
projectsListWithDefaultProject,
creditHistoryRegistry
);
const registry = readFileSync(path.resolve(__dirname, "../public/registry.db"));
const parsedRegistry = feast.core.Registry.decode(registry);
// 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("full app rendering", async () => {
render(<FeastUISansProviders />);
// Rendering the app without any paths should mean
// rendering the <RootProjectSelectionPage />
// Therefore we should expect to see
// "Welcome to Feast."
const noProjectSelectedElement = screen.getByText(/Welcome to Feast/i);
expect(noProjectSelectedElement).toBeInTheDocument();
// Wait for the Redirect, and check that it got removed
await waitForElementToBeRemoved(noProjectSelectedElement);
expect(screen.queryByText(/Welcome to Feast/i)).toBeNull();
// Explore Panel Should Appear
expect(screen.getByText(/Explore this Project/i)).toBeInTheDocument();
const projectNameRegExp = new RegExp(
parsedRegistry.projectMetadata[0].project!,
"i"
);
// It should load the default project, which is credit_scoring_aws
await waitFor(() => {
expect(screen.getByText(projectNameRegExp)).toBeInTheDocument();
});
});
test("routes are reachable", async () => {
const user = userEvent.setup();
render(<FeastUISansProviders />);
// Wait for content to load
await screen.findByText(/Explore this Project/i);
const mainRoutesNames = [
"Data Sources",
"Entities",
"Feature Views",
"Feature Services",
"Datasets",
];
for (const routeName of mainRoutesNames) {
// Main heading shouldn't start with the route name
expect(
screen.queryByRole("heading", { name: routeName, level: 1 })
).toBeNull();
const routeRegExp = new RegExp(routeName, "i");
await user.click(screen.getByRole("button", { name: routeRegExp }));
// Should land on a page with the heading
screen.getByRole("heading", {
name: routeName,
level: 1,
});
}
});
const spec = parsedRegistry.featureViews[0].spec!;
const featureViewName = spec.name!;
const featureName = spec.features![0]!.name!;
test("features are reachable", async () => {
const user = userEvent.setup();
render(<FeastUISansProviders />);
// Wait for content to load
await screen.findByText(/Explore this Project/i);
const routeRegExp = new RegExp("Feature Views", "i");
await user.click(screen.getByRole("button", { name: routeRegExp }));
screen.getByRole("heading", {
name: "Feature Views",
});
await screen.findAllByText(/Feature Views/i);
const fvRegExp = new RegExp(featureViewName, "i");
await user.click(screen.getByRole("link", { name: fvRegExp }));
await screen.findByText(featureName);
const fRegExp = new RegExp(featureName, "i");
await user.click(screen.getByRole("link", { name: fRegExp }));
// Should land on a page with the heading
// await screen.findByText("Feature: " + featureName);
screen.getByRole("heading", {
name: "Feature: " + featureName,
level: 1,
});
});