@thepalaceproject/circulation-admin 1.19.0 → 1.20.0-post.2
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.js +1 -1
- package/dist/circulation-admin.js.LICENSE.txt +30 -2
- package/jest.config.js +4 -0
- package/jest.polyfills.js +20 -0
- package/package.json +12 -4
- package/tests/jest/api/admin.test.ts +60 -0
- package/tests/jest/components/CustomLists.test.tsx +15 -12
- package/tests/jest/components/IndividualAdminEditForm.test.tsx +1 -0
- package/tests/jest/components/InventoryReportRequestModal.test.tsx +652 -0
- package/tests/jest/components/QuicksightDashboard.test.tsx +13 -12
- package/tests/jest/components/Stats.test.tsx +62 -1
- package/tests/jest/testUtils/withProviders.tsx +78 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { render } from "@testing-library/react";
|
|
3
|
-
import {
|
|
3
|
+
import LibraryStats, {
|
|
4
|
+
CustomTooltip,
|
|
5
|
+
} from "../../../src/components/LibraryStats";
|
|
6
|
+
import { renderWithProviders } from "../testUtils/withProviders";
|
|
7
|
+
import { ContextProviderProps } from "../../../src/components/ContextProvider";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
statisticsApiResponseData,
|
|
11
|
+
testLibraryKey as sampleLibraryKey,
|
|
12
|
+
} from "../../__data__/statisticsApiResponseData";
|
|
13
|
+
import { normalizeStatistics } from "../../../src/components/Stats";
|
|
4
14
|
|
|
5
15
|
describe("Dashboard Statistics", () => {
|
|
6
16
|
// NB: This adds test to the already existing tests in:
|
|
@@ -11,6 +21,57 @@ describe("Dashboard Statistics", () => {
|
|
|
11
21
|
// Those tests should eventually be migrated here and
|
|
12
22
|
// adapted to the Jest/React Testing Library paradigm.
|
|
13
23
|
|
|
24
|
+
describe("requesting inventory reports", () => {
|
|
25
|
+
// Convert from the API format to our in-app format.
|
|
26
|
+
const statisticsData = normalizeStatistics(statisticsApiResponseData);
|
|
27
|
+
const librariesStatsTestDataByKey = statisticsData.libraries.reduce(
|
|
28
|
+
(map, library) => ({ ...map, [library.key]: library }),
|
|
29
|
+
{}
|
|
30
|
+
);
|
|
31
|
+
const sampleStatsData = librariesStatsTestDataByKey[sampleLibraryKey];
|
|
32
|
+
|
|
33
|
+
const systemAdmin = [{ role: "system" }];
|
|
34
|
+
const managerAll = [{ role: "manager-all" }];
|
|
35
|
+
const librarianAll = [{ role: "librarian-all" }];
|
|
36
|
+
|
|
37
|
+
const baseContextProviderProps = {
|
|
38
|
+
csrfToken: "",
|
|
39
|
+
featureFlags: { reportsOnlyForSysadmins: false },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const renderFor = (
|
|
43
|
+
onlySysadmins: boolean,
|
|
44
|
+
roles: { role: string; library?: string }[]
|
|
45
|
+
) => {
|
|
46
|
+
const contextProviderProps: ContextProviderProps = {
|
|
47
|
+
...baseContextProviderProps,
|
|
48
|
+
featureFlags: { reportsOnlyForSysadmins: onlySysadmins },
|
|
49
|
+
roles,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const { container, queryByRole } = renderWithProviders(
|
|
53
|
+
<LibraryStats stats={sampleStatsData} library={sampleLibraryKey} />,
|
|
54
|
+
{ contextProviderProps }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const result = queryByRole("button", { name: "⬇︎" });
|
|
58
|
+
// Clean up the container after each render.
|
|
59
|
+
document.body.removeChild(container);
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
it("shows inventory reports only for sysadmins, if feature flag set", async () => {
|
|
64
|
+
// If the feature flag is set, the button should be visible only to sysadmins.
|
|
65
|
+
expect(renderFor(true, systemAdmin)).not.toBeNull();
|
|
66
|
+
expect(renderFor(true, managerAll)).toBeNull();
|
|
67
|
+
expect(renderFor(true, librarianAll)).toBeNull();
|
|
68
|
+
// If the feature flag is false, the button should be visible to all users.
|
|
69
|
+
expect(renderFor(false, systemAdmin)).not.toBeNull();
|
|
70
|
+
expect(renderFor(false, managerAll)).not.toBeNull();
|
|
71
|
+
expect(renderFor(false, librarianAll)).not.toBeNull();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
14
75
|
describe("charting - custom tooltip", () => {
|
|
15
76
|
const defaultLabel = "Collection X";
|
|
16
77
|
const summaryInventory = {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import ContextProvider, {
|
|
3
|
+
ContextProviderProps,
|
|
4
|
+
} from "../../../src/components/ContextProvider";
|
|
5
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
6
|
+
import { render, RenderOptions, RenderResult } from "@testing-library/react";
|
|
7
|
+
import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
|
|
8
|
+
|
|
9
|
+
export type TestProviderWrapperOptions = {
|
|
10
|
+
contextProviderProps?: Partial<ContextProviderProps>;
|
|
11
|
+
queryClient?: QueryClient;
|
|
12
|
+
};
|
|
13
|
+
export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
|
|
14
|
+
renderOptions?: Omit<RenderOptions, "queries">;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The `csrfToken` context provider prop is required, so we provide
|
|
18
|
+
// a default value here, so it can be easily merged with other props.
|
|
19
|
+
const defaultContextProviderProps: ContextProviderProps = {
|
|
20
|
+
csrfToken: "",
|
|
21
|
+
featureFlags: defaultFeatureFlags,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns a component, composed with our providers, that can be used to wrap
|
|
26
|
+
* a React element for testing.
|
|
27
|
+
*
|
|
28
|
+
* @param {TestProviderWrapperOptions} options
|
|
29
|
+
* @param {ContextProviderProps} options.contextProviderProps Props to pass to the ContextProvider wrapper
|
|
30
|
+
* @param {QueryClient} options.queryClient A `tanstack/react-query` QueryClient
|
|
31
|
+
* @returns {React.FunctionComponent} A React component that wraps children with our providers
|
|
32
|
+
*/
|
|
33
|
+
export const componentWithProviders = ({
|
|
34
|
+
contextProviderProps = {
|
|
35
|
+
csrfToken: "",
|
|
36
|
+
featureFlags: defaultFeatureFlags,
|
|
37
|
+
},
|
|
38
|
+
queryClient = new QueryClient(),
|
|
39
|
+
}: TestProviderWrapperOptions): React.FunctionComponent => {
|
|
40
|
+
const effectiveContextProviderProps = {
|
|
41
|
+
...defaultContextProviderProps,
|
|
42
|
+
...contextProviderProps,
|
|
43
|
+
};
|
|
44
|
+
const wrapper = ({ children }) => (
|
|
45
|
+
<ContextProvider {...effectiveContextProviderProps}>
|
|
46
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
47
|
+
</ContextProvider>
|
|
48
|
+
);
|
|
49
|
+
wrapper.displayName = "TestWrapperComponent";
|
|
50
|
+
return wrapper;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Renders a React element with specified providers and provides a function for re-rendering with the same context.
|
|
55
|
+
*
|
|
56
|
+
* @param {React.ReactElement} renderChildren The element to render
|
|
57
|
+
* @param {TestRenderWrapperOptions} testRenderOptions Options for rendering with providers
|
|
58
|
+
* @returns {RenderResult} The result of rendering, including re-rendering functionality
|
|
59
|
+
*/
|
|
60
|
+
export const renderWithProviders = (
|
|
61
|
+
renderChildren: React.ReactElement,
|
|
62
|
+
testRenderOptions: TestRenderWrapperOptions = {}
|
|
63
|
+
): RenderResult => {
|
|
64
|
+
const wrapper = componentWithProviders(testRenderOptions);
|
|
65
|
+
const renderResult = render(
|
|
66
|
+
wrapper({ children: renderChildren }),
|
|
67
|
+
testRenderOptions.renderOptions
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const rerenderWithProviders = (reRenderChildren: React.ReactElement) => {
|
|
71
|
+
return renderResult.rerender(wrapper({ children: reRenderChildren }));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
...renderResult,
|
|
76
|
+
rerender: rerenderWithProviders,
|
|
77
|
+
};
|
|
78
|
+
};
|