-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.test.tsx
97 lines (86 loc) · 3.08 KB
/
App.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
import * as React from "react";
import * as ReactDOM from "react-dom";
import { fireEvent, render } from "@testing-library/react";
import App from "./App";
jest.mock("./api/api", () => {
const actualApi = jest.requireActual("./api/api");
return {
...actualApi,
apiFetch: jest.fn().mockReturnValue({ _items: [], trial_ids: [] })
};
});
jest.mock("./components/info/InfoProvider", () => {
const { InfoContext, ...actualInfoProvider } = jest.requireActual(
"./components/info/InfoProvider"
);
return {
__esModule: true,
...actualInfoProvider,
InfoContext,
default: jest.fn().mockImplementation(props => {
return (
<InfoContext.Provider
value={{ supportedTemplates: { manifests: [] } }}
>
{props.children}
</InfoContext.Provider>
);
})
};
});
jest.mock("./components/identity/IdentityProvider", () => {
const { AuthContext } = jest.requireActual(
"./components/identity/AuthProvider"
);
const { UserContext } = jest.requireActual(
"./components/identity/UserProvider"
);
const actualIdentityProvider = jest.requireActual(
"./components/identity/IdentityProvider"
);
return {
__esModule: true,
...actualIdentityProvider,
default: jest.fn().mockImplementation(props => {
return (
<AuthContext.Provider
value={{
state: "logged-in",
userInfo: { idToken: "test-token" }
}}
>
<UserContext.Provider
value={{
approval_date: "1/1/1",
showAssays: true,
showManifests: true,
showAnalyses: true
}}
>
{props.children}
</UserContext.Provider>
</AuthContext.Provider>
);
})
};
});
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
test("users can navigate to pages as expected", async () => {
const { getByText, findByText, findByTitle } = render(<App />);
fireEvent.click(getByText(/browse data/i));
expect(await findByText(/trial view/i)).toBeInTheDocument();
fireEvent.click(getByText(/pipelines/i));
expect(await findByText(/rima/i)).toBeInTheDocument();
fireEvent.click(getByText(/transfer assays/i));
expect(await findByText(/the cidc cli/i)).toBeInTheDocument();
fireEvent.click(getByText(/schema/i));
expect(await findByTitle(/cidc schema/i)).toBeInTheDocument();
fireEvent.click(getByText(/analyses/i));
expect(await findByText(/the cidc cli/i)).toBeInTheDocument();
fireEvent.click(getByText(/manifests/i));
expect(await findByText(/empty manifest template/)).toBeInTheDocument();
});