@thepalaceproject/circulation-admin 1.29.0 → 1.30.0-post.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/package.json CHANGED
@@ -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.29.0"
154
+ "version": "1.30.0-post.1"
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,8 @@ import {
5
5
  useAppEmail,
6
6
  useAppFeatureFlags,
7
7
  useCsrfToken,
8
+ useTermsOfService,
9
+ useSupportContactUrl,
8
10
  } from "../../../src/context/appContext";
9
11
  import { componentWithProviders } from "../testUtils/withProviders";
10
12
  import { ContextProviderProps } from "../../../src/components/ContextProvider";
@@ -25,12 +27,20 @@ describe("AppContext", () => {
25
27
  testFalse: false,
26
28
  };
27
29
  const expectedRoles = [{ role: "system" }];
30
+ const expectedTermsOfService = {
31
+ text: "Terms of Service",
32
+ href: "/terms-of-service",
33
+ };
34
+ const expectedSupportContactUrl = "helpdesk@example.com";
28
35
 
29
36
  const contextProviderProps: ContextProviderProps = {
30
37
  csrfToken: expectedCsrfToken,
31
38
  featureFlags: expectedFeatureFlags,
32
39
  roles: expectedRoles,
33
40
  email: expectedEmail,
41
+ tos_link_text: expectedTermsOfService.text,
42
+ tos_link_href: expectedTermsOfService.href,
43
+ support_contact_url: expectedSupportContactUrl,
34
44
  };
35
45
  const wrapper = componentWithProviders({ contextProviderProps });
36
46
 
@@ -41,6 +51,7 @@ describe("AppContext", () => {
41
51
  expect(value.admin.email).toEqual(expectedEmail);
42
52
  expect(value.admin.roles).toEqual(expectedRoles);
43
53
  expect(value.featureFlags).toEqual(expectedFeatureFlags);
54
+ expect(value.support_contact_url).toEqual(expectedSupportContactUrl);
44
55
  });
45
56
 
46
57
  it("provides useAppAdmin context hook", () => {
@@ -69,4 +80,22 @@ describe("AppContext", () => {
69
80
  const flags = result.current;
70
81
  expect(flags).toEqual(expectedFeatureFlags);
71
82
  });
83
+
84
+ it("provides useTermsOfService context hook", () => {
85
+ const { result } = renderHook(() => useTermsOfService(), {
86
+ wrapper,
87
+ });
88
+ const tosLink = result.current;
89
+ const { text, href } = tosLink;
90
+ expect(tosLink).toEqual(expectedTermsOfService);
91
+ expect(text).toEqual(expectedTermsOfService.text);
92
+ expect(href).toEqual(expectedTermsOfService.href);
93
+ });
94
+ it("provides useSupportContactUrl context hook", () => {
95
+ const { result } = renderHook(() => useSupportContactUrl(), {
96
+ wrapper,
97
+ });
98
+ const supportContactUrl = result.current;
99
+ expect(supportContactUrl).toEqual(expectedSupportContactUrl);
100
+ });
72
101
  });
@@ -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
- <TOSContextProvider value={tosContextProviderProps}>
74
- <QueryClientProvider client={queryClient}>
75
- {children}
76
- </QueryClientProvider>
77
- </TOSContextProvider>
59
+ <QueryClientProvider client={queryClient}>
60
+ {children}
61
+ </QueryClientProvider>
78
62
  </ContextProvider>
79
63
  </Provider>
80
64
  );