@thepalaceproject/circulation-admin 1.20.0 → 1.21.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
@@ -149,5 +149,5 @@
149
149
  "*.{js,jsx,ts,tsx,css,md}": "prettier --write",
150
150
  "*.{js,css,md}": "prettier --write"
151
151
  },
152
- "version": "1.20.0"
152
+ "version": "1.21.0-post.1"
153
153
  }
@@ -31,6 +31,7 @@ describe("CustomLists", () => {
31
31
 
32
32
  const contextProviderProps = {
33
33
  csrfToken: "",
34
+ featureFlags: {},
34
35
  roles: [{ role: "system" }],
35
36
  };
36
37
 
@@ -70,6 +71,7 @@ describe("CustomLists", () => {
70
71
 
71
72
  const contextProviderProps = {
72
73
  csrfToken: "",
74
+ featureFlags: {},
73
75
  roles: [{ role: "system" }],
74
76
  };
75
77
 
@@ -121,6 +123,7 @@ describe("CustomLists", () => {
121
123
 
122
124
  const contextProviderProps = {
123
125
  csrfToken: "",
126
+ featureFlags: {},
124
127
  roles: [{ role: "system" }],
125
128
  };
126
129
 
@@ -164,6 +167,7 @@ describe("CustomLists", () => {
164
167
 
165
168
  const contextProviderProps = {
166
169
  csrfToken: "",
170
+ featureFlags: {},
167
171
  roles: [{ role: "system" }],
168
172
  };
169
173
 
@@ -10,6 +10,7 @@ describe("IndividualAdminEditForm", () => {
10
10
 
11
11
  const contextProviderProps = {
12
12
  csrfToken: "",
13
+ featureFlags: {},
13
14
  roles: [
14
15
  {
15
16
  role: "system",
@@ -37,6 +37,7 @@ describe("QuicksightDashboard", () => {
37
37
  it("embed url is retrieved and set in iframe", async () => {
38
38
  const contextProviderProps = {
39
39
  csrfToken: "",
40
+ featureFlags: {},
40
41
  roles: [{ role: "system" }],
41
42
  };
42
43
 
@@ -1,6 +1,16 @@
1
1
  import * as React from "react";
2
2
  import { render } from "@testing-library/react";
3
- import { CustomTooltip } from "../../../src/components/LibraryStats";
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 = {
@@ -4,6 +4,7 @@ import ContextProvider, {
4
4
  } from "../../../src/components/ContextProvider";
5
5
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
6
6
  import { render, RenderOptions, RenderResult } from "@testing-library/react";
7
+ import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
7
8
 
8
9
  export type TestProviderWrapperOptions = {
9
10
  contextProviderProps?: Partial<ContextProviderProps>;
@@ -15,7 +16,10 @@ export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
15
16
 
16
17
  // The `csrfToken` context provider prop is required, so we provide
17
18
  // a default value here, so it can be easily merged with other props.
18
- const defaultContextProviderProps = { csrfToken: "" };
19
+ const defaultContextProviderProps: ContextProviderProps = {
20
+ csrfToken: "",
21
+ featureFlags: defaultFeatureFlags,
22
+ };
19
23
 
20
24
  /**
21
25
  * Returns a component, composed with our providers, that can be used to wrap
@@ -27,7 +31,10 @@ const defaultContextProviderProps = { csrfToken: "" };
27
31
  * @returns {React.FunctionComponent} A React component that wraps children with our providers
28
32
  */
29
33
  export const componentWithProviders = ({
30
- contextProviderProps = { csrfToken: "" },
34
+ contextProviderProps = {
35
+ csrfToken: "",
36
+ featureFlags: defaultFeatureFlags,
37
+ },
31
38
  queryClient = new QueryClient(),
32
39
  }: TestProviderWrapperOptions): React.FunctionComponent => {
33
40
  const effectiveContextProviderProps = {
@@ -67,7 +67,7 @@ module.exports = (env) => {
67
67
  return;
68
68
  }
69
69
 
70
- const locationUrl = new URL(location);
70
+ const locationUrl = new URL(location, backendUrl);
71
71
 
72
72
  if (locationUrl.host !== backendUrl.host) {
73
73
  return;