@thepalaceproject/circulation-admin 1.43.0-post.10 → 1.43.0-post.11
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 +1 -1
- package/tests/jest/components/Announcement.test.tsx +76 -0
- package/tests/jest/components/Autocomplete.test.tsx +67 -0
- package/tests/jest/components/BookDetailsEditor.test.tsx +275 -0
- package/tests/jest/components/BookEditForm.test.tsx +352 -0
- package/tests/jest/components/Classifications.test.tsx +166 -0
- package/tests/jest/components/ClassificationsTable.test.tsx +57 -0
- package/tests/jest/components/ColorPicker.test.tsx +58 -0
- package/tests/jest/components/ComplaintForm.test.tsx +171 -0
- package/tests/jest/components/Complaints.test.tsx +259 -0
- package/tests/jest/components/ContextProvider.test.tsx +138 -0
- package/tests/jest/components/CustomListEditor.test.tsx +367 -0
- package/tests/jest/components/CustomListsForBook.test.tsx +315 -0
- package/tests/jest/components/DiagnosticsServiceTabs.test.tsx +141 -0
- package/tests/jest/components/DiagnosticsServiceType.test.tsx +75 -0
- package/tests/jest/components/LibraryEditForm.test.tsx +383 -0
- package/tests/jest/components/LibraryRegistrationForm.test.tsx +203 -0
- package/tests/jest/components/PatronAuthServices.test.tsx +114 -0
- package/tests/jest/components/ResetAdobeId.test.tsx +302 -0
- package/tests/jest/components/SitewideAnnouncements.test.tsx +134 -0
- package/tests/jest/components/TroubleshootingCategoryPage.test.tsx +69 -0
- package/tests/jest/components/TroubleshootingPage.test.tsx +94 -0
package/package.json
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import Announcement from "../../../src/components/Announcement";
|
|
6
|
+
|
|
7
|
+
describe("Announcement", () => {
|
|
8
|
+
let stubDelete: jest.Mock;
|
|
9
|
+
let stubEdit: jest.Mock;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
stubDelete = jest.fn();
|
|
13
|
+
stubEdit = jest.fn();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const renderAnnouncement = (
|
|
17
|
+
overrides: Partial<React.ComponentProps<typeof Announcement>> = {}
|
|
18
|
+
) =>
|
|
19
|
+
render(
|
|
20
|
+
<Announcement
|
|
21
|
+
content="test"
|
|
22
|
+
start="2020-05-12"
|
|
23
|
+
finish="2020-05-28"
|
|
24
|
+
id="1"
|
|
25
|
+
delete={stubDelete}
|
|
26
|
+
edit={stubEdit}
|
|
27
|
+
{...overrides}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
it("renders the content and dates", () => {
|
|
32
|
+
const { container } = renderAnnouncement();
|
|
33
|
+
|
|
34
|
+
expect(
|
|
35
|
+
container.querySelector("section.announcement-info")
|
|
36
|
+
).toBeInTheDocument();
|
|
37
|
+
expect(container.querySelector(".dates")).toHaveTextContent(
|
|
38
|
+
"05/12/2020 – 05/28/2020"
|
|
39
|
+
);
|
|
40
|
+
expect(screen.getByText("test")).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("renders an edit button", async () => {
|
|
44
|
+
const user = userEvent.setup();
|
|
45
|
+
renderAnnouncement();
|
|
46
|
+
|
|
47
|
+
const editButton = screen.getByRole("button", { name: "Edit" });
|
|
48
|
+
await user.click(editButton);
|
|
49
|
+
|
|
50
|
+
expect(stubEdit).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(stubEdit).toHaveBeenCalledWith("1");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("renders a delete button", async () => {
|
|
55
|
+
const user = userEvent.setup();
|
|
56
|
+
renderAnnouncement();
|
|
57
|
+
|
|
58
|
+
const deleteButton = screen.getByRole("button", { name: "Delete" });
|
|
59
|
+
await user.click(deleteButton);
|
|
60
|
+
|
|
61
|
+
expect(stubDelete).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(stubDelete).toHaveBeenCalledWith("1");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("formats dates", () => {
|
|
66
|
+
// The dates are stored as year-month-day but displayed as month/day/year.
|
|
67
|
+
const { container } = renderAnnouncement({
|
|
68
|
+
start: "2020-03-14",
|
|
69
|
+
finish: "2021-12-25",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(container.querySelector(".dates")).toHaveTextContent(
|
|
73
|
+
"03/14/2020 – 12/25/2021"
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import Autocomplete from "../../../src/components/Autocomplete";
|
|
6
|
+
|
|
7
|
+
describe("Autocomplete", () => {
|
|
8
|
+
const autocompleteValues = ["a", "b", "c"];
|
|
9
|
+
|
|
10
|
+
const renderAutocomplete = (ref?: React.Ref<Autocomplete>) =>
|
|
11
|
+
render(
|
|
12
|
+
<Autocomplete
|
|
13
|
+
ref={ref}
|
|
14
|
+
autocompleteValues={autocompleteValues}
|
|
15
|
+
disabled={false}
|
|
16
|
+
name="test"
|
|
17
|
+
label="Test"
|
|
18
|
+
value="b"
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
describe("rendering", () => {
|
|
23
|
+
it("shows input", () => {
|
|
24
|
+
renderAutocomplete();
|
|
25
|
+
|
|
26
|
+
expect(screen.getByText("Test")).toBeInTheDocument();
|
|
27
|
+
// An <input> with a `list` attribute has the implicit role "combobox".
|
|
28
|
+
const input = screen.getByRole("combobox");
|
|
29
|
+
expect(input).toHaveAttribute("type", "text");
|
|
30
|
+
expect(input).not.toBeDisabled();
|
|
31
|
+
expect(input).toHaveAttribute("name", "test");
|
|
32
|
+
expect(input).toHaveValue("b");
|
|
33
|
+
expect(input).toHaveAttribute("list", "test-autocomplete-list");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("shows autocomplete list", () => {
|
|
37
|
+
const { container } = renderAutocomplete();
|
|
38
|
+
|
|
39
|
+
const list = container.querySelector("datalist#test-autocomplete-list");
|
|
40
|
+
expect(list).toBeInTheDocument();
|
|
41
|
+
const options = list.querySelectorAll("option");
|
|
42
|
+
expect(options).toHaveLength(3);
|
|
43
|
+
expect(options[0]).toHaveAttribute("value", "a");
|
|
44
|
+
expect(options[1]).toHaveAttribute("value", "b");
|
|
45
|
+
expect(options[2]).toHaveAttribute("value", "c");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("behavior", () => {
|
|
50
|
+
it("returns value", async () => {
|
|
51
|
+
const user = userEvent.setup();
|
|
52
|
+
// getValue() is the imperative API ProtocolFormField/LanguageField call
|
|
53
|
+
// via a ref in production, so exercise it through a real ref here.
|
|
54
|
+
const ref = React.createRef<Autocomplete>();
|
|
55
|
+
renderAutocomplete(ref);
|
|
56
|
+
|
|
57
|
+
expect(ref.current.getValue()).toBe("b");
|
|
58
|
+
|
|
59
|
+
const input = screen.getByRole("combobox");
|
|
60
|
+
await user.clear(input);
|
|
61
|
+
await user.type(input, "test value");
|
|
62
|
+
|
|
63
|
+
expect(input).toHaveValue("test value");
|
|
64
|
+
expect(ref.current.getValue()).toBe("test value");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
import { renderWithProviders } from "../testUtils/withProviders";
|
|
5
|
+
import buildStore from "../../../src/store";
|
|
6
|
+
import {
|
|
7
|
+
PER_LIBRARY_SUPPRESS_REL,
|
|
8
|
+
PER_LIBRARY_UNSUPPRESS_REL,
|
|
9
|
+
} from "../../../src/features/book/bookEditorSlice";
|
|
10
|
+
|
|
11
|
+
// BookEditForm is a heavy child; the legacy enzyme tests only shallow-rendered
|
|
12
|
+
// it and asserted the props it received. Mock it to a marker that surfaces those
|
|
13
|
+
// props as data attributes so the same facts can be asserted against real DOM.
|
|
14
|
+
jest.mock("../../../src/components/BookEditForm", () => ({
|
|
15
|
+
__esModule: true,
|
|
16
|
+
default: (props: any) => (
|
|
17
|
+
<div
|
|
18
|
+
data-testid="book-edit-form"
|
|
19
|
+
data-title={props.title}
|
|
20
|
+
data-roles={JSON.stringify(props.roles ?? null)}
|
|
21
|
+
data-media={JSON.stringify(props.media ?? null)}
|
|
22
|
+
data-languages={JSON.stringify(props.languages ?? null)}
|
|
23
|
+
/>
|
|
24
|
+
),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
import BookDetailsEditor, {
|
|
28
|
+
BookDetailsEditor as UnconnectedBookDetailsEditor,
|
|
29
|
+
} from "../../../src/components/BookDetailsEditor";
|
|
30
|
+
|
|
31
|
+
// The connected component derives bookData from OPDS parsing of a fetch, which is
|
|
32
|
+
// impractical to synthesize; render the unconnected class with injected props for
|
|
33
|
+
// the render-behavior tests (as the legacy enzyme tests did), and cover the
|
|
34
|
+
// connect wiring with the dedicated connected test below.
|
|
35
|
+
const renderEditor = (overrides: Record<string, unknown> = {}) => {
|
|
36
|
+
const props = {
|
|
37
|
+
bookUrl: "url",
|
|
38
|
+
csrfToken: "token",
|
|
39
|
+
canSuppress: true,
|
|
40
|
+
bookAdminUrl: "admin url",
|
|
41
|
+
bookData: undefined,
|
|
42
|
+
roles: undefined,
|
|
43
|
+
media: undefined,
|
|
44
|
+
languages: undefined,
|
|
45
|
+
isFetching: false,
|
|
46
|
+
fetchError: undefined,
|
|
47
|
+
editError: undefined,
|
|
48
|
+
refreshCatalog: jest.fn().mockResolvedValue(undefined),
|
|
49
|
+
fetchBookData: jest.fn(),
|
|
50
|
+
fetchRoles: jest.fn(),
|
|
51
|
+
fetchMedia: jest.fn(),
|
|
52
|
+
fetchLanguages: jest.fn(),
|
|
53
|
+
postBookData: jest.fn(),
|
|
54
|
+
suppressBook: jest.fn(),
|
|
55
|
+
unsuppressBook: jest.fn(),
|
|
56
|
+
...overrides,
|
|
57
|
+
};
|
|
58
|
+
const result = render(<UnconnectedBookDetailsEditor {...(props as any)} />);
|
|
59
|
+
return { props, ...result };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
describe("BookDetailsEditor", () => {
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
jest.restoreAllMocks();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("loads admin book url, roles, languages, and media on mount", () => {
|
|
68
|
+
const { props } = renderEditor({ bookUrl: "works/1234" });
|
|
69
|
+
|
|
70
|
+
expect(props.fetchBookData).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(props.fetchBookData).toHaveBeenCalledWith("admin/works/1234");
|
|
72
|
+
expect(props.fetchRoles).toHaveBeenCalledTimes(1);
|
|
73
|
+
expect(props.fetchMedia).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(props.fetchLanguages).toHaveBeenCalledTimes(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("loads admin book url when given a new book url", () => {
|
|
78
|
+
const { props, rerender } = renderEditor({ bookUrl: "works/1234" });
|
|
79
|
+
rerender(
|
|
80
|
+
<UnconnectedBookDetailsEditor {...(props as any)} bookUrl="works/5555" />
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(props.fetchBookData).toHaveBeenCalledTimes(2);
|
|
84
|
+
expect((props.fetchBookData as jest.Mock).mock.calls[1][0]).toBe(
|
|
85
|
+
"admin/works/5555"
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("shows the title", () => {
|
|
90
|
+
renderEditor({ bookData: { id: "id", title: "title" } });
|
|
91
|
+
expect(
|
|
92
|
+
screen.getByRole("heading", { level: 2, name: "title" })
|
|
93
|
+
).toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("shows a Hide button for a per-library suppress link", () => {
|
|
97
|
+
renderEditor({
|
|
98
|
+
bookData: {
|
|
99
|
+
id: "id",
|
|
100
|
+
title: "title",
|
|
101
|
+
suppressPerLibraryLink: { href: "href", rel: PER_LIBRARY_SUPPRESS_REL },
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
expect(screen.getByRole("button", { name: "Hide" })).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("shows a Restore button in the visibility banner for a per-library unsuppress link", () => {
|
|
108
|
+
const { container } = renderEditor({
|
|
109
|
+
bookData: {
|
|
110
|
+
id: "id",
|
|
111
|
+
title: "title",
|
|
112
|
+
unsuppressPerLibraryLink: {
|
|
113
|
+
href: "href",
|
|
114
|
+
rel: PER_LIBRARY_UNSUPPRESS_REL,
|
|
115
|
+
},
|
|
116
|
+
visibilityStatus: "manually-suppressed",
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
expect(container.querySelector(".visibility-status")).toBeInTheDocument();
|
|
120
|
+
expect(screen.getByRole("button", { name: "Restore" })).toBeInTheDocument();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("shows the restore banner when an unsuppress link exists without a visibilityStatus", () => {
|
|
124
|
+
const { container } = renderEditor({
|
|
125
|
+
bookData: {
|
|
126
|
+
id: "id",
|
|
127
|
+
title: "title",
|
|
128
|
+
unsuppressPerLibraryLink: {
|
|
129
|
+
href: "href",
|
|
130
|
+
rel: PER_LIBRARY_UNSUPPRESS_REL,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
expect(
|
|
135
|
+
container.querySelector(".visibility-status-manually-suppressed")
|
|
136
|
+
).toBeInTheDocument();
|
|
137
|
+
expect(screen.getByRole("button", { name: "Restore" })).toBeInTheDocument();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("shows the manually-suppressed banner without a restore button when there is no unsuppress link", () => {
|
|
141
|
+
const { container } = renderEditor({
|
|
142
|
+
bookData: {
|
|
143
|
+
id: "id",
|
|
144
|
+
title: "title",
|
|
145
|
+
visibilityStatus: "manually-suppressed",
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const banner = container.querySelector(
|
|
149
|
+
".visibility-status-manually-suppressed"
|
|
150
|
+
);
|
|
151
|
+
expect(banner).toBeInTheDocument();
|
|
152
|
+
expect(banner.textContent).toContain(
|
|
153
|
+
"manually hidden by a library staff member"
|
|
154
|
+
);
|
|
155
|
+
expect(
|
|
156
|
+
screen.queryByRole("button", { name: "Restore" })
|
|
157
|
+
).not.toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("shows the policy-filtered banner without a restore button", () => {
|
|
161
|
+
const { container } = renderEditor({
|
|
162
|
+
bookData: {
|
|
163
|
+
id: "id",
|
|
164
|
+
title: "title",
|
|
165
|
+
visibilityStatus: "policy-filtered",
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
const banner = container.querySelector(
|
|
169
|
+
".visibility-status-policy-filtered"
|
|
170
|
+
);
|
|
171
|
+
expect(banner).toBeInTheDocument();
|
|
172
|
+
expect(banner.textContent).toContain("library content filtering");
|
|
173
|
+
expect(
|
|
174
|
+
screen.queryByRole("button", { name: "Restore" })
|
|
175
|
+
).not.toBeInTheDocument();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("shows a Refresh Metadata button for a refresh link", () => {
|
|
179
|
+
renderEditor({
|
|
180
|
+
bookData: {
|
|
181
|
+
id: "id",
|
|
182
|
+
title: "title",
|
|
183
|
+
refreshLink: {
|
|
184
|
+
href: "href",
|
|
185
|
+
rel: "http://librarysimplified/terms/rel/refresh",
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
expect(
|
|
190
|
+
screen.getByRole("button", { name: "Refresh Metadata" })
|
|
191
|
+
).toBeInTheDocument();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("shows a fetch error message and no edit form", () => {
|
|
195
|
+
renderEditor({
|
|
196
|
+
bookData: { id: "id", title: "title" },
|
|
197
|
+
fetchError: { status: 500, response: "response", url: "" },
|
|
198
|
+
});
|
|
199
|
+
expect(screen.getByText(/Error: response/)).toBeInTheDocument();
|
|
200
|
+
expect(screen.queryByTestId("book-edit-form")).not.toBeInTheDocument();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("shows an edit error message together with the edit form", () => {
|
|
204
|
+
renderEditor({
|
|
205
|
+
bookData: {
|
|
206
|
+
id: "id",
|
|
207
|
+
title: "title",
|
|
208
|
+
editLink: {
|
|
209
|
+
href: "href",
|
|
210
|
+
rel: "http://librarysimplified.org/terms/rel/edit",
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
editError: { status: 500, response: "response", url: "" },
|
|
214
|
+
});
|
|
215
|
+
expect(screen.getByTestId("book-edit-form")).toBeInTheDocument();
|
|
216
|
+
expect(screen.getByText(/Error: response/)).toBeInTheDocument();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("shows the book edit form with roles, media, and languages", () => {
|
|
220
|
+
const roles = { aut: "Author", nar: "Narrator" };
|
|
221
|
+
const media = {
|
|
222
|
+
"http://schema.org/AudioObject": "Audio",
|
|
223
|
+
"http://schema.org/Book": "Book",
|
|
224
|
+
};
|
|
225
|
+
const languages = { eng: ["English"], spa: ["Spanish", "Castilian"] };
|
|
226
|
+
renderEditor({
|
|
227
|
+
bookData: {
|
|
228
|
+
id: "id",
|
|
229
|
+
title: "title",
|
|
230
|
+
editLink: {
|
|
231
|
+
href: "href",
|
|
232
|
+
rel: "http://librarysimplified.org/terms/rel/edit",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
roles,
|
|
236
|
+
media,
|
|
237
|
+
languages,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const form = screen.getByTestId("book-edit-form");
|
|
241
|
+
expect(form).toHaveAttribute("data-title", "title");
|
|
242
|
+
expect(JSON.parse(form.getAttribute("data-roles"))).toStrictEqual(roles);
|
|
243
|
+
expect(JSON.parse(form.getAttribute("data-media"))).toStrictEqual(media);
|
|
244
|
+
expect(JSON.parse(form.getAttribute("data-languages"))).toStrictEqual(
|
|
245
|
+
languages
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("wires up the connected default export (mapStateToProps / mapDispatchToProps)", async () => {
|
|
250
|
+
// Stub fetch so mounting the connected panel does not hit the network. The
|
|
251
|
+
// roles/media/languages endpoints return JSON; the book endpoint returns a
|
|
252
|
+
// non-OPDS body so getBookData rejects (handled) and surfaces a fetch error.
|
|
253
|
+
jest
|
|
254
|
+
.spyOn(globalThis, "fetch")
|
|
255
|
+
.mockImplementation(async () => new Response("{}", { status: 200 }));
|
|
256
|
+
|
|
257
|
+
const store = buildStore();
|
|
258
|
+
renderWithProviders(
|
|
259
|
+
<BookDetailsEditor
|
|
260
|
+
store={store}
|
|
261
|
+
bookUrl="works/1234"
|
|
262
|
+
csrfToken="token"
|
|
263
|
+
canSuppress={true}
|
|
264
|
+
refreshCatalog={jest.fn().mockResolvedValue(undefined)}
|
|
265
|
+
/>,
|
|
266
|
+
{ reduxProviderProps: { store } }
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// getBookData's OPDS parse fails on the non-OPDS body, so mapStateToProps
|
|
270
|
+
// feeds the resulting fetch error back in and the panel renders an error.
|
|
271
|
+
expect(
|
|
272
|
+
await screen.findByText(/Failed to parse OPDS data/)
|
|
273
|
+
).toBeInTheDocument();
|
|
274
|
+
});
|
|
275
|
+
});
|