@databiosphere/findable-ui 50.5.0 → 50.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/lib/components/Export/components/ExportMethod/constants.d.ts +2 -0
  2. package/lib/components/Export/components/ExportMethod/constants.js +6 -0
  3. package/lib/components/Export/components/ExportMethod/exportMethod.d.ts +2 -1
  4. package/lib/components/Export/components/ExportMethod/exportMethod.js +6 -4
  5. package/lib/components/Export/components/ExportMethod/exportMethod.styles.d.ts +8 -2
  6. package/lib/components/Export/components/ExportMethod/exportMethod.styles.js +4 -6
  7. package/package.json +6 -1
  8. package/src/components/Export/components/ExportMethod/constants.ts +8 -0
  9. package/src/components/Export/components/ExportMethod/exportMethod.styles.ts +10 -8
  10. package/src/components/Export/components/ExportMethod/exportMethod.tsx +13 -4
  11. package/.eslintignore +0 -5
  12. package/.eslintrc.json +0 -79
  13. package/.github/copilot-instructions.md +0 -176
  14. package/.github/workflows/release-please.yml +0 -49
  15. package/.github/workflows/run-checks.yml +0 -57
  16. package/.husky/commit-msg +0 -18
  17. package/.husky/pre-commit +0 -43
  18. package/.prettierignore +0 -19
  19. package/.prettierrc.json +0 -1
  20. package/.release-please-manifest.json +0 -3
  21. package/.storybook/main.ts +0 -10
  22. package/.storybook/preview-head.html +0 -4
  23. package/.storybook/preview.js +0 -6
  24. package/CHANGELOG.md +0 -1110
  25. package/CLAUDE.md +0 -214
  26. package/backend/README.md +0 -64
  27. package/backend/__init__.py +0 -0
  28. package/backend/controllers/__init__.py +0 -0
  29. package/backend/controllers/facets_controller.py +0 -16
  30. package/backend/controllers/models.py +0 -11
  31. package/backend/main.py +0 -8
  32. package/backend/requirements.txt +0 -4
  33. package/backend/services/__init__.py +0 -0
  34. package/backend/services/facets_service.py +0 -68
  35. package/backend/services/models.py +0 -43
  36. package/commitlint.config.js +0 -1
  37. package/docs/TRUSTED_PUBLISHING.md +0 -132
  38. package/jest.config.js +0 -6
  39. package/release-please-config.json +0 -23
  40. package/tests/azulFileDownload.test.tsx +0 -96
  41. package/tests/buildCategoryViews.test.ts +0 -282
  42. package/tests/buildRequestFilters.test.ts +0 -60
  43. package/tests/buildRequestManifest.test.ts +0 -103
  44. package/tests/chart.test.tsx +0 -274
  45. package/tests/chartSortUtils.test.ts +0 -119
  46. package/tests/chartView.test.tsx +0 -48
  47. package/tests/dataDictionaryColumnFilters.test.tsx +0 -101
  48. package/tests/dataDictionary_utils.test.ts +0 -153
  49. package/tests/fetchApi.test.ts +0 -93
  50. package/tests/filter.test.tsx +0 -100
  51. package/tests/filterMenu.test.ts +0 -100
  52. package/tests/filterRange.test.tsx +0 -372
  53. package/tests/filterSortUtils.test.ts +0 -180
  54. package/tests/filters.test.tsx +0 -61
  55. package/tests/getFacetedMinMaxValues.test.ts +0 -166
  56. package/tests/getFilterSortType.test.ts +0 -45
  57. package/tests/getProfileStatus.test.ts +0 -290
  58. package/tests/linkCell.test.tsx +0 -89
  59. package/tests/markdownCell.test.tsx +0 -52
  60. package/tests/provider.test.tsx +0 -189
  61. package/tests/research.chatState.test.ts +0 -463
  62. package/tests/research.fetchResponse.test.ts +0 -164
  63. package/tests/research.queryProvider.test.ts +0 -321
  64. package/tests/research.useKeyShortCuts.test.ts +0 -256
  65. package/tests/rowSelectionValidation.test.ts +0 -282
  66. package/tests/setup.ts +0 -19
  67. package/tests/stepIcon.test.tsx +0 -42
  68. package/tests/tableFilter.test.tsx +0 -90
  69. package/tests/terraProfileProvider.test.tsx +0 -117
  70. package/tests/theme.test.ts +0 -465
  71. package/tests/toggleButtonGroupProvider.test.tsx +0 -125
  72. package/tests/transformRoute.test.ts +0 -21
  73. package/tests/tsconfig.json +0 -8
  74. package/tests/useFileLocation.test.ts +0 -36
  75. package/tests/useRequestManifest.test.ts +0 -201
  76. package/tests/useRouteHistory.test.ts +0 -97
  77. package/tests/useSessionActive.test.ts +0 -106
  78. package/tests/useWindowResize.test.ts +0 -130
  79. package/tests/viewModelBuilders_utils.test.ts +0 -58
  80. package/tests/viewToggle.test.tsx +0 -54
  81. package/tsconfig.json +0 -25
@@ -1,290 +0,0 @@
1
- import {
2
- LoginStatus,
3
- REQUEST_STATUS,
4
- } from "../src/providers/authentication/terra/hooks/common/entities";
5
- import { TerraNIHResponse } from "../src/providers/authentication/terra/hooks/useFetchTerraNIHProfile";
6
- import { TerraResponse } from "../src/providers/authentication/terra/hooks/useFetchTerraProfile";
7
- import { TerraTermsOfServiceResponse } from "../src/providers/authentication/terra/hooks/useFetchTerraTermsOfService";
8
- import { TERRA_PROFILE_STATUS } from "../src/providers/authentication/terra/types";
9
- import { getProfileStatus } from "../src/providers/authentication/terra/utils";
10
-
11
- const LOGIN_STATUS_NIH_COMPLETED: LoginStatus<TerraNIHResponse> = {
12
- isSuccess: true,
13
- isSupported: true,
14
- requestStatus: REQUEST_STATUS.COMPLETED,
15
- response: undefined,
16
- };
17
-
18
- const LOGIN_STATUS_TERRA_COMPLETED: LoginStatus<TerraResponse> = {
19
- isSuccess: true,
20
- isSupported: true,
21
- requestStatus: REQUEST_STATUS.COMPLETED,
22
- response: undefined,
23
- };
24
-
25
- const LOGIN_STATUS_TOS_COMPLETED: LoginStatus<TerraTermsOfServiceResponse> = {
26
- isSuccess: true,
27
- isSupported: true,
28
- requestStatus: REQUEST_STATUS.COMPLETED,
29
- response: undefined,
30
- };
31
-
32
- const LOGIN_STATUS_TOS_COMPLETED_UNSUCCESSFUL: LoginStatus<TerraTermsOfServiceResponse> =
33
- {
34
- isSuccess: false,
35
- isSupported: true,
36
- requestStatus: REQUEST_STATUS.COMPLETED,
37
- response: undefined,
38
- };
39
-
40
- const LOGIN_STATUS_NIH_NOT_STARTED: LoginStatus<TerraNIHResponse> = {
41
- isSuccess: false,
42
- isSupported: true,
43
- requestStatus: REQUEST_STATUS.NOT_STARTED,
44
- response: undefined,
45
- };
46
-
47
- const LOGIN_STATUS_TERRA_NOT_STARTED: LoginStatus<TerraResponse> = {
48
- isSuccess: false,
49
- isSupported: true,
50
- requestStatus: REQUEST_STATUS.NOT_STARTED,
51
- response: undefined,
52
- };
53
-
54
- const LOGIN_STATUS_TOS_NOT_STARTED: LoginStatus<TerraTermsOfServiceResponse> = {
55
- isSuccess: false,
56
- isSupported: true,
57
- requestStatus: REQUEST_STATUS.NOT_STARTED,
58
- response: undefined,
59
- };
60
-
61
- const LOGIN_STATUS_NIH_PENDING: LoginStatus<TerraNIHResponse> = {
62
- isSuccess: false,
63
- isSupported: true,
64
- requestStatus: REQUEST_STATUS.PENDING,
65
- response: undefined,
66
- };
67
-
68
- const LOGIN_STATUS_TERRA_PENDING: LoginStatus<TerraResponse> = {
69
- isSuccess: false,
70
- isSupported: true,
71
- requestStatus: REQUEST_STATUS.PENDING,
72
- response: undefined,
73
- };
74
-
75
- const LOGIN_STATUS_TOS_PENDING: LoginStatus<TerraTermsOfServiceResponse> = {
76
- isSuccess: false,
77
- isSupported: true,
78
- requestStatus: REQUEST_STATUS.PENDING,
79
- response: undefined,
80
- };
81
-
82
- const LOGIN_STATUS_NIH_UNSUPPORTED: LoginStatus<TerraNIHResponse> = {
83
- isSuccess: false,
84
- isSupported: false,
85
- requestStatus: REQUEST_STATUS.NOT_STARTED,
86
- response: undefined,
87
- };
88
-
89
- const LOGIN_STATUS_TERRA_UNSUPPORTED: LoginStatus<TerraResponse> = {
90
- isSuccess: false,
91
- isSupported: false,
92
- requestStatus: REQUEST_STATUS.NOT_STARTED,
93
- response: undefined,
94
- };
95
-
96
- const LOGIN_STATUS_TOS_UNSUPPORTED: LoginStatus<TerraTermsOfServiceResponse> = {
97
- isSuccess: false,
98
- isSupported: false,
99
- requestStatus: REQUEST_STATUS.NOT_STARTED,
100
- response: undefined,
101
- };
102
-
103
- describe("getProfileStatus", () => {
104
- test("not authenticated, services not started", () => {
105
- expect(
106
- getProfileStatus(
107
- false,
108
- LOGIN_STATUS_NIH_NOT_STARTED,
109
- LOGIN_STATUS_TERRA_NOT_STARTED,
110
- LOGIN_STATUS_TOS_NOT_STARTED,
111
- ),
112
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
113
- });
114
-
115
- test("not authenticated, services unsupported", () => {
116
- expect(
117
- getProfileStatus(
118
- false,
119
- LOGIN_STATUS_NIH_UNSUPPORTED,
120
- LOGIN_STATUS_TERRA_UNSUPPORTED,
121
- LOGIN_STATUS_TOS_UNSUPPORTED,
122
- ),
123
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
124
- });
125
-
126
- test("not authenticated, services completed", () => {
127
- expect(
128
- getProfileStatus(
129
- false,
130
- LOGIN_STATUS_NIH_COMPLETED,
131
- LOGIN_STATUS_TERRA_COMPLETED,
132
- LOGIN_STATUS_TOS_COMPLETED,
133
- ),
134
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
135
- });
136
-
137
- test("authenticated, services not started", () => {
138
- expect(
139
- getProfileStatus(
140
- true,
141
- LOGIN_STATUS_NIH_NOT_STARTED,
142
- LOGIN_STATUS_TERRA_NOT_STARTED,
143
- LOGIN_STATUS_TOS_NOT_STARTED,
144
- ),
145
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
146
- });
147
-
148
- test("authenticated, services pending", () => {
149
- expect(
150
- getProfileStatus(
151
- true,
152
- LOGIN_STATUS_NIH_PENDING,
153
- LOGIN_STATUS_TERRA_PENDING,
154
- LOGIN_STATUS_TOS_PENDING,
155
- ),
156
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
157
- });
158
-
159
- test("authenticated, nih pending, other services completed", () => {
160
- expect(
161
- getProfileStatus(
162
- true,
163
- LOGIN_STATUS_NIH_PENDING,
164
- LOGIN_STATUS_TERRA_COMPLETED,
165
- LOGIN_STATUS_TOS_COMPLETED,
166
- ),
167
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
168
- });
169
-
170
- test("authenticated, terra pending, other services completed", () => {
171
- expect(
172
- getProfileStatus(
173
- true,
174
- LOGIN_STATUS_NIH_COMPLETED,
175
- LOGIN_STATUS_TERRA_PENDING,
176
- LOGIN_STATUS_TOS_COMPLETED,
177
- ),
178
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
179
- });
180
-
181
- test("authenticated, tos pending, other services completed", () => {
182
- expect(
183
- getProfileStatus(
184
- true,
185
- LOGIN_STATUS_NIH_COMPLETED,
186
- LOGIN_STATUS_TERRA_COMPLETED,
187
- LOGIN_STATUS_TOS_PENDING,
188
- ),
189
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
190
- });
191
-
192
- test("authenticated, nih completed, terra pending, tos not started", () => {
193
- expect(
194
- getProfileStatus(
195
- true,
196
- LOGIN_STATUS_NIH_COMPLETED,
197
- LOGIN_STATUS_TERRA_PENDING,
198
- LOGIN_STATUS_TOS_NOT_STARTED,
199
- ),
200
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
201
- });
202
-
203
- test("authenticated, nih not started, terra completed, tos pending", () => {
204
- expect(
205
- getProfileStatus(
206
- true,
207
- LOGIN_STATUS_NIH_NOT_STARTED,
208
- LOGIN_STATUS_TERRA_COMPLETED,
209
- LOGIN_STATUS_TOS_PENDING,
210
- ),
211
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
212
- });
213
-
214
- test("authenticated, nih pending, terra not started, tos completed", () => {
215
- expect(
216
- getProfileStatus(
217
- true,
218
- LOGIN_STATUS_NIH_PENDING,
219
- LOGIN_STATUS_TERRA_NOT_STARTED,
220
- LOGIN_STATUS_TOS_COMPLETED,
221
- ),
222
- ).toBe(TERRA_PROFILE_STATUS.PENDING);
223
- });
224
-
225
- test("authenticated, services unsupported", () => {
226
- expect(
227
- getProfileStatus(
228
- true,
229
- LOGIN_STATUS_NIH_UNSUPPORTED,
230
- LOGIN_STATUS_TERRA_UNSUPPORTED,
231
- LOGIN_STATUS_TOS_UNSUPPORTED,
232
- ),
233
- ).toBe(TERRA_PROFILE_STATUS.AUTHENTICATED);
234
- });
235
-
236
- test("authenticated, services completed, tos unsuccessful", () => {
237
- expect(
238
- getProfileStatus(
239
- true,
240
- LOGIN_STATUS_NIH_COMPLETED,
241
- LOGIN_STATUS_TERRA_COMPLETED,
242
- LOGIN_STATUS_TOS_COMPLETED_UNSUCCESSFUL,
243
- ),
244
- ).toBe(TERRA_PROFILE_STATUS.UNAUTHENTICATED);
245
- });
246
-
247
- test("authenticated, nih unsupported, terra completed, tos completed unsuccessfully", () => {
248
- expect(
249
- getProfileStatus(
250
- true,
251
- LOGIN_STATUS_NIH_UNSUPPORTED,
252
- LOGIN_STATUS_TERRA_COMPLETED,
253
- LOGIN_STATUS_TOS_COMPLETED_UNSUCCESSFUL,
254
- ),
255
- ).toBe(TERRA_PROFILE_STATUS.UNAUTHENTICATED);
256
- });
257
-
258
- test("authenticated, nih unsupported, other services completed", () => {
259
- expect(
260
- getProfileStatus(
261
- true,
262
- LOGIN_STATUS_NIH_UNSUPPORTED,
263
- LOGIN_STATUS_TERRA_COMPLETED,
264
- LOGIN_STATUS_TOS_COMPLETED,
265
- ),
266
- ).toBe(TERRA_PROFILE_STATUS.AUTHENTICATED);
267
- });
268
-
269
- test("authenticated, terra completed, other services unsupported", () => {
270
- expect(
271
- getProfileStatus(
272
- true,
273
- LOGIN_STATUS_NIH_UNSUPPORTED,
274
- LOGIN_STATUS_TERRA_COMPLETED,
275
- LOGIN_STATUS_TOS_UNSUPPORTED,
276
- ),
277
- ).toBe(TERRA_PROFILE_STATUS.UNAUTHENTICATED);
278
- });
279
-
280
- test("authenticated, services completed", () => {
281
- expect(
282
- getProfileStatus(
283
- true,
284
- LOGIN_STATUS_NIH_COMPLETED,
285
- LOGIN_STATUS_TERRA_COMPLETED,
286
- LOGIN_STATUS_TOS_COMPLETED,
287
- ),
288
- ).toBe(TERRA_PROFILE_STATUS.AUTHENTICATED);
289
- });
290
- });
@@ -1,89 +0,0 @@
1
- import { matchers } from "@emotion/jest";
2
- import { composeStories } from "@storybook/react";
3
- import "@testing-library/jest-dom";
4
- import { render, screen } from "@testing-library/react";
5
- import React from "react";
6
- import {
7
- ANCHOR_TARGET,
8
- REL_ATTRIBUTE,
9
- } from "../src/components/Links/common/entities";
10
- import * as stories from "../src/components/Table/components/TableCell/components/LinkCell/stories/linkCell.stories";
11
-
12
- expect.extend(matchers);
13
-
14
- const { ClientSide, External, Invalid, WithCustomStyle } =
15
- composeStories(stories);
16
-
17
- const STYLE_RULE_PROPERTIES = {
18
- TEXT_DECORATION: "text-decoration",
19
- };
20
-
21
- const STYLE_RULE_VALUES = {
22
- NONE: "none",
23
- UNDERLINE: "underline",
24
- };
25
-
26
- describe("TableCell, LinkCell", () => {
27
- it("renders client-side link", async () => {
28
- render(<ClientSide />);
29
- const anchorEl = screen.getByText("Explore");
30
- expect(anchorEl).toBeDefined();
31
- expect(anchorEl?.getAttribute("href")).toBe("/");
32
- expect(anchorEl?.getAttribute("rel")).toBe(REL_ATTRIBUTE.NO_OPENER);
33
- expect(anchorEl?.getAttribute("target")).toBe(ANCHOR_TARGET.SELF);
34
- // Expect MuiLink-underlineAlways class and underline style.
35
- expect(anchorEl).toHaveClass("MuiLink-underlineAlways");
36
- expect(anchorEl).toHaveStyleRule(
37
- STYLE_RULE_PROPERTIES.TEXT_DECORATION,
38
- STYLE_RULE_VALUES.UNDERLINE,
39
- );
40
- });
41
-
42
- it("renders external link", async () => {
43
- render(<External />);
44
- const anchorEl = screen.getByText("Explore");
45
- expect(anchorEl).toBeDefined();
46
- expect(anchorEl?.getAttribute("href")).toBe("https://www.example.com");
47
- expect(anchorEl?.getAttribute("rel")).toBe(
48
- REL_ATTRIBUTE.NO_OPENER_NO_REFERRER,
49
- );
50
- expect(anchorEl?.getAttribute("target")).toBe(ANCHOR_TARGET.BLANK);
51
- // Expect MuiLink-underlineAlways class and underline style.
52
- expect(anchorEl).toHaveClass("MuiLink-underlineAlways");
53
- expect(anchorEl).toHaveStyleRule(
54
- STYLE_RULE_PROPERTIES.TEXT_DECORATION,
55
- STYLE_RULE_VALUES.UNDERLINE,
56
- );
57
- });
58
-
59
- it("renders plain text for invalid link", () => {
60
- render(<Invalid />);
61
- const spanEl = screen.getByText("Explore");
62
- expect(spanEl.tagName).toBe("SPAN");
63
- expect(spanEl.getAttribute("href")).toBeNull();
64
- expect(spanEl.getAttribute("rel")).toBeNull();
65
- expect(spanEl.getAttribute("target")).toBeNull();
66
- // Expect no MuiLink-root class and no underline style.
67
- expect(spanEl).not.toHaveClass("MuiLink-root");
68
- expect(spanEl).not.toHaveStyleRule(
69
- STYLE_RULE_PROPERTIES.TEXT_DECORATION,
70
- STYLE_RULE_VALUES.UNDERLINE,
71
- );
72
- });
73
-
74
- it("renders link with custom link props", async () => {
75
- render(<WithCustomStyle />);
76
- const anchorEl = screen.getByText("Explore");
77
- // Expect MuiLink-underlineNone class and no underline style.
78
- expect(anchorEl).toHaveClass("MuiLink-underlineNone");
79
- expect(anchorEl).toHaveStyleRule(
80
- STYLE_RULE_PROPERTIES.TEXT_DECORATION,
81
- STYLE_RULE_VALUES.NONE,
82
- );
83
- expect(anchorEl).toHaveStyleRule(
84
- STYLE_RULE_PROPERTIES.TEXT_DECORATION,
85
- STYLE_RULE_VALUES.NONE,
86
- { target: ":hover" },
87
- );
88
- });
89
- });
@@ -1,52 +0,0 @@
1
- import { matchers } from "@emotion/jest";
2
- import { composeStories } from "@storybook/react";
3
- import { Column } from "@tanstack/react-table";
4
- import "@testing-library/jest-dom";
5
- import { render, screen } from "@testing-library/react";
6
- import React from "react";
7
- import {
8
- ANCHOR_TARGET,
9
- REL_ATTRIBUTE,
10
- } from "../src/components/Links/common/entities";
11
- import { STYLED_ANCHOR } from "../src/components/Table/components/TableCell/components/MarkdownCell/stories/constants";
12
- import * as stories from "../src/components/Table/components/TableCell/components/MarkdownCell/stories/markdownCell.stories";
13
-
14
- expect.extend(matchers);
15
-
16
- const { Default, WithHtml } = composeStories(stories);
17
-
18
- describe("MarkdownCell", () => {
19
- it("renders the markdown content", async () => {
20
- render(<Default />);
21
- expect(await screen.findByText("UBERON:0000955")).toBeInTheDocument();
22
- });
23
-
24
- it("renders HTML and anchor elements", async () => {
25
- render(<WithHtml />);
26
- const anchorEl = await screen.findByText("example link");
27
- expect(anchorEl).toBeInTheDocument();
28
- expect(anchorEl.getAttribute("href")).toBe("https://www.example.com");
29
- expect(anchorEl.getAttribute("target")).toBe(ANCHOR_TARGET.BLANK);
30
- expect(anchorEl.getAttribute("rel")).toBe(
31
- REL_ATTRIBUTE.NO_OPENER_NO_REFERRER,
32
- );
33
- expect(anchorEl).toHaveClass("MuiLink-root");
34
- });
35
-
36
- it("applies the correct className and component", async () => {
37
- render(
38
- <WithHtml
39
- className="css-pygqsj"
40
- column={
41
- {
42
- columnDef: { meta: { components: { a: STYLED_ANCHOR } } },
43
- } as unknown as Column<unknown, string>
44
- }
45
- />,
46
- );
47
- const anchorEl = await screen.findByText("example link");
48
- expect(anchorEl).toHaveStyleRule("background-color", "green");
49
- expect(anchorEl).toHaveStyleRule("color", "white");
50
- expect(anchorEl.closest(".css-pygqsj")).toBeInTheDocument();
51
- });
52
- });
@@ -1,189 +0,0 @@
1
- import { jest } from "@jest/globals";
2
- import { act, render, screen } from "@testing-library/react";
3
- import React from "react";
4
- import { LoginGuardContext } from "../src/providers/loginGuard/context";
5
-
6
- jest.unstable_mockModule("../src/hooks/useConfig", () => ({
7
- useConfig: jest.fn(),
8
- }));
9
-
10
- jest.unstable_mockModule("../src/providers/authentication/auth/hook", () => ({
11
- useAuth: jest.fn(),
12
- }));
13
-
14
- jest.unstable_mockModule(
15
- "../src/hooks/authentication/config/useAuthenticationConfig",
16
- () => ({
17
- useAuthenticationConfig: jest.fn(),
18
- }),
19
- );
20
-
21
- const TEST_ID_LOGIN_DIALOG = "login-dialog";
22
- const TEXT_DIALOG_CLOSED = "closed";
23
- const TEXT_DIALOG_OPEN = "open";
24
- jest.unstable_mockModule(
25
- "../src/components/common/LoginDialog/loginDialog",
26
- () => ({
27
- LoginDialog: ({ open }: { open: boolean }): JSX.Element => (
28
- <div data-testid={TEST_ID_LOGIN_DIALOG}>
29
- {open ? TEXT_DIALOG_OPEN : TEXT_DIALOG_CLOSED}
30
- </div>
31
- ),
32
- }),
33
- );
34
-
35
- const { useConfig } = await import("../src/hooks/useConfig");
36
- const { useAuth } = await import("../src/providers/authentication/auth/hook");
37
- const { useAuthenticationConfig } =
38
- await import("../src/hooks/authentication/config/useAuthenticationConfig");
39
-
40
- const { LoginGuardProvider } =
41
- await import("../src/providers/loginGuard/provider");
42
-
43
- const TEXT_BUTTON_EXPORT = "export";
44
-
45
- describe("LoginGuardProvider", () => {
46
- beforeEach(() => {
47
- // Mock hooks used by login guard.
48
- (useConfig as jest.Mock).mockReturnValue({
49
- config: {
50
- exportsRequireAuth: true,
51
- },
52
- });
53
- (useAuth as jest.Mock).mockReturnValue({
54
- authState: {
55
- isAuthenticated: false,
56
- },
57
- });
58
- (useAuthenticationConfig as jest.Mock).mockReturnValue({});
59
- });
60
-
61
- it("should render children and login dialog closed", () => {
62
- render(
63
- <LoginGuardProvider>
64
- <div data-testid="child">child component</div>
65
- </LoginGuardProvider>,
66
- );
67
-
68
- expect(screen.getByTestId("child")).toBeTruthy();
69
- expect(screen.getByTestId(TEST_ID_LOGIN_DIALOG).textContent).toBe(
70
- TEXT_DIALOG_CLOSED,
71
- );
72
- });
73
-
74
- it("calls callback immediately if user is authenticated", () => {
75
- const callback = jest.fn();
76
-
77
- // Simulate user authentication.
78
- (useAuth as jest.Mock).mockReturnValue({
79
- authState: { isAuthenticated: true },
80
- });
81
-
82
- render(
83
- <LoginGuardProvider>
84
- <LoginGuardContext.Consumer>
85
- {({ requireLogin }) => (
86
- <button onClick={() => requireLogin(callback)}>
87
- {TEXT_BUTTON_EXPORT}
88
- </button>
89
- )}
90
- </LoginGuardContext.Consumer>
91
- </LoginGuardProvider>,
92
- );
93
-
94
- // Click button requiring login.
95
- act(() => {
96
- screen.getByText(TEXT_BUTTON_EXPORT).click();
97
- });
98
-
99
- // User is authenticated; callback should be fired immediately.
100
- expect(callback).toHaveBeenCalled();
101
-
102
- // Login dialog should not be open.
103
- expect(screen.getByTestId(TEST_ID_LOGIN_DIALOG).textContent).toBe(
104
- TEXT_DIALOG_CLOSED,
105
- );
106
- });
107
-
108
- it("calls callback immediately if exportsRequireAuth is false", () => {
109
- const callback = jest.fn();
110
-
111
- // Simulate exportsRequireAuth being false.
112
- (useConfig as jest.Mock).mockReturnValue({
113
- config: {
114
- exportsRequireAuth: false,
115
- },
116
- });
117
-
118
- render(
119
- <LoginGuardProvider>
120
- <LoginGuardContext.Consumer>
121
- {({ requireLogin }) => (
122
- <button onClick={() => requireLogin(callback)}>
123
- {TEXT_BUTTON_EXPORT}
124
- </button>
125
- )}
126
- </LoginGuardContext.Consumer>
127
- </LoginGuardProvider>,
128
- );
129
-
130
- // Click button requiring login.
131
- act(() => {
132
- screen.getByText(TEXT_BUTTON_EXPORT).click();
133
- });
134
-
135
- // exportsRequireAuth is false; callback should be fired immediately.
136
- expect(callback).toHaveBeenCalled();
137
-
138
- // Login dialog should not be open.
139
- expect(screen.getByTestId(TEST_ID_LOGIN_DIALOG).textContent).toBe(
140
- TEXT_DIALOG_CLOSED,
141
- );
142
- });
143
-
144
- it("should call callback after user authenticates", async () => {
145
- const callback = jest.fn();
146
-
147
- const { rerender } = render(
148
- <LoginGuardProvider>
149
- <LoginGuardContext.Consumer>
150
- {({ requireLogin }) => (
151
- <button onClick={() => requireLogin(callback)}>
152
- {TEXT_BUTTON_EXPORT}
153
- </button>
154
- )}
155
- </LoginGuardContext.Consumer>
156
- </LoginGuardProvider>,
157
- );
158
-
159
- // Click button requiring login.
160
- act(() => {
161
- screen.getByText(TEXT_BUTTON_EXPORT).click();
162
- });
163
-
164
- // User is not authenticated; callback should not have been called.
165
- expect(callback).not.toHaveBeenCalled();
166
-
167
- // User is not authenticated; login dialog should be open.
168
- expect(screen.getByTestId(TEST_ID_LOGIN_DIALOG).textContent).toBe(
169
- TEXT_DIALOG_OPEN,
170
- );
171
-
172
- // Simulate user authentication.
173
- await act(async () => {
174
- (useAuth as jest.Mock).mockReturnValue({
175
- authState: { isAuthenticated: true },
176
- });
177
- });
178
-
179
- // Rerender to trigger useEffect.
180
- rerender(
181
- <LoginGuardProvider>
182
- <div />
183
- </LoginGuardProvider>,
184
- );
185
-
186
- // Callback should be called (in useEffect called on re-render).
187
- expect(callback).toHaveBeenCalled();
188
- });
189
- });