@thepalaceproject/circulation-admin 1.28.1 → 1.29.0-post.3
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 +1 -1
- package/package.json +2 -2
- package/tests/jest/components/CirculationEventsDownload.test.tsx +66 -0
- package/tests/jest/context/AppContext.test.tsx +18 -0
- package/tests/jest/testUtils/withProviders.tsx +3 -19
- package/tests/jest/utils/NoCacheDataFetcher.test.ts +75 -0
|
@@ -29,7 +29,7 @@ object-assign
|
|
|
29
29
|
* @license MIT
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
/*! @license DOMPurify | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/
|
|
32
|
+
/*! @license DOMPurify 3.2.4 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.4/LICENSE */
|
|
33
33
|
|
|
34
34
|
/*! @preserve
|
|
35
35
|
* numeral.js
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@nypl/dgx-svg-icons": "0.3.4",
|
|
39
39
|
"@reduxjs/toolkit": "^2.2.5",
|
|
40
40
|
"@tanstack/react-query": "^4.36.1",
|
|
41
|
-
"@thepalaceproject/web-opds-client": "^1.0
|
|
41
|
+
"@thepalaceproject/web-opds-client": "^1.1.0",
|
|
42
42
|
"bootstrap": "^3.3.6",
|
|
43
43
|
"classnames": "^2.3.1",
|
|
44
44
|
"draft-convert": "^2.1.5",
|
|
@@ -151,5 +151,5 @@
|
|
|
151
151
|
"*.{js,jsx,ts,tsx,css,md}": "prettier --write",
|
|
152
152
|
"*.{js,css,md}": "prettier --write"
|
|
153
153
|
},
|
|
154
|
-
"version": "1.
|
|
154
|
+
"version": "1.29.0-post.3"
|
|
155
155
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
|
|
5
|
+
import CirculationEventsDownload from "../../../src/components/CirculationEventsDownload";
|
|
6
|
+
import { ContextProviderProps } from "../../../src/components/ContextProvider";
|
|
7
|
+
import { FeatureFlags } from "../../../src/interfaces";
|
|
8
|
+
import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
|
|
9
|
+
import { renderWithProviders } from "../testUtils/withProviders";
|
|
10
|
+
|
|
11
|
+
describe("CirculationEventsDownload", () => {
|
|
12
|
+
it("renders nothing if showCircEventsDownload feature flag is false", () => {
|
|
13
|
+
const featureFlags: FeatureFlags = {
|
|
14
|
+
...defaultFeatureFlags,
|
|
15
|
+
showCircEventsDownload: false,
|
|
16
|
+
};
|
|
17
|
+
const contextProviderProps: Partial<ContextProviderProps> = {
|
|
18
|
+
featureFlags,
|
|
19
|
+
};
|
|
20
|
+
const { container } = renderWithProviders(
|
|
21
|
+
<CirculationEventsDownload library="testlib" />,
|
|
22
|
+
{
|
|
23
|
+
contextProviderProps,
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
expect(container).toBeEmptyDOMElement();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("when showCircEventsDownload feature flag is true", () => {
|
|
30
|
+
const featureFlags: FeatureFlags = {
|
|
31
|
+
...defaultFeatureFlags,
|
|
32
|
+
showCircEventsDownload: true,
|
|
33
|
+
};
|
|
34
|
+
const libraryProp = "testlib";
|
|
35
|
+
const contextProviderProps: Partial<ContextProviderProps> = {
|
|
36
|
+
featureFlags,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
renderWithProviders(<CirculationEventsDownload library={libraryProp} />, {
|
|
41
|
+
contextProviderProps,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("renders a download button", () => {
|
|
46
|
+
expect(
|
|
47
|
+
screen.getByRole("button", { name: "Download CSV" })
|
|
48
|
+
).toBeInTheDocument();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("shows the form when the download button is clicked", () => {
|
|
52
|
+
const downloadButton = screen.getByRole("button", {
|
|
53
|
+
name: "Download CSV",
|
|
54
|
+
});
|
|
55
|
+
fireEvent.click(downloadButton);
|
|
56
|
+
expect(
|
|
57
|
+
screen.getByRole("heading", { name: "Download CSV" })
|
|
58
|
+
).toBeInTheDocument();
|
|
59
|
+
expect(
|
|
60
|
+
screen.getByRole("button", { name: "Download" })
|
|
61
|
+
).toBeInTheDocument();
|
|
62
|
+
expect(screen.getByText("Start Date")).toBeInTheDocument();
|
|
63
|
+
expect(screen.getByText("End Date")).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
useAppEmail,
|
|
6
6
|
useAppFeatureFlags,
|
|
7
7
|
useCsrfToken,
|
|
8
|
+
useTermsOfService,
|
|
8
9
|
} from "../../../src/context/appContext";
|
|
9
10
|
import { componentWithProviders } from "../testUtils/withProviders";
|
|
10
11
|
import { ContextProviderProps } from "../../../src/components/ContextProvider";
|
|
@@ -25,12 +26,18 @@ describe("AppContext", () => {
|
|
|
25
26
|
testFalse: false,
|
|
26
27
|
};
|
|
27
28
|
const expectedRoles = [{ role: "system" }];
|
|
29
|
+
const expectedTermsOfService = {
|
|
30
|
+
text: "Terms of Service",
|
|
31
|
+
href: "/terms-of-service",
|
|
32
|
+
};
|
|
28
33
|
|
|
29
34
|
const contextProviderProps: ContextProviderProps = {
|
|
30
35
|
csrfToken: expectedCsrfToken,
|
|
31
36
|
featureFlags: expectedFeatureFlags,
|
|
32
37
|
roles: expectedRoles,
|
|
33
38
|
email: expectedEmail,
|
|
39
|
+
tos_link_text: expectedTermsOfService.text,
|
|
40
|
+
tos_link_href: expectedTermsOfService.href,
|
|
34
41
|
};
|
|
35
42
|
const wrapper = componentWithProviders({ contextProviderProps });
|
|
36
43
|
|
|
@@ -69,4 +76,15 @@ describe("AppContext", () => {
|
|
|
69
76
|
const flags = result.current;
|
|
70
77
|
expect(flags).toEqual(expectedFeatureFlags);
|
|
71
78
|
});
|
|
79
|
+
|
|
80
|
+
it("provides useTermsOfService context hook", () => {
|
|
81
|
+
const { result } = renderHook(() => useTermsOfService(), {
|
|
82
|
+
wrapper,
|
|
83
|
+
});
|
|
84
|
+
const tosLink = result.current;
|
|
85
|
+
const { text, href } = tosLink;
|
|
86
|
+
expect(tosLink).toEqual(expectedTermsOfService);
|
|
87
|
+
expect(text).toEqual(expectedTermsOfService.text);
|
|
88
|
+
expect(href).toEqual(expectedTermsOfService.href);
|
|
89
|
+
});
|
|
72
90
|
});
|
|
@@ -7,15 +7,10 @@ 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";
|
|
14
10
|
|
|
15
11
|
export type TestProviderWrapperOptions = {
|
|
16
12
|
reduxProviderProps?: ProviderProps;
|
|
17
13
|
contextProviderProps?: Partial<ContextProviderProps>;
|
|
18
|
-
tosContextProviderProps?: TOSContextProviderProps;
|
|
19
14
|
queryClient?: QueryClient;
|
|
20
15
|
};
|
|
21
16
|
export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
|
|
@@ -26,13 +21,6 @@ export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
|
|
|
26
21
|
// be the same for both the Redux Provider and the ContextProvider.
|
|
27
22
|
const defaultReduxStore = store;
|
|
28
23
|
|
|
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
|
-
|
|
36
24
|
// The `csrfToken` context provider prop is required, so we provide
|
|
37
25
|
// a default value here, so it can be easily merged with other props.
|
|
38
26
|
const requiredContextProviderProps: ContextProviderProps = {
|
|
@@ -47,7 +35,6 @@ const requiredContextProviderProps: ContextProviderProps = {
|
|
|
47
35
|
* @param {TestProviderWrapperOptions} options
|
|
48
36
|
* @param options.reduxProviderProps Props to pass to the Redux `Provider` wrapper
|
|
49
37
|
* @param {ContextProviderProps} options.contextProviderProps Props to pass to the ContextProvider wrapper
|
|
50
|
-
* @param {TOSContextProviderProps} options.tosContextProviderProps Props to pass to the TOSContextProvider wrapper
|
|
51
38
|
* @param {QueryClient} options.queryClient A `tanstack/react-query` QueryClient
|
|
52
39
|
* @returns {React.FunctionComponent} A React component that wraps children with our providers
|
|
53
40
|
*/
|
|
@@ -59,7 +46,6 @@ export const componentWithProviders = ({
|
|
|
59
46
|
csrfToken: "",
|
|
60
47
|
featureFlags: defaultFeatureFlags,
|
|
61
48
|
},
|
|
62
|
-
tosContextProviderProps = requiredTOSContextProviderProps,
|
|
63
49
|
queryClient = new QueryClient(),
|
|
64
50
|
}: TestProviderWrapperOptions = {}): React.FunctionComponent => {
|
|
65
51
|
const effectiveContextProviderProps = {
|
|
@@ -70,11 +56,9 @@ export const componentWithProviders = ({
|
|
|
70
56
|
const wrapper = ({ children }) => (
|
|
71
57
|
<Provider {...reduxProviderProps}>
|
|
72
58
|
<ContextProvider {...effectiveContextProviderProps}>
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
</QueryClientProvider>
|
|
77
|
-
</TOSContextProvider>
|
|
59
|
+
<QueryClientProvider client={queryClient}>
|
|
60
|
+
{children}
|
|
61
|
+
</QueryClientProvider>
|
|
78
62
|
</ContextProvider>
|
|
79
63
|
</Provider>
|
|
80
64
|
);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Need to manually mock DataFetcher before importing NoCacheDataFetcher
|
|
2
|
+
const mockSuperFetch = jest.fn();
|
|
3
|
+
|
|
4
|
+
// Mock the DataFetcher module
|
|
5
|
+
jest.mock("@thepalaceproject/web-opds-client/lib/DataFetcher", () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
default: class MockDataFetcher {
|
|
8
|
+
fetch(url: string, options?: any) {
|
|
9
|
+
return mockSuperFetch(url, options);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
// Import after mocking
|
|
15
|
+
import NoCacheDataFetcher from "../../../src/utils/NoCacheDataFetcher";
|
|
16
|
+
|
|
17
|
+
const TEST_URL = "http://example.com";
|
|
18
|
+
|
|
19
|
+
describe("NoCacheDataFetcher", () => {
|
|
20
|
+
let fetcher: NoCacheDataFetcher;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
// Clear mocks between tests
|
|
24
|
+
mockSuperFetch.mockClear();
|
|
25
|
+
|
|
26
|
+
// Create instance of class under test
|
|
27
|
+
fetcher = new NoCacheDataFetcher();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("adds no-cache headers to fetch requests", async () => {
|
|
31
|
+
await fetcher.fetch(TEST_URL);
|
|
32
|
+
|
|
33
|
+
expect(mockSuperFetch).toHaveBeenCalledWith(
|
|
34
|
+
TEST_URL,
|
|
35
|
+
expect.objectContaining({
|
|
36
|
+
headers: { "Cache-Control": "no-cache" },
|
|
37
|
+
cache: "no-cache",
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("preserves existing headers when adding no-cache headers", async () => {
|
|
43
|
+
const options = {
|
|
44
|
+
headers: { "Content-Type": "application/json" },
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
await fetcher.fetch(TEST_URL, options);
|
|
48
|
+
|
|
49
|
+
expect(mockSuperFetch).toHaveBeenCalledWith(
|
|
50
|
+
TEST_URL,
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
headers: {
|
|
53
|
+
"Cache-Control": "no-cache",
|
|
54
|
+
"Content-Type": "application/json",
|
|
55
|
+
},
|
|
56
|
+
cache: "no-cache",
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("passes through other options to super.fetch", async () => {
|
|
62
|
+
await fetcher.fetch(TEST_URL, {
|
|
63
|
+
credentials: "include",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(mockSuperFetch).toHaveBeenCalledWith(
|
|
67
|
+
TEST_URL,
|
|
68
|
+
expect.objectContaining({
|
|
69
|
+
headers: { "Cache-Control": "no-cache" },
|
|
70
|
+
cache: "no-cache",
|
|
71
|
+
credentials: "include",
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
});
|