@thepalaceproject/circulation-admin 0.0.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/.eslintrc +59 -0
- package/.node-version +1 -0
- package/.nvmrc +1 -0
- package/.prettierrc.json +10 -0
- package/.sass-lint.yml +37 -0
- package/CHANGELOG.md +946 -0
- package/README.md +155 -0
- package/dist/060b2710bdbbe3dfe48b58d59bd5f1fb.svg +288 -0
- package/dist/0db1520f47986b6c755a.svg +1 -0
- package/dist/1e59d2330b4c6deb84b3.ttf +0 -0
- package/dist/20fd1704ea223900efa9.woff2 +0 -0
- package/dist/4692b9ec53fd5972caa2.ttf +0 -0
- package/dist/5be1347c682810f199c7.eot +0 -0
- package/dist/6563aa3790be8329e4f2.svg +1 -0
- package/dist/82b1212e45a2bc35dd73.woff +0 -0
- package/dist/8b43027f47b20503057d.eot +0 -0
- package/dist/PalaceCollectionManagerLogo.svg +122 -0
- package/dist/be810be3a3e14c682a25.woff2 +0 -0
- package/dist/c1e38fd9e0e74ba58f7a2b77ef29fdd3.svg +2671 -0
- package/dist/circulation-admin.css +6841 -0
- package/dist/circulation-admin.js +2 -0
- package/dist/circulation-admin.js.LICENSE.txt +153 -0
- package/dist/f691f37e57f04c152e23.woff +0 -0
- package/jest.config.js +15 -0
- package/jest.polyfills.js +12 -0
- package/nightwatch.json +58 -0
- package/package.json +155 -0
- package/pull_request_template.md +22 -0
- package/requirements-ci.txt +1 -0
- package/testReporter.js +31 -0
- package/tests/__data__/statisticsApiResponseData.ts +327 -0
- package/tests/__mocks__/fileMock.js +1 -0
- package/tests/__mocks__/styleMock.js +1 -0
- package/tests/browser/README.md +19 -0
- package/tests/browser/assertions/noError.js +38 -0
- package/tests/browser/commands/goHome.js +13 -0
- package/tests/browser/commands/signIn.js +18 -0
- package/tests/browser/globals.js.sample +5 -0
- package/tests/browser/navigate.js +294 -0
- package/tests/browser/pages/book.js +21 -0
- package/tests/browser/pages/catalog.js +24 -0
- package/tests/browser/pages/login.js +11 -0
- package/tests/browser/redirect.js +104 -0
- package/tests/browser/signInFailure.js +22 -0
- package/tests/jest/README.md +6 -0
- package/tests/jest/api/admin.test.ts +60 -0
- package/tests/jest/businessRules/roleBasedAccess.test.ts +250 -0
- package/tests/jest/components/AdvancedSearchBuilder.test.tsx +38 -0
- package/tests/jest/components/BookEditor.test.tsx +240 -0
- package/tests/jest/components/CirculationEventsDownload.test.tsx +65 -0
- package/tests/jest/components/CustomLists.test.tsx +203 -0
- package/tests/jest/components/EditableInput.test.tsx +64 -0
- package/tests/jest/components/IndividualAdminEditForm.test.tsx +128 -0
- package/tests/jest/components/InventoryReportRequestModal.test.tsx +652 -0
- package/tests/jest/components/Lane.test.tsx +78 -0
- package/tests/jest/components/LaneEditor.test.tsx +148 -0
- package/tests/jest/components/ProtocolFormField.test.tsx +37 -0
- package/tests/jest/components/QuicksightDashboard.test.tsx +67 -0
- package/tests/jest/components/Stats.test.tsx +699 -0
- package/tests/jest/context/AppContext.test.tsx +113 -0
- package/tests/jest/features/book.test.ts +396 -0
- package/tests/jest/jest-setup.ts +1 -0
- package/tests/jest/sample/sample.test.js +3 -0
- package/tests/jest/testUtils/renderWithContext.tsx +38 -0
- package/tests/jest/testUtils/withProviders.tsx +92 -0
- package/tests/jest/utils/NoCacheDataFetcher.test.ts +75 -0
- package/tsconfig.json +25 -0
- package/tslint.json +56 -0
- package/webpack.common.js +72 -0
- package/webpack.dev-server.config.js +215 -0
- package/webpack.dev.config.js +9 -0
- package/webpack.prod.config.js +8 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { ALL_LIBRARIES_HEADING } from "../../../src/components/LibraryStats";
|
|
4
|
+
import { CustomTooltip } from "../../../src/components/StatsCollectionsBarChart";
|
|
5
|
+
import {
|
|
6
|
+
componentWithProviders,
|
|
7
|
+
renderWithProviders,
|
|
8
|
+
} from "../testUtils/withProviders";
|
|
9
|
+
import {
|
|
10
|
+
statisticsApiResponseData,
|
|
11
|
+
testLibraryKey as sampleLibraryKey,
|
|
12
|
+
testLibraryName as sampleLibraryName,
|
|
13
|
+
} from "../../__data__/statisticsApiResponseData";
|
|
14
|
+
|
|
15
|
+
import { normalizeStatistics } from "../../../src/features/stats/normalizeStatistics";
|
|
16
|
+
import { useGetStatsQuery } from "../../../src/features/stats/statsSlice";
|
|
17
|
+
import * as fetchMock from "fetch-mock-jest";
|
|
18
|
+
import { STATS_API_ENDPOINT } from "../../../src/features/stats/statsSlice";
|
|
19
|
+
import Stats from "../../../src/components/Stats";
|
|
20
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
21
|
+
import { FetchErrorData } from "@thepalaceproject/web-opds-client/lib/interfaces";
|
|
22
|
+
import { store } from "../../../src/store";
|
|
23
|
+
import { api } from "../../../src/features/api/apiSlice";
|
|
24
|
+
import {
|
|
25
|
+
AdminRoleData,
|
|
26
|
+
ConfigurationSettings,
|
|
27
|
+
RolesData,
|
|
28
|
+
} from "../../../src/interfaces";
|
|
29
|
+
|
|
30
|
+
const normalizedData = normalizeStatistics(statisticsApiResponseData);
|
|
31
|
+
|
|
32
|
+
global.ResizeObserver = require("resize-observer-polyfill");
|
|
33
|
+
|
|
34
|
+
describe("Dashboard Statistics", () => {
|
|
35
|
+
// NB: This adds test to the already existing tests in:
|
|
36
|
+
// - `src/components/__tests__/LibraryStats-test.tsx`.
|
|
37
|
+
// - `src/components/__tests__/SingleStatListItem-test.tsx`.
|
|
38
|
+
//
|
|
39
|
+
// Those tests should eventually be migrated here and
|
|
40
|
+
// adapted to the Jest/React Testing Library paradigm.
|
|
41
|
+
|
|
42
|
+
// Configure standard constructors so that RTK Query works in tests with FetchMockJest
|
|
43
|
+
Object.assign(fetchMock.config, {
|
|
44
|
+
fetch,
|
|
45
|
+
Headers,
|
|
46
|
+
Request,
|
|
47
|
+
Response,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const statGroupToHeading = {
|
|
51
|
+
patrons: "Current Circulation Activity",
|
|
52
|
+
circulations: "Circulation Totals",
|
|
53
|
+
inventory: "Inventory",
|
|
54
|
+
usageReports: "Usage and Reports",
|
|
55
|
+
collections: "Configured Collections",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
describe("query hook correctly handles fetch responses", () => {
|
|
59
|
+
const wrapper = componentWithProviders();
|
|
60
|
+
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
store.dispatch(api.util.resetApiState());
|
|
63
|
+
fetchMock.restore();
|
|
64
|
+
});
|
|
65
|
+
afterAll(() => {
|
|
66
|
+
store.dispatch(api.util.resetApiState());
|
|
67
|
+
fetchMock.restore();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("returns data when fetch successful", async () => {
|
|
71
|
+
fetchMock.get(
|
|
72
|
+
`path:${STATS_API_ENDPOINT}`,
|
|
73
|
+
{
|
|
74
|
+
body: JSON.stringify(statisticsApiResponseData),
|
|
75
|
+
status: 200,
|
|
76
|
+
},
|
|
77
|
+
{ overwriteRoutes: true }
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const { result, waitFor } = renderHook(() => useGetStatsQuery(), {
|
|
81
|
+
wrapper,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Expect loading status immediately after first use of the hook.
|
|
85
|
+
let { isSuccess, isError, error, data } = result.current;
|
|
86
|
+
expect(isSuccess).toBe(false);
|
|
87
|
+
expect(isError).toBe(false);
|
|
88
|
+
expect(error).toBe(undefined);
|
|
89
|
+
expect(data).toEqual(undefined);
|
|
90
|
+
|
|
91
|
+
// Once loaded, we should have our data.
|
|
92
|
+
await waitFor(() => !result.current.isLoading);
|
|
93
|
+
({ isSuccess, isError, error, data } = result.current);
|
|
94
|
+
|
|
95
|
+
expect(isSuccess).toBe(true);
|
|
96
|
+
expect(isError).toBe(false);
|
|
97
|
+
expect(error).toBe(undefined);
|
|
98
|
+
expect(data).toEqual(normalizedData);
|
|
99
|
+
|
|
100
|
+
// But if we use the hook again, we should get the data back from
|
|
101
|
+
// the cache immediately, without loading state.
|
|
102
|
+
const { result: result2 } = renderHook(() => useGetStatsQuery(), {
|
|
103
|
+
wrapper,
|
|
104
|
+
});
|
|
105
|
+
({ isSuccess, isError, error, data } = result2.current);
|
|
106
|
+
|
|
107
|
+
expect(isSuccess).toBe(true);
|
|
108
|
+
expect(isError).toBe(false);
|
|
109
|
+
expect(error).toBe(undefined);
|
|
110
|
+
expect(data).toEqual(normalizedData);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("returns error and no data when request fails", async () => {
|
|
114
|
+
fetchMock.get(
|
|
115
|
+
`path:${STATS_API_ENDPOINT}`,
|
|
116
|
+
{
|
|
117
|
+
status: 500,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
overwriteRoutes: true,
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const { result, waitFor } = renderHook(() => useGetStatsQuery(), {
|
|
125
|
+
wrapper,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Expect loading status immediately after first use of the hook.
|
|
129
|
+
let { isSuccess, isError, error, data } = result.current;
|
|
130
|
+
expect(isSuccess).toBe(false);
|
|
131
|
+
expect(isError).toBe(false);
|
|
132
|
+
expect(error).toBe(undefined);
|
|
133
|
+
expect(data).toEqual(undefined);
|
|
134
|
+
|
|
135
|
+
await waitFor(() => !result.current.isLoading);
|
|
136
|
+
({ isSuccess, isError, error, data } = result.current);
|
|
137
|
+
|
|
138
|
+
expect(isSuccess).toBe(false);
|
|
139
|
+
expect(isError).toBe(true);
|
|
140
|
+
expect(data).toBe(undefined);
|
|
141
|
+
expect((error as FetchErrorData).status).toBe(500);
|
|
142
|
+
|
|
143
|
+
// But if we use the hook again, we should get our error back from
|
|
144
|
+
// the cache immediately, without loading state.
|
|
145
|
+
const { result: result2 } = renderHook(() => useGetStatsQuery(), {
|
|
146
|
+
wrapper,
|
|
147
|
+
});
|
|
148
|
+
({ isSuccess, isError, error, data } = result2.current);
|
|
149
|
+
|
|
150
|
+
expect(isSuccess).toBe(false);
|
|
151
|
+
expect(isError).toBe(true);
|
|
152
|
+
expect(data).toBe(undefined);
|
|
153
|
+
expect((error as FetchErrorData).status).toBe(500);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("rendering", () => {
|
|
158
|
+
beforeAll(() => {
|
|
159
|
+
fetchMock.get(`path:${STATS_API_ENDPOINT}`, {
|
|
160
|
+
body: JSON.stringify(statisticsApiResponseData),
|
|
161
|
+
status: 200,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
afterAll(() => {
|
|
165
|
+
fetchMock.restore();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("correctly handles fetching and caching", () => {
|
|
169
|
+
afterEach(() => {
|
|
170
|
+
fetchMock.resetHistory();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const assertLoadingState = ({ getByRole }) => {
|
|
174
|
+
getByRole("dialog", { name: "Loading" });
|
|
175
|
+
getByRole("heading", { level: 1, name: "Loading" });
|
|
176
|
+
};
|
|
177
|
+
const assertNotLoadingState = ({ queryByRole }) => {
|
|
178
|
+
const missingLoadingDialog = queryByRole("dialog", { name: "Loading" });
|
|
179
|
+
const missingLoadingHeading = queryByRole("heading", {
|
|
180
|
+
level: 1,
|
|
181
|
+
name: "Loading",
|
|
182
|
+
});
|
|
183
|
+
expect(missingLoadingDialog).not.toBeInTheDocument();
|
|
184
|
+
expect(missingLoadingHeading).not.toBeInTheDocument();
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
it("shows/hides the loading indicator", async () => {
|
|
188
|
+
// We haven't tried to fetch anything yet.
|
|
189
|
+
expect(fetchMock.calls()).toHaveLength(0);
|
|
190
|
+
|
|
191
|
+
const { rerender, getByRole, queryByRole } = renderWithProviders(
|
|
192
|
+
<Stats />
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// We should start in the loading state.
|
|
196
|
+
assertLoadingState({ getByRole });
|
|
197
|
+
|
|
198
|
+
// Wait a tick for the statistics to render.
|
|
199
|
+
await new Promise(process.nextTick);
|
|
200
|
+
// Now we've fetched something.
|
|
201
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
202
|
+
|
|
203
|
+
rerender(<Stats />);
|
|
204
|
+
|
|
205
|
+
// We should show our content without the loading state.
|
|
206
|
+
assertNotLoadingState({ queryByRole });
|
|
207
|
+
getByRole("heading", { level: 2, name: ALL_LIBRARIES_HEADING });
|
|
208
|
+
|
|
209
|
+
// We haven't made another call, since the response is cached.
|
|
210
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("doesn't fetch again, because response is cached", async () => {
|
|
214
|
+
const { getByRole, queryByRole } = renderWithProviders(<Stats />);
|
|
215
|
+
|
|
216
|
+
// We should show our content immediately, without entering the loading state.
|
|
217
|
+
assertNotLoadingState({ queryByRole });
|
|
218
|
+
getByRole("heading", { level: 2, name: ALL_LIBRARIES_HEADING });
|
|
219
|
+
|
|
220
|
+
// We never tried to fetch anything because the result is cached.
|
|
221
|
+
expect(fetchMock.calls()).toHaveLength(0);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("show stats for a library, if a library is specified", async () => {
|
|
225
|
+
const { getByRole, queryByRole, getByText } = renderWithProviders(
|
|
226
|
+
<Stats library={sampleLibraryKey} />
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// We should show our content immediately, without entering the loading state.
|
|
230
|
+
assertNotLoadingState({ queryByRole });
|
|
231
|
+
getByRole("heading", {
|
|
232
|
+
level: 2,
|
|
233
|
+
name: `${sampleLibraryName} Dashboard`,
|
|
234
|
+
});
|
|
235
|
+
getByRole("heading", { level: 3, name: statGroupToHeading.patrons });
|
|
236
|
+
getByText("21");
|
|
237
|
+
|
|
238
|
+
// We never tried to fetch anything because the result is cached.
|
|
239
|
+
expect(fetchMock.calls()).toHaveLength(0);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("shows site-wide stats when no library specified", async () => {
|
|
243
|
+
const { getByRole, getByText, queryByRole } = renderWithProviders(
|
|
244
|
+
<Stats />
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
// We should show our content immediately, without entering the loading state.
|
|
248
|
+
assertNotLoadingState({ queryByRole });
|
|
249
|
+
|
|
250
|
+
getByRole("heading", { level: 2, name: ALL_LIBRARIES_HEADING });
|
|
251
|
+
getByRole("heading", {
|
|
252
|
+
level: 3,
|
|
253
|
+
name: "Current Circulation Activity",
|
|
254
|
+
});
|
|
255
|
+
getByText("1.6k");
|
|
256
|
+
|
|
257
|
+
// We never tried to fetch anything because the result is cached.
|
|
258
|
+
expect(fetchMock.calls()).toHaveLength(0);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe("has correct statistics groups", () => {
|
|
263
|
+
it("shows the right groups with a library", () => {
|
|
264
|
+
const { getAllByRole } = renderWithProviders(
|
|
265
|
+
<Stats library={sampleLibraryKey} />
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const groupHeadings = getAllByRole("heading", { level: 3 });
|
|
269
|
+
const expectedHeadings = [
|
|
270
|
+
statGroupToHeading.patrons,
|
|
271
|
+
statGroupToHeading.usageReports,
|
|
272
|
+
statGroupToHeading.collections,
|
|
273
|
+
];
|
|
274
|
+
expect(groupHeadings).toHaveLength(3);
|
|
275
|
+
groupHeadings.forEach((heading, index) => {
|
|
276
|
+
expect(heading).toHaveTextContent(expectedHeadings[index]);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("shows the right groups with/out a library", () => {
|
|
281
|
+
const { getAllByRole } = renderWithProviders(<Stats />);
|
|
282
|
+
|
|
283
|
+
const groupHeadings = getAllByRole("heading", { level: 3 });
|
|
284
|
+
const expectedHeadings = [
|
|
285
|
+
statGroupToHeading.patrons,
|
|
286
|
+
statGroupToHeading.circulations,
|
|
287
|
+
statGroupToHeading.inventory,
|
|
288
|
+
statGroupToHeading.collections,
|
|
289
|
+
];
|
|
290
|
+
expect(groupHeadings).toHaveLength(4);
|
|
291
|
+
groupHeadings.forEach((heading, index) => {
|
|
292
|
+
expect(heading).toHaveTextContent(expectedHeadings[index]);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("shows the correct UI with/out sysadmin role", () => {
|
|
298
|
+
const systemAdmin: AdminRoleData[] = [{ role: "system" }];
|
|
299
|
+
const managerAll: AdminRoleData[] = [{ role: "manager-all" }];
|
|
300
|
+
const librarianAll: AdminRoleData[] = [{ role: "librarian-all" }];
|
|
301
|
+
|
|
302
|
+
const collectionNames = [
|
|
303
|
+
"New BiblioBoard Test",
|
|
304
|
+
"New Bibliotheca Test Collection",
|
|
305
|
+
"Palace Bookshelf",
|
|
306
|
+
"TEST Baker & Taylor",
|
|
307
|
+
"TEST Palace Marketplace",
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
it("tests BarChart component", () => {
|
|
311
|
+
const appConfigSettings: Partial<ConfigurationSettings> = {
|
|
312
|
+
roles: systemAdmin,
|
|
313
|
+
dashboardCollectionsBarChart: { width: 800 },
|
|
314
|
+
};
|
|
315
|
+
const { container, getByRole } = renderWithProviders(
|
|
316
|
+
<Stats library={sampleLibraryKey} />,
|
|
317
|
+
{ appConfigSettings }
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const collectionsHeading = getByRole("heading", {
|
|
321
|
+
level: 3,
|
|
322
|
+
name: statGroupToHeading.collections,
|
|
323
|
+
});
|
|
324
|
+
const collectionsGroup = collectionsHeading.closest(".stat-group");
|
|
325
|
+
const barChartAxisTick = collectionsGroup.querySelectorAll(
|
|
326
|
+
".recharts-cartesian-axis-tick"
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
// We expect the first ticks to be along the y-axis, which
|
|
330
|
+
// should have our collection names.
|
|
331
|
+
collectionNames.forEach((name, index) => {
|
|
332
|
+
expect(barChartAxisTick[index]).toHaveTextContent(name);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Clean up the container after each render.
|
|
336
|
+
document.body.removeChild(container);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("shows collection bar chart for sysadmins, but list for others", () => {
|
|
340
|
+
// We'll use this function to test multiple scenarios.
|
|
341
|
+
const testFor = (expectBarChart: boolean, roles: AdminRoleData[]) => {
|
|
342
|
+
const appConfigSettings: Partial<ConfigurationSettings> = { roles };
|
|
343
|
+
const { container, getByRole } = renderWithProviders(
|
|
344
|
+
<Stats library={sampleLibraryKey} />,
|
|
345
|
+
{ appConfigSettings }
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
const collectionsHeading = getByRole("heading", {
|
|
349
|
+
level: 3,
|
|
350
|
+
name: statGroupToHeading.collections,
|
|
351
|
+
});
|
|
352
|
+
const collectionsGroup = collectionsHeading.closest(".stat-group");
|
|
353
|
+
|
|
354
|
+
if (expectBarChart) {
|
|
355
|
+
collectionsGroup.querySelector(".recharts-responsive-container");
|
|
356
|
+
} else {
|
|
357
|
+
const list = collectionsGroup.querySelector("ul");
|
|
358
|
+
const items = list.querySelectorAll("li");
|
|
359
|
+
expect(items.length).toBe(collectionNames.length);
|
|
360
|
+
|
|
361
|
+
collectionNames.forEach((name: string) => {
|
|
362
|
+
expect(list).toHaveTextContent(name);
|
|
363
|
+
});
|
|
364
|
+
items.forEach((item, index) => {
|
|
365
|
+
expect(item).toHaveTextContent(collectionNames[index]);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Clean up the container after each render.
|
|
370
|
+
document.body.removeChild(container);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// If the feature flag is set, the button should be visible only to sysadmins.
|
|
374
|
+
testFor(true, systemAdmin);
|
|
375
|
+
testFor(false, managerAll);
|
|
376
|
+
testFor(false, librarianAll);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("shows inventory reports only for sysadmins, if sysadmin-only flag set", () => {
|
|
380
|
+
const fakeQuickSightHref = "https://example.com/fakeQS";
|
|
381
|
+
|
|
382
|
+
// We'll use this function to test multiple scenarios.
|
|
383
|
+
const renderFor = (onlySysadmins: boolean, roles: AdminRoleData[]) => {
|
|
384
|
+
const appConfigSettings: Partial<ConfigurationSettings> = {
|
|
385
|
+
featureFlags: { reportsOnlyForSysadmins: onlySysadmins },
|
|
386
|
+
roles,
|
|
387
|
+
quicksightPagePath: fakeQuickSightHref,
|
|
388
|
+
};
|
|
389
|
+
const {
|
|
390
|
+
container,
|
|
391
|
+
getByRole,
|
|
392
|
+
queryByRole,
|
|
393
|
+
queryByText,
|
|
394
|
+
} = renderWithProviders(<Stats library={sampleLibraryKey} />, {
|
|
395
|
+
appConfigSettings,
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// We should always render a Usage reports group when a library is specified.
|
|
399
|
+
getByRole("heading", {
|
|
400
|
+
level: 3,
|
|
401
|
+
name: statGroupToHeading.usageReports,
|
|
402
|
+
});
|
|
403
|
+
const usageReportLink = getByRole("link", { name: /View Usage/i });
|
|
404
|
+
expect(usageReportLink).toHaveAttribute("href", fakeQuickSightHref);
|
|
405
|
+
|
|
406
|
+
const requestButton = queryByRole("button", {
|
|
407
|
+
name: /Request Report/i,
|
|
408
|
+
});
|
|
409
|
+
const blurb = queryByText(
|
|
410
|
+
/These reports provide up-to-date data on both inventory and holds/i
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// The inventory report blurb should be visible only when the button is.
|
|
414
|
+
if (requestButton) {
|
|
415
|
+
expect(blurb).not.toBeNull();
|
|
416
|
+
} else {
|
|
417
|
+
expect(blurb).toBeNull();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Clean up the container after each render.
|
|
421
|
+
document.body.removeChild(container);
|
|
422
|
+
return requestButton;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
// If the feature flag is set, the button should be visible only to sysadmins.
|
|
426
|
+
expect(renderFor(true, systemAdmin)).not.toBeNull();
|
|
427
|
+
expect(renderFor(true, managerAll)).toBeNull();
|
|
428
|
+
expect(renderFor(true, librarianAll)).toBeNull();
|
|
429
|
+
// If the feature flag is false, the button should be visible to all users.
|
|
430
|
+
expect(renderFor(false, systemAdmin)).not.toBeNull();
|
|
431
|
+
expect(renderFor(false, managerAll)).not.toBeNull();
|
|
432
|
+
expect(renderFor(false, librarianAll)).not.toBeNull();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it("shows quicksight link only for sysadmins, if sysadmin-only flag set", () => {
|
|
436
|
+
const fakeQuickSightHref = "https://example.com/fakeQS";
|
|
437
|
+
|
|
438
|
+
// We'll use this function to test multiple scenarios.
|
|
439
|
+
const renderFor = (onlySysadmins: boolean, roles: AdminRoleData[]) => {
|
|
440
|
+
const appConfigSettings: Partial<ConfigurationSettings> = {
|
|
441
|
+
featureFlags: { quicksightOnlyForSysadmins: onlySysadmins },
|
|
442
|
+
roles,
|
|
443
|
+
quicksightPagePath: fakeQuickSightHref,
|
|
444
|
+
};
|
|
445
|
+
const {
|
|
446
|
+
container,
|
|
447
|
+
getByRole,
|
|
448
|
+
queryByRole,
|
|
449
|
+
queryByText,
|
|
450
|
+
} = renderWithProviders(<Stats library={sampleLibraryKey} />, {
|
|
451
|
+
appConfigSettings,
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// We should always render a Usage reports group when a library is specified.
|
|
455
|
+
getByRole("heading", {
|
|
456
|
+
level: 3,
|
|
457
|
+
name: statGroupToHeading.usageReports,
|
|
458
|
+
});
|
|
459
|
+
const usageReportLink = queryByRole("link", { name: /View Usage/i });
|
|
460
|
+
if (usageReportLink) {
|
|
461
|
+
expect(usageReportLink).toHaveAttribute("href", fakeQuickSightHref);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Clean up the container after each render.
|
|
465
|
+
document.body.removeChild(container);
|
|
466
|
+
return usageReportLink;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// If the feature flag is set, the link should be visible only to sysadmins.
|
|
470
|
+
expect(renderFor(true, systemAdmin)).not.toBeNull();
|
|
471
|
+
expect(renderFor(true, managerAll)).toBeNull();
|
|
472
|
+
expect(renderFor(true, librarianAll)).toBeNull();
|
|
473
|
+
// If the feature flag is false, the button should be visible to all users.
|
|
474
|
+
expect(renderFor(false, systemAdmin)).not.toBeNull();
|
|
475
|
+
expect(renderFor(false, managerAll)).not.toBeNull();
|
|
476
|
+
expect(renderFor(false, librarianAll)).not.toBeNull();
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
describe("charting - custom tooltip", () => {
|
|
481
|
+
const defaultLabel = "Collection X";
|
|
482
|
+
const summaryInventory = {
|
|
483
|
+
availableTitles: 7953,
|
|
484
|
+
licensedTitles: 7974,
|
|
485
|
+
meteredLicenseTitles: 7974,
|
|
486
|
+
meteredLicensesAvailable: 75446,
|
|
487
|
+
meteredLicensesOwned: 301541,
|
|
488
|
+
openAccessTitles: 0,
|
|
489
|
+
titles: 7974,
|
|
490
|
+
unlimitedLicenseTitles: 0,
|
|
491
|
+
};
|
|
492
|
+
const perMediumInventory = {
|
|
493
|
+
Audio: {
|
|
494
|
+
availableTitles: 148,
|
|
495
|
+
licensedTitles: 165,
|
|
496
|
+
meteredLicenseTitles: 165,
|
|
497
|
+
meteredLicensesAvailable: 221,
|
|
498
|
+
meteredLicensesOwned: 392,
|
|
499
|
+
openAccessTitles: 0,
|
|
500
|
+
titles: 165,
|
|
501
|
+
unlimitedLicenseTitles: 0,
|
|
502
|
+
},
|
|
503
|
+
Book: {
|
|
504
|
+
availableTitles: 7805,
|
|
505
|
+
licensedTitles: 7809,
|
|
506
|
+
meteredLicenseTitles: 7809,
|
|
507
|
+
meteredLicensesAvailable: 75225,
|
|
508
|
+
meteredLicensesOwned: 301149,
|
|
509
|
+
openAccessTitles: 0,
|
|
510
|
+
titles: 7809,
|
|
511
|
+
unlimitedLicenseTitles: 0,
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
const defaultChartItemWithoutPerMediumInventory = {
|
|
515
|
+
name: defaultLabel,
|
|
516
|
+
...summaryInventory,
|
|
517
|
+
};
|
|
518
|
+
const defaultChartItemWithPerMediumInventory = {
|
|
519
|
+
...defaultChartItemWithoutPerMediumInventory,
|
|
520
|
+
_by_medium: perMediumInventory,
|
|
521
|
+
};
|
|
522
|
+
const defaultPayload = [
|
|
523
|
+
{
|
|
524
|
+
fill: "#606060",
|
|
525
|
+
dataKey: "meteredLicenseTitles",
|
|
526
|
+
name: "Metered License Titles",
|
|
527
|
+
color: "#606060",
|
|
528
|
+
value: 7974,
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
fill: "#404040",
|
|
532
|
+
dataKey: "unlimitedLicenseTitles",
|
|
533
|
+
name: "Unlimited License Titles",
|
|
534
|
+
color: "#404040",
|
|
535
|
+
value: 0,
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
fill: "#202020",
|
|
539
|
+
dataKey: "openAccessTitles",
|
|
540
|
+
name: "Open Access Titles",
|
|
541
|
+
color: "#202020",
|
|
542
|
+
value: 0,
|
|
543
|
+
},
|
|
544
|
+
];
|
|
545
|
+
|
|
546
|
+
const populateTooltipProps = ({
|
|
547
|
+
active = true,
|
|
548
|
+
label = defaultLabel,
|
|
549
|
+
payload = [],
|
|
550
|
+
chartItem = undefined,
|
|
551
|
+
}) => {
|
|
552
|
+
const constructedChartItem = !chartItem
|
|
553
|
+
? chartItem
|
|
554
|
+
: {
|
|
555
|
+
...chartItem,
|
|
556
|
+
name: label,
|
|
557
|
+
};
|
|
558
|
+
const constructedPayload = payload.map((entry) => ({
|
|
559
|
+
...entry,
|
|
560
|
+
payload: constructedChartItem,
|
|
561
|
+
}));
|
|
562
|
+
return {
|
|
563
|
+
active,
|
|
564
|
+
label,
|
|
565
|
+
payload: constructedPayload,
|
|
566
|
+
};
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Helper function to test passing tests for a tooltip
|
|
571
|
+
*
|
|
572
|
+
* @param tooltipProps - passed to the <CustomTooltip /> component
|
|
573
|
+
* @param expectedInventoryItemText - the expected inventory item text content
|
|
574
|
+
*/
|
|
575
|
+
const expectPassingTestsForActiveTooltip = ({
|
|
576
|
+
tooltipProps,
|
|
577
|
+
expectedInventoryItemText,
|
|
578
|
+
}) => {
|
|
579
|
+
const { container, getByRole } = render(
|
|
580
|
+
<CustomTooltip {...tooltipProps} />
|
|
581
|
+
);
|
|
582
|
+
const tooltipContent = container.querySelector(".customTooltip");
|
|
583
|
+
|
|
584
|
+
const detail = tooltipContent.querySelector(".customTooltipDetail");
|
|
585
|
+
const detailChildren = detail.children;
|
|
586
|
+
const heading = getByRole("heading", {
|
|
587
|
+
level: 1,
|
|
588
|
+
name: "Collection X",
|
|
589
|
+
});
|
|
590
|
+
const items = tooltipContent.querySelectorAll("p.customTooltipItem");
|
|
591
|
+
const divider = detail.querySelector("hr");
|
|
592
|
+
|
|
593
|
+
expect(heading).toHaveTextContent("Collection X");
|
|
594
|
+
|
|
595
|
+
// Eight (8) metrics in the following order.
|
|
596
|
+
expect(items).toHaveLength(8);
|
|
597
|
+
// The expected inventory item labels array should be the same length.
|
|
598
|
+
expect(expectedInventoryItemText).toHaveLength(items.length);
|
|
599
|
+
// And the items should contain at least the expected text.
|
|
600
|
+
Array.from(items).forEach((item, index) => {
|
|
601
|
+
expect(item).toHaveTextContent(expectedInventoryItemText[index]);
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
// The heading should be at the top and the divider (`hr`)
|
|
605
|
+
// should be between the third and fourth statistics.
|
|
606
|
+
expect(detailChildren).toHaveLength(10);
|
|
607
|
+
expect(heading).toEqual(detailChildren[0]);
|
|
608
|
+
expect(items[0]).toEqual(detailChildren[1]);
|
|
609
|
+
expect(items[2]).toEqual(detailChildren[3]);
|
|
610
|
+
expect(divider).toEqual(detailChildren[4]);
|
|
611
|
+
expect(items[3]).toEqual(detailChildren[5]);
|
|
612
|
+
expect(items[7]).toEqual(detailChildren[9]);
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
it("should not render when active is false", () => {
|
|
616
|
+
// Recharts sticks some extra props
|
|
617
|
+
const tooltipProps = populateTooltipProps({
|
|
618
|
+
active: false,
|
|
619
|
+
chartItem: defaultChartItemWithPerMediumInventory,
|
|
620
|
+
payload: defaultPayload,
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
const { container } = render(<CustomTooltip {...tooltipProps} />);
|
|
624
|
+
const tooltipContent = container.querySelectorAll(".customTooltip");
|
|
625
|
+
|
|
626
|
+
expect(tooltipContent).toHaveLength(0);
|
|
627
|
+
});
|
|
628
|
+
it("should render when active is true", () => {
|
|
629
|
+
const tooltipProps = populateTooltipProps({
|
|
630
|
+
active: true,
|
|
631
|
+
chartItem: defaultChartItemWithoutPerMediumInventory,
|
|
632
|
+
payload: defaultPayload,
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
const expectedInventoryItemText = [
|
|
636
|
+
"Titles:",
|
|
637
|
+
"Available Titles:",
|
|
638
|
+
"Metered License Titles:",
|
|
639
|
+
"Licensed Titles:",
|
|
640
|
+
"Metered Licenses Available:",
|
|
641
|
+
"Metered Licenses Owned:",
|
|
642
|
+
"Open Access Titles:",
|
|
643
|
+
"Unlimited License Titles:",
|
|
644
|
+
];
|
|
645
|
+
|
|
646
|
+
expectPassingTestsForActiveTooltip({
|
|
647
|
+
tooltipProps,
|
|
648
|
+
expectedInventoryItemText,
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
it("should render without per-medium inventory", () => {
|
|
652
|
+
const tooltipProps = populateTooltipProps({
|
|
653
|
+
active: true,
|
|
654
|
+
chartItem: defaultChartItemWithoutPerMediumInventory,
|
|
655
|
+
payload: defaultPayload,
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
const expectedInventoryItemText = [
|
|
659
|
+
"Titles: 7,974",
|
|
660
|
+
"Available Titles: 7,953",
|
|
661
|
+
"Metered License Titles: 7,974",
|
|
662
|
+
"Licensed Titles: 7,974",
|
|
663
|
+
"Metered Licenses Available: 75,446",
|
|
664
|
+
"Metered Licenses Owned: 301,541",
|
|
665
|
+
"Open Access Titles: 0",
|
|
666
|
+
"Unlimited License Titles: 0",
|
|
667
|
+
];
|
|
668
|
+
|
|
669
|
+
expectPassingTestsForActiveTooltip({
|
|
670
|
+
tooltipProps,
|
|
671
|
+
expectedInventoryItemText,
|
|
672
|
+
});
|
|
673
|
+
});
|
|
674
|
+
it("should render additional detail with per-medium inventory", () => {
|
|
675
|
+
const tooltipProps = populateTooltipProps({
|
|
676
|
+
active: true,
|
|
677
|
+
chartItem: defaultChartItemWithPerMediumInventory,
|
|
678
|
+
payload: defaultPayload,
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
const expectedInventoryItemText = [
|
|
682
|
+
"Titles: 7,974 (Audio: 165, Book: 7,809)",
|
|
683
|
+
"Available Titles: 7,953 (Audio: 148, Book: 7,805)",
|
|
684
|
+
"Metered License Titles: 7,974 (Audio: 165, Book: 7,809)",
|
|
685
|
+
"Licensed Titles: 7,974 (Audio: 165, Book: 7,809)",
|
|
686
|
+
"Metered Licenses Available: 75,446 (Audio: 221, Book: 75,225)",
|
|
687
|
+
"Metered Licenses Owned: 301,541 (Audio: 392, Book: 301,149)",
|
|
688
|
+
"Open Access Titles: 0",
|
|
689
|
+
"Unlimited License Titles: 0",
|
|
690
|
+
];
|
|
691
|
+
|
|
692
|
+
expectPassingTestsForActiveTooltip({
|
|
693
|
+
tooltipProps,
|
|
694
|
+
expectedInventoryItemText,
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
});
|