@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.
- package/lib/components/Export/components/ExportMethod/constants.d.ts +2 -0
- package/lib/components/Export/components/ExportMethod/constants.js +6 -0
- package/lib/components/Export/components/ExportMethod/exportMethod.d.ts +2 -1
- package/lib/components/Export/components/ExportMethod/exportMethod.js +6 -4
- package/lib/components/Export/components/ExportMethod/exportMethod.styles.d.ts +8 -2
- package/lib/components/Export/components/ExportMethod/exportMethod.styles.js +4 -6
- package/package.json +6 -1
- package/src/components/Export/components/ExportMethod/constants.ts +8 -0
- package/src/components/Export/components/ExportMethod/exportMethod.styles.ts +10 -8
- package/src/components/Export/components/ExportMethod/exportMethod.tsx +13 -4
- package/.eslintignore +0 -5
- package/.eslintrc.json +0 -79
- package/.github/copilot-instructions.md +0 -176
- package/.github/workflows/release-please.yml +0 -49
- package/.github/workflows/run-checks.yml +0 -57
- package/.husky/commit-msg +0 -18
- package/.husky/pre-commit +0 -43
- package/.prettierignore +0 -19
- package/.prettierrc.json +0 -1
- package/.release-please-manifest.json +0 -3
- package/.storybook/main.ts +0 -10
- package/.storybook/preview-head.html +0 -4
- package/.storybook/preview.js +0 -6
- package/CHANGELOG.md +0 -1110
- package/CLAUDE.md +0 -214
- package/backend/README.md +0 -64
- package/backend/__init__.py +0 -0
- package/backend/controllers/__init__.py +0 -0
- package/backend/controllers/facets_controller.py +0 -16
- package/backend/controllers/models.py +0 -11
- package/backend/main.py +0 -8
- package/backend/requirements.txt +0 -4
- package/backend/services/__init__.py +0 -0
- package/backend/services/facets_service.py +0 -68
- package/backend/services/models.py +0 -43
- package/commitlint.config.js +0 -1
- package/docs/TRUSTED_PUBLISHING.md +0 -132
- package/jest.config.js +0 -6
- package/release-please-config.json +0 -23
- package/tests/azulFileDownload.test.tsx +0 -96
- package/tests/buildCategoryViews.test.ts +0 -282
- package/tests/buildRequestFilters.test.ts +0 -60
- package/tests/buildRequestManifest.test.ts +0 -103
- package/tests/chart.test.tsx +0 -274
- package/tests/chartSortUtils.test.ts +0 -119
- package/tests/chartView.test.tsx +0 -48
- package/tests/dataDictionaryColumnFilters.test.tsx +0 -101
- package/tests/dataDictionary_utils.test.ts +0 -153
- package/tests/fetchApi.test.ts +0 -93
- package/tests/filter.test.tsx +0 -100
- package/tests/filterMenu.test.ts +0 -100
- package/tests/filterRange.test.tsx +0 -372
- package/tests/filterSortUtils.test.ts +0 -180
- package/tests/filters.test.tsx +0 -61
- package/tests/getFacetedMinMaxValues.test.ts +0 -166
- package/tests/getFilterSortType.test.ts +0 -45
- package/tests/getProfileStatus.test.ts +0 -290
- package/tests/linkCell.test.tsx +0 -89
- package/tests/markdownCell.test.tsx +0 -52
- package/tests/provider.test.tsx +0 -189
- package/tests/research.chatState.test.ts +0 -463
- package/tests/research.fetchResponse.test.ts +0 -164
- package/tests/research.queryProvider.test.ts +0 -321
- package/tests/research.useKeyShortCuts.test.ts +0 -256
- package/tests/rowSelectionValidation.test.ts +0 -282
- package/tests/setup.ts +0 -19
- package/tests/stepIcon.test.tsx +0 -42
- package/tests/tableFilter.test.tsx +0 -90
- package/tests/terraProfileProvider.test.tsx +0 -117
- package/tests/theme.test.ts +0 -465
- package/tests/toggleButtonGroupProvider.test.tsx +0 -125
- package/tests/transformRoute.test.ts +0 -21
- package/tests/tsconfig.json +0 -8
- package/tests/useFileLocation.test.ts +0 -36
- package/tests/useRequestManifest.test.ts +0 -201
- package/tests/useRouteHistory.test.ts +0 -97
- package/tests/useSessionActive.test.ts +0 -106
- package/tests/useWindowResize.test.ts +0 -130
- package/tests/viewModelBuilders_utils.test.ts +0 -58
- package/tests/viewToggle.test.tsx +0 -54
- package/tsconfig.json +0 -25
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { jest } from "@jest/globals";
|
|
2
|
-
import { renderHook } from "@testing-library/react";
|
|
3
|
-
import { MANIFEST_DOWNLOAD_FORMAT } from "../src/apis/azul/common/entities";
|
|
4
|
-
import { FormFacet } from "../src/components/Export/common/entities";
|
|
5
|
-
import { METHOD } from "../src/hooks/types";
|
|
6
|
-
import {
|
|
7
|
-
CATALOG,
|
|
8
|
-
CONFIG,
|
|
9
|
-
FILE_MANIFEST_STATE,
|
|
10
|
-
FORM_FACET,
|
|
11
|
-
} from "../src/mocks/useRequestFileManifest.mocks";
|
|
12
|
-
|
|
13
|
-
jest.unstable_mockModule("../src/hooks/useConfig", () => ({
|
|
14
|
-
useConfig: jest.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
jest.unstable_mockModule("../src/hooks/useCatalog", () => ({
|
|
18
|
-
useCatalog: jest.fn(),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
jest.unstable_mockModule("../src/hooks/useFileManifestState", () => ({
|
|
22
|
-
useFileManifestState: jest.fn(),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const { useConfig } = await import("../src/hooks/useConfig");
|
|
26
|
-
const { useCatalog } = await import("../src/hooks/useCatalog");
|
|
27
|
-
const { useFileManifestState } =
|
|
28
|
-
await import("../src/hooks/useFileManifestState");
|
|
29
|
-
const { useRequestManifest } =
|
|
30
|
-
await import("../src/hooks/useRequestManifest/useRequestManifest");
|
|
31
|
-
|
|
32
|
-
const MOCK_USE_CATALOG = useCatalog as jest.MockedFunction<typeof useCatalog>;
|
|
33
|
-
const MOCK_USE_CONFIG = useConfig as jest.MockedFunction<
|
|
34
|
-
() => Partial<ReturnType<typeof useConfig>>
|
|
35
|
-
>;
|
|
36
|
-
const MOCK_USE_FILE_MANIFEST_STATE =
|
|
37
|
-
useFileManifestState as jest.MockedFunction<
|
|
38
|
-
() => Partial<ReturnType<typeof useFileManifestState>>
|
|
39
|
-
>;
|
|
40
|
-
|
|
41
|
-
describe("useRequestManifest", () => {
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
MOCK_USE_CATALOG.mockReset();
|
|
44
|
-
MOCK_USE_CONFIG.mockReset();
|
|
45
|
-
MOCK_USE_FILE_MANIFEST_STATE.mockReset();
|
|
46
|
-
MOCK_USE_CATALOG.mockReturnValue(CATALOG);
|
|
47
|
-
MOCK_USE_CONFIG.mockReturnValue(CONFIG);
|
|
48
|
-
MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
|
|
49
|
-
fileManifestDispatch: jest.fn(),
|
|
50
|
-
fileManifestState: FILE_MANIFEST_STATE,
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("useRequestManifest - always returns request method", () => {
|
|
55
|
-
test("requestMethod is always METHOD.PUT regardless of conditions", () => {
|
|
56
|
-
MOCK_USE_CATALOG.mockReturnValue(undefined);
|
|
57
|
-
const { result } = renderHook(() =>
|
|
58
|
-
useRequestManifest(undefined, FORM_FACET.INITIAL_SET),
|
|
59
|
-
);
|
|
60
|
-
expect(result.current.requestMethod).toEqual(METHOD.PUT);
|
|
61
|
-
expect(result.current.requestParams).toBeUndefined();
|
|
62
|
-
expect(result.current.requestUrl).toBeUndefined();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("useRequestManifest - returns undefined for params and URL when", () => {
|
|
67
|
-
test("catalog is not defined", () => {
|
|
68
|
-
MOCK_USE_CATALOG.mockReturnValue(undefined);
|
|
69
|
-
testRequestManifest({
|
|
70
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("fileManifestFormat is not ready", () => {
|
|
75
|
-
test("when fileManifestFormat is not defined", () => {
|
|
76
|
-
testRequestManifest({
|
|
77
|
-
fileManifestFormat: undefined,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("when fileManifestFormat is invalid", () => {
|
|
82
|
-
testRequestManifest({
|
|
83
|
-
fileManifestFormat: "INVALID_FORMAT" as MANIFEST_DOWNLOAD_FORMAT,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("fileManifestState is not ready", () => {
|
|
89
|
-
test("when fileManifestState is not enabled", () => {
|
|
90
|
-
MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
|
|
91
|
-
fileManifestDispatch: jest.fn(),
|
|
92
|
-
fileManifestState: { ...FILE_MANIFEST_STATE, isEnabled: false },
|
|
93
|
-
});
|
|
94
|
-
testRequestManifest({
|
|
95
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test("when fileManifestState is loading", () => {
|
|
100
|
-
MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
|
|
101
|
-
fileManifestDispatch: jest.fn(),
|
|
102
|
-
fileManifestState: { ...FILE_MANIFEST_STATE, isLoading: true },
|
|
103
|
-
});
|
|
104
|
-
testRequestManifest({
|
|
105
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test("when fileManifestState fileCount is undefined", () => {
|
|
111
|
-
MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
|
|
112
|
-
fileManifestDispatch: jest.fn(),
|
|
113
|
-
fileManifestState: { ...FILE_MANIFEST_STATE, fileCount: undefined },
|
|
114
|
-
});
|
|
115
|
-
testRequestManifest({
|
|
116
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe("form selection is not ready", () => {
|
|
121
|
-
test("when a form facet is undefined", () => {
|
|
122
|
-
testRequestManifest({
|
|
123
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
124
|
-
formFacet: {},
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("when a form facet `fileSummaryFacet` and `speciesFacet` are not defined", () => {
|
|
129
|
-
testRequestManifest({
|
|
130
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
131
|
-
formFacet: FORM_FACET.INITIAL_SET,
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test("when a form facet is not selected", () => {
|
|
136
|
-
testRequestManifest({
|
|
137
|
-
fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
138
|
-
formFacet: FORM_FACET.INCOMPLETE_SET,
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("useRequestManifest - returns the request manifest object when all conditions are met", () => {
|
|
145
|
-
test("and at least one form facet has an unselected term", () => {
|
|
146
|
-
const { result } = renderHook(() =>
|
|
147
|
-
useRequestManifest(
|
|
148
|
-
MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
149
|
-
FORM_FACET.SUBSET,
|
|
150
|
-
),
|
|
151
|
-
);
|
|
152
|
-
expect(result.current.requestMethod).toEqual(METHOD.PUT);
|
|
153
|
-
expect(result.current.requestParams).toBeDefined();
|
|
154
|
-
expect(result.current.requestUrl).toBeDefined();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test("and all form facets have all their terms selected", () => {
|
|
158
|
-
const { result } = renderHook(() =>
|
|
159
|
-
useRequestManifest(
|
|
160
|
-
MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
|
|
161
|
-
FORM_FACET.COMPLETE_SET,
|
|
162
|
-
),
|
|
163
|
-
);
|
|
164
|
-
expect(result.current.requestMethod).toEqual(METHOD.PUT);
|
|
165
|
-
expect(result.current.requestParams).toBeDefined();
|
|
166
|
-
expect(result.current.requestUrl).toBeDefined();
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Utility function to test the behavior of the `useRequestManifest` hook.
|
|
173
|
-
* This function renders the `useRequestManifest` hook with the provided arguments
|
|
174
|
-
* and asserts the expected values for `requestMethod`, `requestParams`, and `requestUrl`.
|
|
175
|
-
* @param testObject - Object containing the expected values for `requestMethod`, `requestParams`, and `requestUrl`.
|
|
176
|
-
* @param testObject.expectedMethod - The expected request method.
|
|
177
|
-
* @param testObject.expectedParams - The expected request parameters.
|
|
178
|
-
* @param testObject.expectedUrl - The expected request URL.
|
|
179
|
-
* @param testObject.fileManifestFormat - The file manifest format.
|
|
180
|
-
* @param testObject.formFacet - Form facet.
|
|
181
|
-
*/
|
|
182
|
-
function testRequestManifest({
|
|
183
|
-
expectedMethod = METHOD.PUT,
|
|
184
|
-
expectedParams = undefined,
|
|
185
|
-
expectedUrl = undefined,
|
|
186
|
-
fileManifestFormat,
|
|
187
|
-
formFacet = FORM_FACET.COMPLETE_SET,
|
|
188
|
-
}: {
|
|
189
|
-
expectedMethod?: METHOD;
|
|
190
|
-
expectedParams?: URLSearchParams;
|
|
191
|
-
expectedUrl?: string;
|
|
192
|
-
fileManifestFormat?: MANIFEST_DOWNLOAD_FORMAT;
|
|
193
|
-
formFacet?: FormFacet;
|
|
194
|
-
}): void {
|
|
195
|
-
const { result } = renderHook(() =>
|
|
196
|
-
useRequestManifest(fileManifestFormat, formFacet),
|
|
197
|
-
);
|
|
198
|
-
expect(result.current.requestMethod).toEqual(expectedMethod);
|
|
199
|
-
expect(result.current.requestParams).toEqual(expectedParams);
|
|
200
|
-
expect(result.current.requestUrl).toEqual(expectedUrl);
|
|
201
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { jest } from "@jest/globals";
|
|
2
|
-
import { act, renderHook } from "@testing-library/react";
|
|
3
|
-
import Router, { NextRouter } from "next/router";
|
|
4
|
-
|
|
5
|
-
const ROOT_PATH = "/";
|
|
6
|
-
const ROUTES = ["/route1", "/route2", "/route3", "/route4"];
|
|
7
|
-
|
|
8
|
-
jest.unstable_mockModule("next/router", () => {
|
|
9
|
-
return {
|
|
10
|
-
...jest.requireActual<typeof import("next/router")>("next/router"),
|
|
11
|
-
useRouter: jest.fn(),
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
jest.unstable_mockModule("../src/hooks/useRouteRoot", () => ({
|
|
15
|
-
useRouteRoot: jest.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const { useRouter } = await import("next/router");
|
|
19
|
-
const { useRouteRoot } = await import("../src/hooks/useRouteRoot");
|
|
20
|
-
const { useRouteHistory } = await import("../src/hooks/useRouteHistory");
|
|
21
|
-
|
|
22
|
-
const MOCK_USE_ROUTER = useRouter as jest.MockedFunction<
|
|
23
|
-
() => Partial<NextRouter>
|
|
24
|
-
>;
|
|
25
|
-
const MOCK_USE_ROUTE_ROOT = useRouteRoot as jest.MockedFunction<
|
|
26
|
-
typeof useRouteRoot
|
|
27
|
-
>;
|
|
28
|
-
|
|
29
|
-
describe("useRouteHistory", () => {
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
MOCK_USE_ROUTE_ROOT.mockReset();
|
|
32
|
-
MOCK_USE_ROUTER.mockReset();
|
|
33
|
-
MOCK_USE_ROUTER.mockReturnValue({
|
|
34
|
-
asPath: ROUTES[0],
|
|
35
|
-
});
|
|
36
|
-
MOCK_USE_ROUTE_ROOT.mockReturnValue(ROOT_PATH);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("returns the root path when no previous route exists", () => {
|
|
40
|
-
const { result } = renderHook(() => useRouteHistory());
|
|
41
|
-
expect(result.current.callbackUrl()).toBe(ROOT_PATH);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("updates history on route change", () => {
|
|
45
|
-
const { result } = renderHook(() => useRouteHistory());
|
|
46
|
-
act(() => {
|
|
47
|
-
Router.events.emit("routeChangeComplete", ROUTES[1]);
|
|
48
|
-
Router.events.emit("routeChangeComplete", ROUTES[2]);
|
|
49
|
-
});
|
|
50
|
-
expect(result.current.callbackUrl()).toBe(ROUTES[1]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("does not add duplicate routes to history", () => {
|
|
54
|
-
const { result } = renderHook(() => useRouteHistory());
|
|
55
|
-
act(() => {
|
|
56
|
-
Router.events.emit("routeChangeComplete", ROUTES[2]);
|
|
57
|
-
Router.events.emit("routeChangeComplete", ROUTES[2]);
|
|
58
|
-
});
|
|
59
|
-
expect(result.current.callbackUrl()).toBe(ROUTES[0]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("limits history length to maxHistory", () => {
|
|
63
|
-
const { result } = renderHook(() => useRouteHistory(2));
|
|
64
|
-
act(() => {
|
|
65
|
-
Router.events.emit("routeChangeComplete", ROUTES[1]);
|
|
66
|
-
Router.events.emit("routeChangeComplete", ROUTES[2]);
|
|
67
|
-
Router.events.emit("routeChangeComplete", ROUTES[3]);
|
|
68
|
-
});
|
|
69
|
-
// Use `callbackUrl` with a transform function to capture the full history.
|
|
70
|
-
let history;
|
|
71
|
-
result.current.callbackUrl((routes) => {
|
|
72
|
-
history = routes;
|
|
73
|
-
return ROOT_PATH;
|
|
74
|
-
});
|
|
75
|
-
// After emitting the routes, the history stack is [ROUTES[3], ROUTES[2].
|
|
76
|
-
expect(history).toHaveLength(2);
|
|
77
|
-
expect(history).toEqual([ROUTES[3], ROUTES[2]]);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("uses transform function if provided", () => {
|
|
81
|
-
const { result } = renderHook(() => useRouteHistory(4));
|
|
82
|
-
act(() => {
|
|
83
|
-
Router.events.emit("routeChangeComplete", ROUTES[1]);
|
|
84
|
-
Router.events.emit("routeChangeComplete", ROUTES[2]);
|
|
85
|
-
Router.events.emit("routeChangeComplete", ROUTES[3]);
|
|
86
|
-
});
|
|
87
|
-
// After emitting the routes, the history stack is [ROUTES[3], ROUTES[2], ROUTES[1], ROUTES[0]].
|
|
88
|
-
const transformFn = (routes: string[]): string => routes[2];
|
|
89
|
-
expect(result.current.callbackUrl(transformFn)).toBe(ROUTES[1]);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("returns root path when transform function is provided but history stack lacks sufficient entries", () => {
|
|
93
|
-
const { result } = renderHook(() => useRouteHistory());
|
|
94
|
-
const transformFn = (routes: string[]): string => routes[2];
|
|
95
|
-
expect(result.current.callbackUrl(transformFn)).toBe(ROOT_PATH);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { jest } from "@jest/globals";
|
|
2
|
-
import { renderHook } from "@testing-library/react";
|
|
3
|
-
import { TransformRouteFn } from "../src/hooks/useRouteHistory";
|
|
4
|
-
import {
|
|
5
|
-
AUTH_STATUS,
|
|
6
|
-
AuthState,
|
|
7
|
-
} from "../src/providers/authentication/auth/types";
|
|
8
|
-
import {
|
|
9
|
-
AUTHENTICATION_STATUS,
|
|
10
|
-
AuthenticationState,
|
|
11
|
-
} from "../src/providers/authentication/authentication/types";
|
|
12
|
-
|
|
13
|
-
const AUTH_STATE_AUTHENTICATED_SETTLED: AuthState = {
|
|
14
|
-
isAuthenticated: true,
|
|
15
|
-
status: AUTH_STATUS.SETTLED,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const AUTH_STATE_PENDING: AuthState = {
|
|
19
|
-
isAuthenticated: false,
|
|
20
|
-
status: AUTH_STATUS.PENDING,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const AUTH_STATE_UNAUTHENTICATED_SETTLED: AuthState = {
|
|
24
|
-
isAuthenticated: false,
|
|
25
|
-
status: AUTH_STATUS.SETTLED,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const AUTHENTICATION_STATE_PENDING: AuthenticationState = {
|
|
29
|
-
profile: undefined,
|
|
30
|
-
status: AUTHENTICATION_STATUS.PENDING,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const AUTHENTICATION_STATE_SETTLED: AuthenticationState = {
|
|
34
|
-
profile: { email: "", name: "" },
|
|
35
|
-
status: AUTHENTICATION_STATUS.SETTLED,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const ROOT_PATH = "/";
|
|
39
|
-
const ROUTES = ["/login", "/route1", "/route2"];
|
|
40
|
-
|
|
41
|
-
jest.unstable_mockModule("next/router", () => {
|
|
42
|
-
return {
|
|
43
|
-
...jest.requireActual<typeof import("next/router")>("next/router"),
|
|
44
|
-
default: {
|
|
45
|
-
push: jest.fn(),
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
jest.unstable_mockModule("../src/hooks/useRouteHistory", () => ({
|
|
50
|
-
useRouteHistory: jest.fn(),
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
const Router = (await import("next/router")).default;
|
|
54
|
-
const { useRouteHistory } = await import("../src/hooks/useRouteHistory");
|
|
55
|
-
const { useSessionActive } =
|
|
56
|
-
await import("../src/hooks/authentication/session/useSessionActive");
|
|
57
|
-
|
|
58
|
-
const MOCK_USE_ROUTE_HISTORY = useRouteHistory as jest.MockedFunction<
|
|
59
|
-
typeof useRouteHistory
|
|
60
|
-
>;
|
|
61
|
-
|
|
62
|
-
describe("useSessionActive", () => {
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
MOCK_USE_ROUTE_HISTORY.mockReset();
|
|
65
|
-
MOCK_USE_ROUTE_HISTORY.mockReturnValue({
|
|
66
|
-
callbackUrl: jest.fn(
|
|
67
|
-
(transformFn?: TransformRouteFn | undefined) =>
|
|
68
|
-
transformFn?.(ROUTES) ?? ROOT_PATH,
|
|
69
|
-
),
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("does not redirect if auth status and authentication status is PENDING", () => {
|
|
74
|
-
renderHook(() =>
|
|
75
|
-
useSessionActive(AUTH_STATE_PENDING, AUTHENTICATION_STATE_PENDING),
|
|
76
|
-
);
|
|
77
|
-
expect(Router.push).not.toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("does not redirect if auth status is PENDING and authentication status is SETTLED", () => {
|
|
81
|
-
renderHook(() =>
|
|
82
|
-
useSessionActive(AUTH_STATE_PENDING, AUTHENTICATION_STATE_SETTLED),
|
|
83
|
-
);
|
|
84
|
-
expect(Router.push).not.toHaveBeenCalled();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("redirects if auth status and authentication status is SETTLED", () => {
|
|
88
|
-
renderHook(() =>
|
|
89
|
-
useSessionActive(
|
|
90
|
-
AUTH_STATE_UNAUTHENTICATED_SETTLED,
|
|
91
|
-
AUTHENTICATION_STATE_SETTLED,
|
|
92
|
-
),
|
|
93
|
-
);
|
|
94
|
-
expect(Router.push).toHaveBeenCalled();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("redirects to callback URL if auth status is SETTLED and authentication status is SETTLED", () => {
|
|
98
|
-
renderHook(() =>
|
|
99
|
-
useSessionActive(
|
|
100
|
-
AUTH_STATE_AUTHENTICATED_SETTLED,
|
|
101
|
-
AUTHENTICATION_STATE_SETTLED,
|
|
102
|
-
),
|
|
103
|
-
);
|
|
104
|
-
expect(Router.push).toHaveBeenCalledWith(ROUTES[1]);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { jest } from "@jest/globals";
|
|
2
|
-
import { act, renderHook } from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
const { useWindowResize } = await import("../src/hooks/useWindowResize");
|
|
5
|
-
|
|
6
|
-
describe("useWindowResize", () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
jest.useFakeTimers();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
jest.clearAllTimers();
|
|
13
|
-
jest.useRealTimers();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("returns current window dimensions", () => {
|
|
17
|
-
// Set window dimensions
|
|
18
|
-
Object.defineProperty(window, "innerWidth", {
|
|
19
|
-
configurable: true,
|
|
20
|
-
value: 1024,
|
|
21
|
-
writable: true,
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(window, "innerHeight", {
|
|
24
|
-
configurable: true,
|
|
25
|
-
value: 768,
|
|
26
|
-
writable: true,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const { result } = renderHook(() => useWindowResize());
|
|
30
|
-
|
|
31
|
-
expect(result.current).toEqual({ height: 768, width: 1024 });
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("updates dimensions on window resize", () => {
|
|
35
|
-
// Set initial dimensions
|
|
36
|
-
Object.defineProperty(window, "innerWidth", {
|
|
37
|
-
configurable: true,
|
|
38
|
-
value: 1024,
|
|
39
|
-
writable: true,
|
|
40
|
-
});
|
|
41
|
-
Object.defineProperty(window, "innerHeight", {
|
|
42
|
-
configurable: true,
|
|
43
|
-
value: 768,
|
|
44
|
-
writable: true,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const { result } = renderHook(() => useWindowResize(100));
|
|
48
|
-
|
|
49
|
-
expect(result.current).toEqual({ height: 768, width: 1024 });
|
|
50
|
-
|
|
51
|
-
// Simulate window resize
|
|
52
|
-
act(() => {
|
|
53
|
-
Object.defineProperty(window, "innerWidth", {
|
|
54
|
-
configurable: true,
|
|
55
|
-
value: 1920,
|
|
56
|
-
writable: true,
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(window, "innerHeight", {
|
|
59
|
-
configurable: true,
|
|
60
|
-
value: 1080,
|
|
61
|
-
writable: true,
|
|
62
|
-
});
|
|
63
|
-
window.dispatchEvent(new Event("resize"));
|
|
64
|
-
|
|
65
|
-
// Fast-forward timeout
|
|
66
|
-
jest.advanceTimersByTime(100);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(result.current).toEqual({ height: 1080, width: 1920 });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("debounces resize events with the specified timeout", () => {
|
|
73
|
-
Object.defineProperty(window, "innerWidth", {
|
|
74
|
-
configurable: true,
|
|
75
|
-
value: 1024,
|
|
76
|
-
writable: true,
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(window, "innerHeight", {
|
|
79
|
-
configurable: true,
|
|
80
|
-
value: 768,
|
|
81
|
-
writable: true,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const { result } = renderHook(() => useWindowResize(200));
|
|
85
|
-
|
|
86
|
-
// Simulate multiple rapid resize events
|
|
87
|
-
act(() => {
|
|
88
|
-
Object.defineProperty(window, "innerWidth", {
|
|
89
|
-
configurable: true,
|
|
90
|
-
value: 1920,
|
|
91
|
-
writable: true,
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(window, "innerHeight", {
|
|
94
|
-
configurable: true,
|
|
95
|
-
value: 1080,
|
|
96
|
-
writable: true,
|
|
97
|
-
});
|
|
98
|
-
window.dispatchEvent(new Event("resize"));
|
|
99
|
-
|
|
100
|
-
// Fast-forward only 100ms - should not update yet
|
|
101
|
-
jest.advanceTimersByTime(100);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// Should still have initial dimensions
|
|
105
|
-
expect(result.current).toEqual({ height: 768, width: 1024 });
|
|
106
|
-
|
|
107
|
-
act(() => {
|
|
108
|
-
// Fast-forward remaining 100ms
|
|
109
|
-
jest.advanceTimersByTime(100);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Now should have updated dimensions
|
|
113
|
-
expect(result.current).toEqual({ height: 1080, width: 1920 });
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("cleans up event listener on unmount", () => {
|
|
117
|
-
const removeEventListenerSpy = jest.spyOn(window, "removeEventListener");
|
|
118
|
-
|
|
119
|
-
const { unmount } = renderHook(() => useWindowResize());
|
|
120
|
-
|
|
121
|
-
unmount();
|
|
122
|
-
|
|
123
|
-
expect(removeEventListenerSpy).toHaveBeenCalledWith(
|
|
124
|
-
"resize",
|
|
125
|
-
expect.any(Function),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
removeEventListenerSpy.mockRestore();
|
|
129
|
-
});
|
|
130
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
sanitizeString,
|
|
3
|
-
sanitizeStringArray,
|
|
4
|
-
} from "../src/viewModelBuilders/common/utils";
|
|
5
|
-
|
|
6
|
-
// sanitizeString tests:
|
|
7
|
-
|
|
8
|
-
test('sanitize "" to "Unspecified"', () => {
|
|
9
|
-
expect(sanitizeString("")).toBe("Unspecified");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('sanitize null to "Unspecified"', () => {
|
|
13
|
-
expect(sanitizeString(null as any)).toBe("Unspecified");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('sanitize undefined to "Unspecified"', () => {
|
|
17
|
-
expect(sanitizeString(undefined as any)).toBe("Unspecified");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('sanitize "example" with no change', () => {
|
|
21
|
-
expect(sanitizeString("example")).toBe("example");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// sanitizeStringArray tests:
|
|
25
|
-
|
|
26
|
-
test('sanitize null string array to ["Unspecified"]', () => {
|
|
27
|
-
expect(sanitizeStringArray(null as any)).toStrictEqual(["Unspecified"]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('sanitize empty string array to ["Unspecified"]', () => {
|
|
31
|
-
expect(sanitizeStringArray([])).toStrictEqual(["Unspecified"]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("sanitize string array containing null, undefined, and empty string values", () => {
|
|
35
|
-
expect(
|
|
36
|
-
sanitizeStringArray([
|
|
37
|
-
"a",
|
|
38
|
-
"",
|
|
39
|
-
null,
|
|
40
|
-
"b",
|
|
41
|
-
"c",
|
|
42
|
-
undefined,
|
|
43
|
-
null,
|
|
44
|
-
"d",
|
|
45
|
-
"e",
|
|
46
|
-
] as any),
|
|
47
|
-
).toStrictEqual([
|
|
48
|
-
"a",
|
|
49
|
-
"Unspecified",
|
|
50
|
-
"Unspecified",
|
|
51
|
-
"b",
|
|
52
|
-
"c",
|
|
53
|
-
"Unspecified",
|
|
54
|
-
"Unspecified",
|
|
55
|
-
"d",
|
|
56
|
-
"e",
|
|
57
|
-
]);
|
|
58
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { jest } from "@jest/globals";
|
|
2
|
-
import { render, screen } from "@testing-library/react";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { VIEW_MODE } from "../src/components/Index/components/EntityView/components/controls/ViewToggle/hooks/UseViewToggle/types";
|
|
5
|
-
import { TEST_IDS } from "../src/tests/testIds";
|
|
6
|
-
|
|
7
|
-
jest.unstable_mockModule(
|
|
8
|
-
"../src/components/Index/components/EntityView/context/hook",
|
|
9
|
-
() => ({
|
|
10
|
-
useEntityView: jest.fn(),
|
|
11
|
-
}),
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const { useEntityView } =
|
|
15
|
-
await import("../src/components/Index/components/EntityView/context/hook");
|
|
16
|
-
const { composeStories } = await import("@storybook/react");
|
|
17
|
-
const stories =
|
|
18
|
-
await import("../src/components/Index/components/EntityView/components/controls/ViewToggle/stories/viewToggle.stories");
|
|
19
|
-
|
|
20
|
-
const { Default } = composeStories(stories);
|
|
21
|
-
|
|
22
|
-
describe("ViewToggle", () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
jest.clearAllMocks();
|
|
25
|
-
(useEntityView as jest.Mock).mockReturnValue({
|
|
26
|
-
onChange: jest.fn(),
|
|
27
|
-
viewMode: VIEW_MODE.TABLE,
|
|
28
|
-
viewStatus: { disabled: false },
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
it("renders correctly", () => {
|
|
32
|
-
render(<Default testId={TEST_IDS.VIEW_TOGGLE} />);
|
|
33
|
-
const viewEl = screen.getByTestId(TEST_IDS.VIEW_TOGGLE);
|
|
34
|
-
expect(viewEl).not.toBeNull();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("does not render toggle buttons when disabled", () => {
|
|
38
|
-
(useEntityView as jest.Mock).mockReturnValue({
|
|
39
|
-
onChange: jest.fn(),
|
|
40
|
-
viewMode: VIEW_MODE.TABLE,
|
|
41
|
-
viewStatus: { disabled: true },
|
|
42
|
-
});
|
|
43
|
-
render(<Default testId={TEST_IDS.VIEW_TOGGLE} />);
|
|
44
|
-
const viewEl = screen.queryByTestId(TEST_IDS.VIEW_TOGGLE);
|
|
45
|
-
expect(viewEl).toBeNull();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("renders toggle buttons when enabled", () => {
|
|
49
|
-
render(<Default testId={TEST_IDS.VIEW_TOGGLE} />);
|
|
50
|
-
const viewEl = screen.getByTestId(TEST_IDS.VIEW_TOGGLE);
|
|
51
|
-
const buttonsEl = viewEl.getElementsByClassName("MuiToggleButton-root");
|
|
52
|
-
expect(buttonsEl.length).toEqual(2);
|
|
53
|
-
});
|
|
54
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"module": "ESNext",
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"jsx": "react-jsx",
|
|
15
|
-
"baseUrl": "./src",
|
|
16
|
-
"rootDir": "./src",
|
|
17
|
-
"outDir": "lib",
|
|
18
|
-
"declaration": true,
|
|
19
|
-
"noImplicitAny": true,
|
|
20
|
-
"noImplicitThis": true,
|
|
21
|
-
"strictNullChecks": true
|
|
22
|
-
},
|
|
23
|
-
"include": ["src/**/*.ts", "src/**/*.tsx", "types/*.d.ts"],
|
|
24
|
-
"exclude": ["node_modules"]
|
|
25
|
-
}
|