@thepalaceproject/circulation-admin 1.43.0-post.2 → 1.43.0-post.20
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/CLAUDE.md +26 -12
- package/README.md +11 -5
- package/dist/circulation-admin.js +1 -1
- package/jest.config.js +17 -18
- package/package.json +4 -22
- package/tests/jest/actions.test.ts +962 -0
- package/tests/jest/components/AccountPage.test.tsx +41 -0
- package/tests/jest/components/AdvancedSearchBooleanFilter.test.tsx +231 -0
- package/tests/jest/components/AdvancedSearchBuilder.test.tsx +93 -20
- package/tests/jest/components/AdvancedSearchFilter.test.tsx +142 -0
- package/tests/jest/components/AdvancedSearchFilterInput.test.tsx +212 -0
- package/tests/jest/components/AdvancedSearchFilterViewer.test.tsx +52 -0
- package/tests/jest/components/AdvancedSearchValueFilter.test.tsx +123 -0
- package/tests/jest/components/Announcement.test.tsx +76 -0
- package/tests/jest/components/AnnouncementForm.test.tsx +229 -0
- package/tests/jest/components/AnnouncementsSection.test.tsx +146 -0
- package/tests/jest/components/Autocomplete.test.tsx +67 -0
- package/tests/jest/components/BookCoverEditor.test.tsx +393 -0
- package/tests/jest/components/BookDetails.test.tsx +133 -0
- package/tests/jest/components/BookDetailsContainer.test.tsx +116 -0
- package/tests/jest/components/BookDetailsEditor.test.tsx +275 -0
- package/tests/jest/components/BookDetailsTabContainer.test.tsx +237 -0
- package/tests/jest/components/BookEditForm.test.tsx +352 -0
- package/tests/jest/components/BookEditor.test.tsx +20 -21
- package/tests/jest/components/CatalogPage.test.tsx +158 -0
- package/tests/jest/components/CatalogServices.test.tsx +100 -0
- package/tests/jest/components/ChangePasswordForm.test.tsx +163 -0
- package/tests/jest/components/CirculationEventsDownloadForm.test.tsx +41 -0
- package/tests/jest/components/Classifications.test.tsx +166 -0
- package/tests/jest/components/ClassificationsForm.test.tsx +458 -0
- package/tests/jest/components/ClassificationsTable.test.tsx +57 -0
- package/tests/jest/components/Collections.test.tsx +335 -7
- 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/ConfigPage.test.tsx +58 -0
- package/tests/jest/components/ConfigTabContainer.test.tsx +196 -0
- package/tests/jest/components/ContextProvider.test.tsx +138 -0
- package/tests/jest/components/Contributors.test.tsx +157 -0
- package/tests/jest/components/CustomListEditor.test.tsx +367 -0
- package/tests/jest/components/CustomListEntriesEditor.test.tsx +1240 -0
- package/tests/jest/components/CustomListPage.test.tsx +57 -0
- package/tests/jest/components/CustomListSearch.test.tsx +275 -0
- package/tests/jest/components/CustomLists.test.tsx +621 -4
- package/tests/jest/components/CustomListsForBook.test.tsx +353 -0
- package/tests/jest/components/CustomListsSidebar.test.tsx +251 -0
- package/tests/jest/components/DashboardPage.test.tsx +76 -0
- package/tests/jest/components/DebugAuthentication.test.tsx +1 -5
- package/tests/jest/components/DiagnosticsServiceTabs.test.tsx +141 -0
- package/tests/jest/components/DiagnosticsServiceType.test.tsx +75 -0
- package/tests/jest/components/DiagnosticsTabContainer.test.tsx +147 -0
- package/tests/jest/components/DiscoveryServices.test.tsx +154 -7
- package/tests/jest/components/EditableConfigList.test.tsx +606 -9
- package/tests/jest/components/EditableInput.test.tsx +250 -1
- package/tests/jest/components/EditorField.test.tsx +95 -0
- package/tests/jest/components/EntryPointsContainer.test.tsx +97 -0
- package/tests/jest/components/EntryPointsTabs.test.tsx +88 -0
- package/tests/jest/components/ErrorMessage.test.tsx +97 -0
- package/tests/jest/components/Footer.test.tsx +141 -0
- package/tests/jest/components/GenreForm.test.tsx +152 -0
- package/tests/jest/components/Header.test.tsx +421 -0
- package/tests/jest/components/IndividualAdminEditForm.test.tsx +506 -1
- package/tests/jest/components/IndividualAdmins.test.tsx +124 -8
- package/tests/jest/components/InputList.test.tsx +493 -0
- package/tests/jest/components/InventoryReportRequestModal.test.tsx +16 -42
- package/tests/jest/components/Lane.test.tsx +132 -10
- package/tests/jest/components/LaneCustomListsEditor.test.tsx +450 -0
- package/tests/jest/components/LaneEditor.test.tsx +377 -13
- package/tests/jest/components/LanePage.test.tsx +68 -0
- package/tests/jest/components/Lanes.test.tsx +446 -0
- package/tests/jest/components/LanesSidebar.test.tsx +621 -0
- package/tests/jest/components/LanguageField.test.tsx +40 -0
- package/tests/jest/components/Libraries.test.tsx +48 -0
- package/tests/jest/components/LibraryEditForm.test.tsx +383 -0
- package/tests/jest/components/LibraryRegistration.test.tsx +354 -0
- package/tests/jest/components/LibraryRegistrationForm.test.tsx +203 -0
- package/tests/jest/components/LoadButton.test.tsx +49 -0
- package/tests/jest/components/ManagePatrons.test.tsx +73 -0
- package/tests/jest/components/ManagePatronsForm.test.tsx +180 -0
- package/tests/jest/components/ManagePatronsTabContainer.test.tsx +143 -0
- package/tests/jest/components/MetadataServices.test.tsx +95 -0
- package/tests/jest/components/NeighborhoodAnalyticsForm.test.tsx +167 -0
- package/tests/jest/components/PairedMenus.test.tsx +220 -0
- package/tests/jest/components/PatronAuthServices.test.tsx +114 -0
- package/tests/jest/components/PatronBlockingRulesEditor.test.tsx +3 -1
- package/tests/jest/components/PatronInfo.test.tsx +54 -0
- package/tests/jest/components/ProtocolFormField.test.tsx +443 -7
- package/tests/jest/components/ResetAdobeId.test.tsx +302 -0
- package/tests/jest/components/SaveButton.test.tsx +47 -0
- package/tests/jest/components/SelfTestResult.test.tsx +164 -0
- package/tests/jest/components/SelfTests.test.tsx +601 -0
- package/tests/jest/components/SelfTestsCategory.test.tsx +200 -0
- package/tests/jest/components/SelfTestsTabContainer.test.tsx +216 -0
- package/tests/jest/components/ServiceEditForm.test.tsx +1092 -0
- package/tests/jest/components/ServiceWithRegistrationsEditForm.test.tsx +110 -0
- package/tests/jest/components/SetupPage.test.tsx +41 -0
- package/tests/jest/components/SingleStatListItem.test.tsx +62 -0
- package/tests/jest/components/SitewideAnnouncements.test.tsx +134 -0
- package/tests/jest/components/Stats.test.tsx +4 -15
- package/tests/jest/components/TabContainer.test.tsx +68 -0
- package/tests/jest/components/TextWithEditMode.test.tsx +218 -0
- package/tests/jest/components/Timestamp.test.tsx +74 -0
- package/tests/jest/components/ToolTip.test.tsx +46 -0
- package/tests/jest/components/TroubleshootingCategoryPage.test.tsx +69 -0
- package/tests/jest/components/TroubleshootingPage.test.tsx +94 -0
- package/tests/jest/components/TroubleshootingTabContainer.test.tsx +68 -0
- package/tests/jest/components/UpdatingLoader.test.tsx +36 -0
- package/tests/jest/components/WelcomePage.test.tsx +43 -0
- package/tests/jest/components/WithEditButton.test.tsx +55 -0
- package/tests/jest/components/WithRemoveButton.test.tsx +95 -0
- package/tests/jest/editorAdapter.test.ts +245 -0
- package/tests/jest/features/book.test.ts +75 -80
- package/tests/jest/fixtures/classificationsData.ts +45 -0
- package/tests/jest/fixtures/genreData.ts +811 -0
- package/tests/jest/index.test.tsx +50 -0
- package/tests/jest/models/Admin.test.ts +206 -0
- package/tests/jest/reducers/bookCoverPreview.test.ts +81 -0
- package/tests/jest/reducers/classifications.test.ts +161 -0
- package/tests/jest/reducers/collections.test.ts +96 -0
- package/tests/jest/reducers/complaints.test.ts +166 -0
- package/tests/jest/reducers/createFetchEditReducer.test.ts +220 -0
- package/tests/jest/reducers/createRegisterLibraryReducer.test.ts +51 -0
- package/tests/jest/reducers/customListDetails.test.ts +120 -0
- package/tests/jest/reducers/customListEditor.test.ts +2823 -0
- package/tests/jest/reducers/managePatrons.test.ts +71 -0
- package/tests/jest/testUtils/formDataShim.test.ts +135 -0
- package/tests/jest/testUtils/formDataShim.ts +112 -0
- package/tests/jest/utils/sharedFunctions.test.ts +121 -0
- package/tsconfig.json +3 -4
- package/.nycrc.json +0 -8
- package/testReporter.js +0 -29
- package/tests/jest/README.md +0 -6
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { screen } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
import Libraries from "../../../src/components/Libraries";
|
|
5
|
+
import { renderWithProviders } from "../testUtils/withProviders";
|
|
6
|
+
import buildStore from "../../../src/store";
|
|
7
|
+
|
|
8
|
+
// The connected default export is what the app mounts, so render that rather
|
|
9
|
+
// than the bare component: it is the only thing that exercises Libraries'
|
|
10
|
+
// mapStateToProps/mapDispatchToProps.
|
|
11
|
+
describe("Libraries - connected wiring", () => {
|
|
12
|
+
afterEach(() => jest.restoreAllMocks());
|
|
13
|
+
|
|
14
|
+
it("wires mapStateToProps/mapDispatchToProps and renders the fetched list", async () => {
|
|
15
|
+
jest.spyOn(globalThis, "fetch").mockImplementation(
|
|
16
|
+
async () =>
|
|
17
|
+
new Response(
|
|
18
|
+
JSON.stringify({
|
|
19
|
+
libraries: [
|
|
20
|
+
{
|
|
21
|
+
uuid: "uuid-nypl",
|
|
22
|
+
short_name: "nypl",
|
|
23
|
+
name: "New York Public Library",
|
|
24
|
+
settings: {},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
}),
|
|
28
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
29
|
+
)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
renderWithProviders(<Libraries csrfToken="token" />, {
|
|
33
|
+
reduxProviderProps: { store: buildStore() },
|
|
34
|
+
appConfigSettings: { roles: [{ role: "system" }] },
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// The library and its edit control appear once the on-mount fetch resolves
|
|
38
|
+
// and mapStateToProps feeds the fetched data back in as props.
|
|
39
|
+
expect(
|
|
40
|
+
await screen.findByText("New York Public Library")
|
|
41
|
+
).toBeInTheDocument();
|
|
42
|
+
const editLink = await screen.findByRole("link", { name: /edit/i });
|
|
43
|
+
expect(editLink).toHaveAttribute(
|
|
44
|
+
"href",
|
|
45
|
+
"/admin/web/config/libraries/edit/uuid-nypl"
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { installFormDataShim } from "../testUtils/formDataShim";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
import LibraryEditForm, {
|
|
7
|
+
LibraryEditFormProps,
|
|
8
|
+
} from "../../../src/components/LibraryEditForm";
|
|
9
|
+
import {
|
|
10
|
+
LibrariesData,
|
|
11
|
+
LibraryData,
|
|
12
|
+
LibrarySettingField,
|
|
13
|
+
} from "../../../src/interfaces";
|
|
14
|
+
installFormDataShim();
|
|
15
|
+
|
|
16
|
+
describe("LibraryEditForm", () => {
|
|
17
|
+
const libraryData = {
|
|
18
|
+
uuid: "uuid",
|
|
19
|
+
name: "name",
|
|
20
|
+
short_name: "short_name",
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
settings: {
|
|
23
|
+
"privacy-policy": "http://privacy",
|
|
24
|
+
"copyright": "http://copyright",
|
|
25
|
+
"featured_lane_size": "20",
|
|
26
|
+
"announcements": "[{\"content\": \"Announcement #1\", \"start\": \"2020-06-15\", \"finish\": \"2020-08-15\", \"id\": \"1\"}]"
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const settingFields = [
|
|
31
|
+
{ key: "name", label: "Name", category: "Basic Information", level: 3 },
|
|
32
|
+
{
|
|
33
|
+
key: "short_name",
|
|
34
|
+
label: "Short Name",
|
|
35
|
+
category: "Basic Information",
|
|
36
|
+
level: 3,
|
|
37
|
+
},
|
|
38
|
+
{ key: "privacy-policy", label: "Privacy Policy", category: "Links" },
|
|
39
|
+
{ key: "copyright", label: "Copyright", category: "Links" },
|
|
40
|
+
{ key: "logo", label: "Logo", category: "Client Interface Customization" },
|
|
41
|
+
{ key: "large_collections", label: "Languages", category: "Languages" },
|
|
42
|
+
{
|
|
43
|
+
key: "featured_lane_size",
|
|
44
|
+
label: "Maximum number of books in the 'featured' lanes",
|
|
45
|
+
category: "Lanes & Filters",
|
|
46
|
+
type: "number",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "service_area",
|
|
50
|
+
label: "Service Area",
|
|
51
|
+
category: "Geographic Areas",
|
|
52
|
+
type: "list",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: "announcements",
|
|
56
|
+
label: "Announcements",
|
|
57
|
+
category: "Announcements",
|
|
58
|
+
type: "announcements",
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
type Overrides = Partial<LibraryEditFormProps> & {
|
|
63
|
+
fetchError?: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const makeData = (
|
|
67
|
+
settings: LibrarySettingField[] = settingFields as LibrarySettingField[]
|
|
68
|
+
): LibrariesData => ({
|
|
69
|
+
libraries: [libraryData as LibraryData],
|
|
70
|
+
settings,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const makeProps = (overrides: Overrides = {}): LibraryEditFormProps => ({
|
|
74
|
+
data: makeData(),
|
|
75
|
+
disabled: false,
|
|
76
|
+
save: jest.fn(),
|
|
77
|
+
urlBase: "url base",
|
|
78
|
+
listDataKey: "libraries",
|
|
79
|
+
adminLevel: 3,
|
|
80
|
+
...(overrides as LibraryEditFormProps),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const renderForm = (overrides: Overrides = {}) => {
|
|
84
|
+
const props = makeProps(overrides);
|
|
85
|
+
const result = render(<LibraryEditForm {...props} />);
|
|
86
|
+
const rerender = (nextOverrides: Overrides) =>
|
|
87
|
+
result.rerender(<LibraryEditForm {...makeProps(nextOverrides)} />);
|
|
88
|
+
return { ...result, rerender, props };
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const inputByName = (container: HTMLElement, name: string) =>
|
|
92
|
+
container.querySelector<HTMLInputElement>(`input[name="${name}"]`);
|
|
93
|
+
|
|
94
|
+
const panelByName = (container: HTMLElement, name: string) =>
|
|
95
|
+
Array.from(container.querySelectorAll<HTMLElement>(".panel")).find(
|
|
96
|
+
(panel) =>
|
|
97
|
+
panel.querySelector(".panel-heading")?.textContent?.startsWith(name) ??
|
|
98
|
+
false
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
describe("rendering", () => {
|
|
102
|
+
it("renders hidden uuid", () => {
|
|
103
|
+
const { container, rerender } = renderForm();
|
|
104
|
+
expect(inputByName(container, "uuid")).toHaveValue("");
|
|
105
|
+
|
|
106
|
+
rerender({ item: libraryData as LibraryData });
|
|
107
|
+
expect(inputByName(container, "uuid")).toHaveValue("uuid");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("renders name", () => {
|
|
111
|
+
const { container, rerender } = renderForm();
|
|
112
|
+
expect(inputByName(container, "name")).toHaveValue("");
|
|
113
|
+
|
|
114
|
+
rerender({ item: libraryData as LibraryData });
|
|
115
|
+
expect(inputByName(container, "name")).toHaveValue("name");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("renders short name", () => {
|
|
119
|
+
const { container, rerender } = renderForm();
|
|
120
|
+
expect(inputByName(container, "short_name")).toHaveValue("");
|
|
121
|
+
|
|
122
|
+
rerender({ item: libraryData as LibraryData });
|
|
123
|
+
expect(inputByName(container, "short_name")).toHaveValue("short_name");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("renders settings", () => {
|
|
127
|
+
const { container, rerender } = renderForm();
|
|
128
|
+
expect(inputByName(container, "privacy-policy")).toHaveValue("");
|
|
129
|
+
expect(inputByName(container, "copyright")).toHaveValue("");
|
|
130
|
+
|
|
131
|
+
rerender({ item: libraryData as LibraryData });
|
|
132
|
+
expect(inputByName(container, "privacy-policy")).toHaveValue(
|
|
133
|
+
"http://privacy"
|
|
134
|
+
);
|
|
135
|
+
expect(inputByName(container, "copyright")).toHaveValue(
|
|
136
|
+
"http://copyright"
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("does not render settings with the skip attribute", () => {
|
|
141
|
+
const skip = { key: "skip", label: "Skip this setting!", skip: true };
|
|
142
|
+
const { container } = renderForm({
|
|
143
|
+
data: makeData([...settingFields, skip]),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// A normal setting still renders, but the skipped one does not.
|
|
147
|
+
expect(inputByName(container, "privacy-policy")).toBeInTheDocument();
|
|
148
|
+
expect(inputByName(container, "skip")).not.toBeInTheDocument();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("renders the PairedMenus component", () => {
|
|
152
|
+
const inputListSetting = {
|
|
153
|
+
key: "inputList",
|
|
154
|
+
label: "Input List",
|
|
155
|
+
paired: "dropdown",
|
|
156
|
+
options: [],
|
|
157
|
+
default: ["opt_1"],
|
|
158
|
+
level: 2,
|
|
159
|
+
};
|
|
160
|
+
const dropdownSetting = {
|
|
161
|
+
key: "dropdown",
|
|
162
|
+
label: "Dropdown List",
|
|
163
|
+
options: [
|
|
164
|
+
{ key: "opt_1", label: "Option 1" },
|
|
165
|
+
{ key: "opt_2", label: "Option 2" },
|
|
166
|
+
],
|
|
167
|
+
type: "select",
|
|
168
|
+
level: 2,
|
|
169
|
+
};
|
|
170
|
+
const { container, rerender } = renderForm({
|
|
171
|
+
data: makeData([inputListSetting, dropdownSetting]),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// These settings render inside a collapsed (aria-hidden) panel, so query
|
|
175
|
+
// the DOM directly rather than via accessible-role queries.
|
|
176
|
+
const pairedMenus = container.querySelector<HTMLElement>(".paired-menus");
|
|
177
|
+
expect(pairedMenus).toBeInTheDocument();
|
|
178
|
+
|
|
179
|
+
// The dropdown inside the paired menus is filtered to the option that is
|
|
180
|
+
// present in the input list (opt_1).
|
|
181
|
+
const dropdown = pairedMenus.querySelector<HTMLSelectElement>(
|
|
182
|
+
'select[name="dropdown"]'
|
|
183
|
+
);
|
|
184
|
+
const options = dropdown.querySelectorAll("option");
|
|
185
|
+
expect(options).toHaveLength(1);
|
|
186
|
+
expect(options[0]).toHaveValue("opt_1");
|
|
187
|
+
|
|
188
|
+
// At admin level 3 the setting is editable, so the input list's remove
|
|
189
|
+
// button is enabled.
|
|
190
|
+
expect(pairedMenus.querySelector(".remove-btn")).toBeEnabled();
|
|
191
|
+
|
|
192
|
+
// A librarian (level 1) is not authorized, so the paired menus become
|
|
193
|
+
// read-only and the remove button is disabled.
|
|
194
|
+
rerender({
|
|
195
|
+
data: makeData([inputListSetting, dropdownSetting]),
|
|
196
|
+
adminLevel: 1,
|
|
197
|
+
});
|
|
198
|
+
const readOnlyPaired =
|
|
199
|
+
container.querySelector<HTMLElement>(".paired-menus");
|
|
200
|
+
expect(readOnlyPaired.querySelector(".remove-btn")).toBeDisabled();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("renders the InputList component", () => {
|
|
204
|
+
const inputListSetting = {
|
|
205
|
+
key: "inputList",
|
|
206
|
+
label: "Input List",
|
|
207
|
+
options: [],
|
|
208
|
+
default: ["opt_1"],
|
|
209
|
+
level: 2,
|
|
210
|
+
menuOptions: [],
|
|
211
|
+
type: "menu",
|
|
212
|
+
};
|
|
213
|
+
const { container, rerender } = renderForm({
|
|
214
|
+
data: makeData([inputListSetting]),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// This setting renders inside a collapsed (aria-hidden) panel, so query
|
|
218
|
+
// the DOM directly rather than via accessible-role queries.
|
|
219
|
+
expect(container.querySelector(".input-list")).toBeInTheDocument();
|
|
220
|
+
// The existing list item is editable and removable for an authorized admin.
|
|
221
|
+
expect(inputByName(container, "inputList_opt_1")).not.toHaveAttribute(
|
|
222
|
+
"readonly"
|
|
223
|
+
);
|
|
224
|
+
expect(container.querySelector(".remove-btn")).toBeEnabled();
|
|
225
|
+
|
|
226
|
+
// A librarian (level 1) is not authorized: the item becomes read-only and
|
|
227
|
+
// the remove button is disabled.
|
|
228
|
+
rerender({ data: makeData([inputListSetting]), adminLevel: 1 });
|
|
229
|
+
expect(inputByName(container, "inputList_opt_1")).toHaveAttribute(
|
|
230
|
+
"readonly"
|
|
231
|
+
);
|
|
232
|
+
expect(container.querySelector(".remove-btn")).toBeDisabled();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("renders the Announcements component", () => {
|
|
236
|
+
const { container } = renderForm({ item: libraryData as LibraryData });
|
|
237
|
+
|
|
238
|
+
// The announcements section renders the library's saved announcement.
|
|
239
|
+
expect(
|
|
240
|
+
container.querySelector(".announcements-section")
|
|
241
|
+
).toBeInTheDocument();
|
|
242
|
+
expect(screen.getByText("Scheduled Announcements:")).toBeInTheDocument();
|
|
243
|
+
expect(screen.getByText(/Announcement #1/)).toBeInTheDocument();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("subdivides fields", () => {
|
|
247
|
+
const { container } = renderForm();
|
|
248
|
+
|
|
249
|
+
const panels = container.querySelectorAll(".panel");
|
|
250
|
+
expect(panels).toHaveLength(7);
|
|
251
|
+
|
|
252
|
+
// The first panel is the (required) Basic Information panel; the rest are
|
|
253
|
+
// optional.
|
|
254
|
+
const basic = panels[0].querySelector(".panel-heading");
|
|
255
|
+
expect(basic).toHaveTextContent("Basic Information");
|
|
256
|
+
Array.from(panels)
|
|
257
|
+
.slice(1)
|
|
258
|
+
.forEach((panel) => {
|
|
259
|
+
expect(panel.querySelector(".panel-heading")).toHaveTextContent(
|
|
260
|
+
"(Optional)"
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// The Links panel holds two settings.
|
|
265
|
+
const links = panelByName(container, "Links");
|
|
266
|
+
expect(inputByName(links, "privacy-policy")).toBeInTheDocument();
|
|
267
|
+
expect(inputByName(links, "copyright")).toBeInTheDocument();
|
|
268
|
+
expect(
|
|
269
|
+
panelByName(container, "Languages").querySelectorAll("input")
|
|
270
|
+
).toHaveLength(1);
|
|
271
|
+
expect(
|
|
272
|
+
panelByName(
|
|
273
|
+
container,
|
|
274
|
+
"Client Interface Customization"
|
|
275
|
+
).querySelectorAll("input")
|
|
276
|
+
).toHaveLength(1);
|
|
277
|
+
|
|
278
|
+
// Geographic Areas is a list input, which renders an add-list-item span
|
|
279
|
+
// and button.
|
|
280
|
+
const geographic = panelByName(container, "Geographic Areas");
|
|
281
|
+
expect(geographic.querySelectorAll(".add-list-item")).toHaveLength(2);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("has a save button", () => {
|
|
285
|
+
renderForm();
|
|
286
|
+
expect(
|
|
287
|
+
screen.getByRole("button", { name: "Submit" })
|
|
288
|
+
).toBeInTheDocument();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("disables some fields if the user isn't a system admin", () => {
|
|
292
|
+
const sysAdminOnly = {
|
|
293
|
+
key: "level-3",
|
|
294
|
+
label: "Level 3",
|
|
295
|
+
category: "Basic Information",
|
|
296
|
+
level: 3,
|
|
297
|
+
};
|
|
298
|
+
const sysAdminAndLibMgr = {
|
|
299
|
+
key: "level-2",
|
|
300
|
+
label: "Level 2",
|
|
301
|
+
category: "Basic Information",
|
|
302
|
+
level: 2,
|
|
303
|
+
};
|
|
304
|
+
const data = makeData([
|
|
305
|
+
...settingFields,
|
|
306
|
+
sysAdminOnly,
|
|
307
|
+
sysAdminAndLibMgr,
|
|
308
|
+
]);
|
|
309
|
+
const { container, rerender } = renderForm({ data, adminLevel: 3 });
|
|
310
|
+
|
|
311
|
+
// System admin: everything is editable.
|
|
312
|
+
["name", "short_name", "level-3", "level-2"].forEach((name) =>
|
|
313
|
+
expect(inputByName(container, name)).not.toHaveAttribute("readonly")
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
// Library manager (level 2): level-3 (and the always-restricted name/short
|
|
317
|
+
// name) are read-only, level-2 is editable.
|
|
318
|
+
rerender({ data, adminLevel: 2 });
|
|
319
|
+
["name", "short_name", "level-3"].forEach((name) =>
|
|
320
|
+
expect(inputByName(container, name)).toHaveAttribute("readonly")
|
|
321
|
+
);
|
|
322
|
+
expect(inputByName(container, "level-2")).not.toHaveAttribute("readonly");
|
|
323
|
+
|
|
324
|
+
// Librarian (level 1): level-2 is now read-only too.
|
|
325
|
+
rerender({ data, adminLevel: 1 });
|
|
326
|
+
["name", "short_name", "level-3", "level-2"].forEach((name) =>
|
|
327
|
+
expect(inputByName(container, name)).toHaveAttribute("readonly")
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("behavior", () => {
|
|
333
|
+
it("calls save when the save button is clicked", async () => {
|
|
334
|
+
const user = userEvent.setup();
|
|
335
|
+
const save = jest.fn();
|
|
336
|
+
renderForm({ save });
|
|
337
|
+
|
|
338
|
+
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
339
|
+
|
|
340
|
+
expect(save).toHaveBeenCalledTimes(1);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("submits data", async () => {
|
|
344
|
+
const user = userEvent.setup();
|
|
345
|
+
const save = jest.fn();
|
|
346
|
+
renderForm({ save, item: libraryData as LibraryData });
|
|
347
|
+
|
|
348
|
+
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
349
|
+
|
|
350
|
+
expect(save).toHaveBeenCalledTimes(1);
|
|
351
|
+
const formData = save.mock.calls[0][0];
|
|
352
|
+
expect(formData.get("uuid")).toBe("uuid");
|
|
353
|
+
expect(formData.get("name")).toBe("name");
|
|
354
|
+
expect(formData.get("short_name")).toBe("short_name");
|
|
355
|
+
expect(formData.get("privacy-policy")).toBe("http://privacy");
|
|
356
|
+
expect(formData.get("copyright")).toBe("http://copyright");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("clears the form when a response comes back without an error", async () => {
|
|
360
|
+
const user = userEvent.setup();
|
|
361
|
+
const { container, rerender } = renderForm();
|
|
362
|
+
|
|
363
|
+
await user.type(inputByName(container, "name"), "new name");
|
|
364
|
+
expect(inputByName(container, "name")).toHaveValue("new name");
|
|
365
|
+
|
|
366
|
+
// A successful response (responseBody with no error) clears the form.
|
|
367
|
+
rerender({ responseBody: "new library" });
|
|
368
|
+
expect(inputByName(container, "name")).toHaveValue("");
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("doesn't clear the form if there's an error message", async () => {
|
|
372
|
+
const user = userEvent.setup();
|
|
373
|
+
const { container, rerender } = renderForm();
|
|
374
|
+
|
|
375
|
+
await user.type(inputByName(container, "name"), "new name");
|
|
376
|
+
expect(inputByName(container, "name")).toHaveValue("new name");
|
|
377
|
+
|
|
378
|
+
// An error response leaves the entered value in place.
|
|
379
|
+
rerender({ fetchError: "ERROR" });
|
|
380
|
+
expect(inputByName(container, "name")).toHaveValue("new name");
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
});
|