@thepalaceproject/circulation-admin 1.39.0 → 1.40.0
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.css +1 -1
- package/dist/circulation-admin.js +1 -1
- package/package.json +2 -2
- package/tests/jest/components/Collections.test.tsx +220 -0
- package/tests/jest/components/DiscoveryServices.test.tsx +545 -0
- package/tests/jest/components/EditableConfigList.test.tsx +399 -0
- package/tests/jest/components/IndividualAdmins.test.tsx +390 -0
package/package.json
CHANGED
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"fetch-mock-jest": "^1.5.1",
|
|
107
107
|
"fetch-ponyfill": "^7.1.0",
|
|
108
108
|
"file-loader": "^6.2.0",
|
|
109
|
-
"follow-redirects": "^1.
|
|
109
|
+
"follow-redirects": "^1.16.0",
|
|
110
110
|
"husky": "^4.3.0",
|
|
111
111
|
"jest": "^29.3.1",
|
|
112
112
|
"jest-environment-jsdom": "^29.3.1",
|
|
@@ -154,5 +154,5 @@
|
|
|
154
154
|
"*.{js,jsx,ts,tsx,css,md}": "prettier --write",
|
|
155
155
|
"*.{js,css,md}": "prettier --write"
|
|
156
156
|
},
|
|
157
|
-
"version": "1.
|
|
157
|
+
"version": "1.40.0"
|
|
158
158
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { fireEvent } from "@testing-library/react";
|
|
3
|
+
import { Collections } from "../../../src/components/Collections";
|
|
4
|
+
import renderWithContext from "../testUtils/renderWithContext";
|
|
5
|
+
import {
|
|
6
|
+
CollectionsData,
|
|
7
|
+
ConfigurationSettings,
|
|
8
|
+
} from "../../../src/interfaces";
|
|
9
|
+
import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
|
|
10
|
+
|
|
11
|
+
// NB: This adds tests to the already existing tests in:
|
|
12
|
+
// - `src/components/__tests__/Collections-test.tsx`.
|
|
13
|
+
//
|
|
14
|
+
// Those tests should eventually be migrated here and
|
|
15
|
+
// adapted to the Jest/React Testing Library paradigm.
|
|
16
|
+
|
|
17
|
+
describe("Collections - associated library disclosure", () => {
|
|
18
|
+
// ── Shared fixtures ───────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
const allLibraries = [
|
|
21
|
+
{ short_name: "gamma", name: "Gamma Library", uuid: "uuid-gamma" },
|
|
22
|
+
{ short_name: "alpha", name: "Alpha Library", uuid: "uuid-alpha" },
|
|
23
|
+
{ short_name: "beta", name: "Beta Library", uuid: "uuid-beta" },
|
|
24
|
+
{ short_name: "delta", name: "Delta Library" }, // no uuid
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const sysAdminConfig: Partial<ConfigurationSettings> = {
|
|
28
|
+
csrfToken: "",
|
|
29
|
+
featureFlags: defaultFeatureFlags,
|
|
30
|
+
roles: [{ role: "system" }],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const renderCollections = (data: Partial<CollectionsData>) =>
|
|
34
|
+
renderWithContext(
|
|
35
|
+
<Collections
|
|
36
|
+
data={
|
|
37
|
+
{
|
|
38
|
+
collections: [],
|
|
39
|
+
protocols: [],
|
|
40
|
+
allLibraries,
|
|
41
|
+
...data,
|
|
42
|
+
} as CollectionsData
|
|
43
|
+
}
|
|
44
|
+
fetchData={jest.fn()}
|
|
45
|
+
editItem={jest.fn().mockResolvedValue(undefined)}
|
|
46
|
+
deleteItem={jest.fn().mockResolvedValue(undefined)}
|
|
47
|
+
registerLibrary={jest.fn().mockResolvedValue(undefined)}
|
|
48
|
+
importCollection={jest.fn().mockResolvedValue(undefined)}
|
|
49
|
+
csrfToken="token"
|
|
50
|
+
isFetching={false}
|
|
51
|
+
/>,
|
|
52
|
+
sysAdminConfig
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// ── Toggle visibility ─────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
it("shows no toggle for a collection without a libraries field", () => {
|
|
58
|
+
const { container } = renderCollections({
|
|
59
|
+
collections: [{ id: 1, protocol: "p", name: "My Collection" } as any],
|
|
60
|
+
});
|
|
61
|
+
expect(container.querySelector(".association-toggle")).toBeNull();
|
|
62
|
+
expect(container.querySelector(".library-count")).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("shows a disabled toggle and 'no libraries' for a collection with an empty libraries array", () => {
|
|
66
|
+
const { container } = renderCollections({
|
|
67
|
+
collections: [
|
|
68
|
+
{ id: 1, protocol: "p", name: "My Collection", libraries: [] } as any,
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
const toggle = container.querySelector<HTMLButtonElement>(
|
|
72
|
+
".association-toggle"
|
|
73
|
+
);
|
|
74
|
+
expect(toggle).not.toBeNull();
|
|
75
|
+
expect(toggle.disabled).toBe(true);
|
|
76
|
+
expect(container.querySelector(".library-count").textContent).toBe(
|
|
77
|
+
" (no libraries)"
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("shows '1 library' for a collection with one associated library", () => {
|
|
82
|
+
const { container } = renderCollections({
|
|
83
|
+
collections: [
|
|
84
|
+
{
|
|
85
|
+
id: 1,
|
|
86
|
+
protocol: "p",
|
|
87
|
+
name: "My Collection",
|
|
88
|
+
libraries: [{ short_name: "alpha" }],
|
|
89
|
+
} as any,
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
const toggle = container.querySelector<HTMLButtonElement>(
|
|
93
|
+
".association-toggle"
|
|
94
|
+
);
|
|
95
|
+
expect(toggle.disabled).toBe(false);
|
|
96
|
+
expect(container.querySelector(".library-count").textContent).toBe(
|
|
97
|
+
" (1 library)"
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("shows 'N libraries' for a collection with multiple associated libraries", () => {
|
|
102
|
+
const { container } = renderCollections({
|
|
103
|
+
collections: [
|
|
104
|
+
{
|
|
105
|
+
id: 1,
|
|
106
|
+
protocol: "p",
|
|
107
|
+
name: "My Collection",
|
|
108
|
+
libraries: [
|
|
109
|
+
{ short_name: "alpha" },
|
|
110
|
+
{ short_name: "beta" },
|
|
111
|
+
{ short_name: "gamma" },
|
|
112
|
+
],
|
|
113
|
+
} as any,
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
expect(container.querySelector(".library-count").textContent).toBe(
|
|
117
|
+
" (3 libraries)"
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// ── Expand / collapse ─────────────────────────────────────────────────────
|
|
122
|
+
|
|
123
|
+
it("expands the library list on toggle click and collapses on a second click", () => {
|
|
124
|
+
const { container } = renderCollections({
|
|
125
|
+
collections: [
|
|
126
|
+
{
|
|
127
|
+
id: 1,
|
|
128
|
+
protocol: "p",
|
|
129
|
+
name: "My Collection",
|
|
130
|
+
libraries: [{ short_name: "alpha" }, { short_name: "beta" }],
|
|
131
|
+
} as any,
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
const toggle = container.querySelector(".association-toggle");
|
|
135
|
+
expect(container.querySelector(".associated-items")).toBeNull();
|
|
136
|
+
fireEvent.click(toggle);
|
|
137
|
+
expect(container.querySelector(".associated-items")).not.toBeNull();
|
|
138
|
+
fireEvent.click(toggle);
|
|
139
|
+
expect(container.querySelector(".associated-items")).toBeNull();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// ── allLibraries injection from mapStateToProps ───────────────────────────
|
|
143
|
+
|
|
144
|
+
it("resolves library display names from allLibraries", () => {
|
|
145
|
+
const { container } = renderCollections({
|
|
146
|
+
collections: [
|
|
147
|
+
{
|
|
148
|
+
id: 1,
|
|
149
|
+
protocol: "p",
|
|
150
|
+
name: "My Collection",
|
|
151
|
+
libraries: [{ short_name: "alpha" }, { short_name: "beta" }],
|
|
152
|
+
} as any,
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
fireEvent.click(container.querySelector(".association-toggle"));
|
|
156
|
+
|
|
157
|
+
const items = container.querySelectorAll(".associated-items li");
|
|
158
|
+
// Sorted alphabetically: Alpha, Beta
|
|
159
|
+
expect(items[0].textContent).toBe("Alpha Library");
|
|
160
|
+
expect(items[1].textContent).toBe("Beta Library");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("links a library name to its config page when a uuid is available", () => {
|
|
164
|
+
const { container } = renderCollections({
|
|
165
|
+
collections: [
|
|
166
|
+
{
|
|
167
|
+
id: 1,
|
|
168
|
+
protocol: "p",
|
|
169
|
+
name: "My Collection",
|
|
170
|
+
libraries: [{ short_name: "alpha" }],
|
|
171
|
+
} as any,
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
fireEvent.click(container.querySelector(".association-toggle"));
|
|
175
|
+
|
|
176
|
+
const link = container.querySelector<HTMLAnchorElement>(
|
|
177
|
+
".associated-items a"
|
|
178
|
+
);
|
|
179
|
+
expect(link).not.toBeNull();
|
|
180
|
+
expect(link.textContent).toBe("Alpha Library");
|
|
181
|
+
expect(link.href).toContain("/admin/web/config/libraries/edit/uuid-alpha");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("renders a library without a uuid as plain text", () => {
|
|
185
|
+
const { container } = renderCollections({
|
|
186
|
+
collections: [
|
|
187
|
+
{
|
|
188
|
+
id: 1,
|
|
189
|
+
protocol: "p",
|
|
190
|
+
name: "My Collection",
|
|
191
|
+
libraries: [{ short_name: "delta" }],
|
|
192
|
+
} as any,
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
fireEvent.click(container.querySelector(".association-toggle"));
|
|
196
|
+
|
|
197
|
+
expect(container.querySelector(".associated-items a")).toBeNull();
|
|
198
|
+
expect(container.querySelector(".associated-items li").textContent).toBe(
|
|
199
|
+
"Delta Library"
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("falls back to short_name when the library is not in allLibraries", () => {
|
|
204
|
+
const { container } = renderCollections({
|
|
205
|
+
collections: [
|
|
206
|
+
{
|
|
207
|
+
id: 1,
|
|
208
|
+
protocol: "p",
|
|
209
|
+
name: "My Collection",
|
|
210
|
+
libraries: [{ short_name: "unknown" }],
|
|
211
|
+
} as any,
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
fireEvent.click(container.querySelector(".association-toggle"));
|
|
215
|
+
|
|
216
|
+
expect(container.querySelector(".associated-items li").textContent).toBe(
|
|
217
|
+
"unknown"
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
});
|