@thepalaceproject/circulation-admin 1.23.0 → 1.24.0-post.5
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/dist/circulation-admin.css +1 -1
- package/dist/circulation-admin.js +1 -1
- package/jest.config.js +5 -0
- package/package.json +2 -2
- package/tests/__mocks__/fileMock.js +1 -0
- package/tests/__mocks__/styleMock.js +1 -0
- package/tests/jest/businessRules/roleBasedAccess.test.ts +93 -0
- package/tests/jest/components/QuicksightDashboard.test.tsx +20 -9
- package/tests/jest/components/Stats.test.tsx +47 -0
- package/tests/jest/testUtils/withProviders.tsx +19 -3
package/jest.config.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
2
|
module.exports = {
|
|
3
|
+
moduleNameMapper: {
|
|
4
|
+
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
|
|
5
|
+
"<rootDir>/tests/__mocks__/fileMock.js",
|
|
6
|
+
"\\.(css|less)$": "<rootDir>/tests/__mocks__/styleMock.js",
|
|
7
|
+
},
|
|
3
8
|
preset: "ts-jest",
|
|
4
9
|
testEnvironment: "jsdom",
|
|
5
10
|
testEnvironmentOptions: {
|
package/package.json
CHANGED
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
"typedoc": "0.23.21",
|
|
136
136
|
"typescript": "4.9.4",
|
|
137
137
|
"url-loader": "^4.1.1",
|
|
138
|
-
"webpack": "^5.
|
|
138
|
+
"webpack": "^5.94.0",
|
|
139
139
|
"webpack-cli": "^5.0.1",
|
|
140
140
|
"webpack-dev-server": "^4.11.1",
|
|
141
141
|
"webpack-merge": "^5.8.0"
|
|
@@ -150,5 +150,5 @@
|
|
|
150
150
|
"*.{js,jsx,ts,tsx,css,md}": "prettier --write",
|
|
151
151
|
"*.{js,css,md}": "prettier --write"
|
|
152
152
|
},
|
|
153
|
-
"version": "1.
|
|
153
|
+
"version": "1.24.0-post.5"
|
|
154
154
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = "test-file-stub";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {};
|
|
@@ -4,6 +4,7 @@ import { ContextProviderProps } from "../../../src/components/ContextProvider";
|
|
|
4
4
|
import { ConfigurationSettings, FeatureFlags } from "../../../src/interfaces";
|
|
5
5
|
import {
|
|
6
6
|
useMayRequestInventoryReports,
|
|
7
|
+
useMaySeeQuickSightLink,
|
|
7
8
|
useMayViewCollectionBarChart,
|
|
8
9
|
} from "../../../src/businessRules/roleBasedAccess";
|
|
9
10
|
|
|
@@ -116,6 +117,98 @@ describe("Business rules for role-based access", () => {
|
|
|
116
117
|
});
|
|
117
118
|
});
|
|
118
119
|
|
|
120
|
+
describe("controls access to the quicksight link", () => {
|
|
121
|
+
const testAccess = (
|
|
122
|
+
expectedResult: boolean,
|
|
123
|
+
config: Partial<ConfigurationSettings>
|
|
124
|
+
) => {
|
|
125
|
+
const wrapper = setupWrapper(config);
|
|
126
|
+
const { result } = renderHook(
|
|
127
|
+
() => useMaySeeQuickSightLink({ library: libraryMatch }),
|
|
128
|
+
{ wrapper }
|
|
129
|
+
);
|
|
130
|
+
expect(result.current).toBe(expectedResult);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
it("restricts access to only sysadmins, if the restriction feature flag is true", () => {
|
|
134
|
+
const featureFlags: FeatureFlags = { quicksightOnlyForSysadmins: true };
|
|
135
|
+
|
|
136
|
+
testAccess(true, { roles: [{ role: "system" }], featureFlags });
|
|
137
|
+
|
|
138
|
+
testAccess(false, { roles: [{ role: "manager-all" }], featureFlags });
|
|
139
|
+
testAccess(false, { roles: [{ role: "librarian-all" }], featureFlags });
|
|
140
|
+
|
|
141
|
+
testAccess(false, {
|
|
142
|
+
roles: [{ role: "manager", library: libraryMatch }],
|
|
143
|
+
featureFlags,
|
|
144
|
+
});
|
|
145
|
+
testAccess(false, {
|
|
146
|
+
roles: [{ role: "manager", library: libraryMismatch }],
|
|
147
|
+
featureFlags,
|
|
148
|
+
});
|
|
149
|
+
testAccess(false, {
|
|
150
|
+
roles: [{ role: "librarian", library: libraryMatch }],
|
|
151
|
+
featureFlags,
|
|
152
|
+
});
|
|
153
|
+
testAccess(false, {
|
|
154
|
+
roles: [{ role: "librarian", library: libraryMismatch }],
|
|
155
|
+
featureFlags,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("allows all users, if the restriction feature flag is is false", () => {
|
|
160
|
+
const featureFlags: FeatureFlags = { quicksightOnlyForSysadmins: false };
|
|
161
|
+
|
|
162
|
+
testAccess(true, { roles: [{ role: "system" }], featureFlags });
|
|
163
|
+
|
|
164
|
+
testAccess(true, { roles: [{ role: "manager-all" }], featureFlags });
|
|
165
|
+
testAccess(true, { roles: [{ role: "librarian-all" }], featureFlags });
|
|
166
|
+
|
|
167
|
+
testAccess(true, {
|
|
168
|
+
roles: [{ role: "manager", library: libraryMatch }],
|
|
169
|
+
featureFlags,
|
|
170
|
+
});
|
|
171
|
+
testAccess(true, {
|
|
172
|
+
roles: [{ role: "manager", library: libraryMismatch }],
|
|
173
|
+
featureFlags,
|
|
174
|
+
});
|
|
175
|
+
testAccess(true, {
|
|
176
|
+
roles: [{ role: "librarian", library: libraryMatch }],
|
|
177
|
+
featureFlags,
|
|
178
|
+
});
|
|
179
|
+
testAccess(true, {
|
|
180
|
+
roles: [{ role: "librarian", library: libraryMismatch }],
|
|
181
|
+
featureFlags,
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("allows all users, if the restriction feature flag is not set", () => {
|
|
186
|
+
const featureFlags: FeatureFlags = {};
|
|
187
|
+
|
|
188
|
+
testAccess(true, { roles: [{ role: "system" }], featureFlags });
|
|
189
|
+
|
|
190
|
+
testAccess(true, { roles: [{ role: "manager-all" }], featureFlags });
|
|
191
|
+
testAccess(true, { roles: [{ role: "librarian-all" }], featureFlags });
|
|
192
|
+
|
|
193
|
+
testAccess(true, {
|
|
194
|
+
roles: [{ role: "manager", library: libraryMatch }],
|
|
195
|
+
featureFlags,
|
|
196
|
+
});
|
|
197
|
+
testAccess(true, {
|
|
198
|
+
roles: [{ role: "manager", library: libraryMismatch }],
|
|
199
|
+
featureFlags,
|
|
200
|
+
});
|
|
201
|
+
testAccess(true, {
|
|
202
|
+
roles: [{ role: "librarian", library: libraryMatch }],
|
|
203
|
+
featureFlags,
|
|
204
|
+
});
|
|
205
|
+
testAccess(true, {
|
|
206
|
+
roles: [{ role: "librarian", library: libraryMismatch }],
|
|
207
|
+
featureFlags,
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
119
212
|
describe("controls access to the collection statistics barchart", () => {
|
|
120
213
|
const testAccess = (
|
|
121
214
|
expectedResult: boolean,
|
|
@@ -7,6 +7,8 @@ import buildStore from "../../../src/store";
|
|
|
7
7
|
import { setupServer } from "msw/node";
|
|
8
8
|
import { http, HttpResponse } from "msw";
|
|
9
9
|
import renderWithContext from "../testUtils/renderWithContext";
|
|
10
|
+
import { renderWithProviders } from "../testUtils/withProviders";
|
|
11
|
+
import QuicksightDashboardPage from "../../../src/components/QuicksightDashboardPage";
|
|
10
12
|
|
|
11
13
|
const libraries: LibrariesData = { libraries: [{ uuid: "my-uuid" }] };
|
|
12
14
|
const dashboardId = "test";
|
|
@@ -35,15 +37,8 @@ describe("QuicksightDashboard", () => {
|
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
it("embed url is retrieved and set in iframe", async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
featureFlags: {},
|
|
41
|
-
roles: [{ role: "system" }],
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
renderWithContext(
|
|
45
|
-
<QuicksightDashboard dashboardId={dashboardId} store={buildStore()} />,
|
|
46
|
-
contextProviderProps
|
|
40
|
+
renderWithProviders(
|
|
41
|
+
<QuicksightDashboard dashboardId={dashboardId} store={buildStore()} />
|
|
47
42
|
);
|
|
48
43
|
|
|
49
44
|
await waitFor(() => {
|
|
@@ -53,4 +48,20 @@ describe("QuicksightDashboard", () => {
|
|
|
53
48
|
);
|
|
54
49
|
});
|
|
55
50
|
});
|
|
51
|
+
|
|
52
|
+
it("header renders without navigation links ", () => {
|
|
53
|
+
renderWithProviders(<QuicksightDashboardPage params={{ library: null }} />);
|
|
54
|
+
|
|
55
|
+
// Make sure we see the QuicksSight iFrame.
|
|
56
|
+
expect(screen.getByTitle("Library Dashboard")).toBeInTheDocument();
|
|
57
|
+
// Make sure we have the branding image.
|
|
58
|
+
expect(
|
|
59
|
+
screen.getByAltText("Palace Collection Manager")
|
|
60
|
+
).toBeInTheDocument();
|
|
61
|
+
|
|
62
|
+
// Make sure we do not see other navigation links.
|
|
63
|
+
["Dashboard", "System Configuration"].forEach((name) => {
|
|
64
|
+
expect(screen.queryByText(name)).not.toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
56
67
|
});
|
|
@@ -434,6 +434,53 @@ describe("Dashboard Statistics", () => {
|
|
|
434
434
|
expect(renderFor(false, managerAll)).not.toBeNull();
|
|
435
435
|
expect(renderFor(false, librarianAll)).not.toBeNull();
|
|
436
436
|
});
|
|
437
|
+
|
|
438
|
+
it("shows quicksight link only for sysadmins, if sysadmin-only flag set", () => {
|
|
439
|
+
const fakeQuickSightHref = "https://example.com/fakeQS";
|
|
440
|
+
|
|
441
|
+
// We'll use this function to test multiple scenarios.
|
|
442
|
+
const renderFor = (
|
|
443
|
+
onlySysadmins: boolean,
|
|
444
|
+
roles: { role: string; library?: string }[]
|
|
445
|
+
) => {
|
|
446
|
+
const contextProviderProps: Partial<ContextProviderProps> = {
|
|
447
|
+
featureFlags: { quicksightOnlyForSysadmins: onlySysadmins },
|
|
448
|
+
roles,
|
|
449
|
+
quicksightPagePath: fakeQuickSightHref,
|
|
450
|
+
};
|
|
451
|
+
const {
|
|
452
|
+
container,
|
|
453
|
+
getByRole,
|
|
454
|
+
queryByRole,
|
|
455
|
+
queryByText,
|
|
456
|
+
} = renderWithProviders(<Stats library={sampleLibraryKey} />, {
|
|
457
|
+
contextProviderProps,
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// We should always render a Usage reports group when a library is specified.
|
|
461
|
+
getByRole("heading", {
|
|
462
|
+
level: 3,
|
|
463
|
+
name: statGroupToHeading.usageReports,
|
|
464
|
+
});
|
|
465
|
+
const usageReportLink = queryByRole("link", { name: /View Usage/i });
|
|
466
|
+
if (usageReportLink) {
|
|
467
|
+
expect(usageReportLink).toHaveAttribute("href", fakeQuickSightHref);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Clean up the container after each render.
|
|
471
|
+
document.body.removeChild(container);
|
|
472
|
+
return usageReportLink;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// If the feature flag is set, the link should be visible only to sysadmins.
|
|
476
|
+
expect(renderFor(true, systemAdmin)).not.toBeNull();
|
|
477
|
+
expect(renderFor(true, managerAll)).toBeNull();
|
|
478
|
+
expect(renderFor(true, librarianAll)).toBeNull();
|
|
479
|
+
// If the feature flag is false, the button should be visible to all users.
|
|
480
|
+
expect(renderFor(false, systemAdmin)).not.toBeNull();
|
|
481
|
+
expect(renderFor(false, managerAll)).not.toBeNull();
|
|
482
|
+
expect(renderFor(false, librarianAll)).not.toBeNull();
|
|
483
|
+
});
|
|
437
484
|
});
|
|
438
485
|
|
|
439
486
|
describe("charting - custom tooltip", () => {
|
|
@@ -7,10 +7,15 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
7
7
|
import { render, RenderOptions, RenderResult } from "@testing-library/react";
|
|
8
8
|
import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
|
|
9
9
|
import { store } from "../../../src/store";
|
|
10
|
+
import {
|
|
11
|
+
TOSContextProvider,
|
|
12
|
+
TOSContextProviderProps,
|
|
13
|
+
} from "../../../src/components/TOSContext";
|
|
10
14
|
|
|
11
15
|
export type TestProviderWrapperOptions = {
|
|
12
16
|
reduxProviderProps?: ProviderProps;
|
|
13
17
|
contextProviderProps?: Partial<ContextProviderProps>;
|
|
18
|
+
tosContextProviderProps?: TOSContextProviderProps;
|
|
14
19
|
queryClient?: QueryClient;
|
|
15
20
|
};
|
|
16
21
|
export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
|
|
@@ -21,6 +26,13 @@ export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
|
|
|
21
26
|
// be the same for both the Redux Provider and the ContextProvider.
|
|
22
27
|
const defaultReduxStore = store;
|
|
23
28
|
|
|
29
|
+
// Setup default TOSContext provider props.
|
|
30
|
+
const tosText = "Sample terms of service.";
|
|
31
|
+
const tosHref = "http://example.com/terms-of-service";
|
|
32
|
+
const requiredTOSContextProviderProps: TOSContextProviderProps = {
|
|
33
|
+
...[tosText, tosHref],
|
|
34
|
+
};
|
|
35
|
+
|
|
24
36
|
// The `csrfToken` context provider prop is required, so we provide
|
|
25
37
|
// a default value here, so it can be easily merged with other props.
|
|
26
38
|
const requiredContextProviderProps: ContextProviderProps = {
|
|
@@ -35,6 +47,7 @@ const requiredContextProviderProps: ContextProviderProps = {
|
|
|
35
47
|
* @param {TestProviderWrapperOptions} options
|
|
36
48
|
* @param options.reduxProviderProps Props to pass to the Redux `Provider` wrapper
|
|
37
49
|
* @param {ContextProviderProps} options.contextProviderProps Props to pass to the ContextProvider wrapper
|
|
50
|
+
* @param {TOSContextProviderProps} options.tosContextProviderProps Props to pass to the TOSContextProvider wrapper
|
|
38
51
|
* @param {QueryClient} options.queryClient A `tanstack/react-query` QueryClient
|
|
39
52
|
* @returns {React.FunctionComponent} A React component that wraps children with our providers
|
|
40
53
|
*/
|
|
@@ -46,6 +59,7 @@ export const componentWithProviders = ({
|
|
|
46
59
|
csrfToken: "",
|
|
47
60
|
featureFlags: defaultFeatureFlags,
|
|
48
61
|
},
|
|
62
|
+
tosContextProviderProps = requiredTOSContextProviderProps,
|
|
49
63
|
queryClient = new QueryClient(),
|
|
50
64
|
}: TestProviderWrapperOptions = {}): React.FunctionComponent => {
|
|
51
65
|
const effectiveContextProviderProps = {
|
|
@@ -56,9 +70,11 @@ export const componentWithProviders = ({
|
|
|
56
70
|
const wrapper = ({ children }) => (
|
|
57
71
|
<Provider {...reduxProviderProps}>
|
|
58
72
|
<ContextProvider {...effectiveContextProviderProps}>
|
|
59
|
-
<
|
|
60
|
-
{
|
|
61
|
-
|
|
73
|
+
<TOSContextProvider value={tosContextProviderProps}>
|
|
74
|
+
<QueryClientProvider client={queryClient}>
|
|
75
|
+
{children}
|
|
76
|
+
</QueryClientProvider>
|
|
77
|
+
</TOSContextProvider>
|
|
62
78
|
</ContextProvider>
|
|
63
79
|
</Provider>
|
|
64
80
|
);
|