@thepalaceproject/circulation-admin 1.43.0-post.1 → 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/CLAUDE.md +16 -7
- package/dist/circulation-admin.js +1 -1
- package/eslint.config.mjs +9 -1
- package/jest.config.js +56 -9
- package/package.json +6 -16
- 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/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/Autocomplete.test.tsx +67 -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/BookEditForm.test.tsx +352 -0
- package/tests/jest/components/CatalogServices.test.tsx +63 -0
- package/tests/jest/components/CirculationEventsDownloadForm.test.tsx +41 -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/ConfigPage.test.tsx +58 -0
- package/tests/jest/components/ContextProvider.test.tsx +138 -0
- package/tests/jest/components/CustomListEditor.test.tsx +367 -0
- package/tests/jest/components/CustomListPage.test.tsx +57 -0
- package/tests/jest/components/CustomListSearch.test.tsx +275 -0
- package/tests/jest/components/CustomListsForBook.test.tsx +315 -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/EditableConfigList.test.tsx +8 -2
- 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/InventoryReportRequestModal.test.tsx +16 -42
- package/tests/jest/components/LaneEditor.test.tsx +2 -6
- package/tests/jest/components/LanePage.test.tsx +68 -0
- package/tests/jest/components/LanguageField.test.tsx +40 -0
- package/tests/jest/components/LibraryEditForm.test.tsx +383 -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 +59 -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/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/SelfTestsCategory.test.tsx +200 -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 -8
- package/tests/jest/components/TabContainer.test.tsx +68 -0
- package/tests/jest/components/Timestamp.test.tsx +74 -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/index.test.tsx +50 -0
- package/tests/jest/legacy-setup.ts +13 -0
- package/tests/jest/legacyJsdomEnvironment.js +49 -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/testReporter.js +0 -29
- package/tests/jest/components/AdvancedSearchBuilder.test.tsx +0 -38
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { DndProvider } from "react-dnd";
|
|
5
|
+
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
6
|
+
import AdvancedSearchValueFilter from "../../../src/components/AdvancedSearchValueFilter";
|
|
7
|
+
import {
|
|
8
|
+
fields,
|
|
9
|
+
operators,
|
|
10
|
+
} from "../../../src/components/AdvancedSearchBuilder";
|
|
11
|
+
|
|
12
|
+
describe("AdvancedSearchValueFilter", () => {
|
|
13
|
+
let onMove;
|
|
14
|
+
let onRemove;
|
|
15
|
+
let onSelect;
|
|
16
|
+
let query;
|
|
17
|
+
|
|
18
|
+
const renderFilter = (props = {}) =>
|
|
19
|
+
render(
|
|
20
|
+
<DndProvider backend={HTML5Backend}>
|
|
21
|
+
<AdvancedSearchValueFilter
|
|
22
|
+
query={query}
|
|
23
|
+
onMove={onMove}
|
|
24
|
+
onSelect={onSelect}
|
|
25
|
+
onRemove={onRemove}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
</DndProvider>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
onMove = jest.fn();
|
|
33
|
+
onRemove = jest.fn();
|
|
34
|
+
onSelect = jest.fn();
|
|
35
|
+
|
|
36
|
+
query = {
|
|
37
|
+
id: "91",
|
|
38
|
+
key: "title",
|
|
39
|
+
op: "eq",
|
|
40
|
+
value: "foo",
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should render the field label, operator symbol, and value of the query", () => {
|
|
45
|
+
renderFilter();
|
|
46
|
+
|
|
47
|
+
const expectedField = `${
|
|
48
|
+
fields.find((field) => field.value === "title")?.label
|
|
49
|
+
}`;
|
|
50
|
+
const expectedOperator = `${
|
|
51
|
+
operators.find((op) => op.value === "eq")?.symbol
|
|
52
|
+
}`;
|
|
53
|
+
const filterLabelText = `${expectedField} ${expectedOperator} foo`;
|
|
54
|
+
|
|
55
|
+
expect(screen.getByText(filterLabelText)).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should apply the selected class when selected is true", () => {
|
|
59
|
+
const { container } = renderFilter({ selected: true });
|
|
60
|
+
|
|
61
|
+
expect(
|
|
62
|
+
container.querySelector(".advanced-search-value-filter")
|
|
63
|
+
).toHaveClass("selected");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should not apply the selected class when readOnly is true", () => {
|
|
67
|
+
const { container } = renderFilter({ readOnly: true, selected: true });
|
|
68
|
+
|
|
69
|
+
expect(
|
|
70
|
+
container.querySelector(".advanced-search-value-filter")
|
|
71
|
+
).not.toHaveClass("selected");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should render a remove button", () => {
|
|
75
|
+
renderFilter();
|
|
76
|
+
|
|
77
|
+
const button = screen.getByRole("button");
|
|
78
|
+
|
|
79
|
+
expect(button).toHaveTextContent("×");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should not render a remove button when readOnly is true", () => {
|
|
83
|
+
renderFilter({ readOnly: true });
|
|
84
|
+
|
|
85
|
+
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should call onRemove when the remove button is clicked", async () => {
|
|
89
|
+
const user = userEvent.setup();
|
|
90
|
+
renderFilter();
|
|
91
|
+
|
|
92
|
+
await user.click(screen.getByRole("button"));
|
|
93
|
+
|
|
94
|
+
expect(onRemove).toHaveBeenCalledTimes(1);
|
|
95
|
+
expect(onRemove).toHaveBeenCalledWith("91");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should call onSelect when clicked", async () => {
|
|
99
|
+
const user = userEvent.setup();
|
|
100
|
+
const { container } = renderFilter();
|
|
101
|
+
|
|
102
|
+
await user.click(container.querySelector(".advanced-search-value-filter"));
|
|
103
|
+
|
|
104
|
+
expect(onSelect).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect(onSelect).toHaveBeenCalledWith("91");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should call onSelect when the space bar is depressed", async () => {
|
|
109
|
+
const user = userEvent.setup();
|
|
110
|
+
const { container } = renderFilter();
|
|
111
|
+
|
|
112
|
+
// The filter is a focusable treeitem; focus it and press space, as a
|
|
113
|
+
// keyboard user would.
|
|
114
|
+
const item = container.querySelector(
|
|
115
|
+
".advanced-search-value-filter"
|
|
116
|
+
) as HTMLElement;
|
|
117
|
+
item.focus();
|
|
118
|
+
await user.keyboard(" ");
|
|
119
|
+
|
|
120
|
+
expect(onSelect).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(onSelect).toHaveBeenCalledWith("91");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -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,133 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
import BookDetails from "../../../src/components/BookDetails";
|
|
5
|
+
import { BookData } from "@thepalaceproject/web-opds-client/lib/interfaces";
|
|
6
|
+
|
|
7
|
+
const book: BookData = {
|
|
8
|
+
id: "urn:librarysimplified.org/terms/id/3M%20ID/crrmnr9",
|
|
9
|
+
url: "http://circulation.librarysimplified.org/works/3M/crrmnr9",
|
|
10
|
+
title: "The Mayan Secrets",
|
|
11
|
+
authors: ["Clive Cussler", "Thomas Perry"],
|
|
12
|
+
contributors: ["contributor 1"],
|
|
13
|
+
summary:
|
|
14
|
+
"<b>Sam and Remi Fargo race for treasure—and survival—in this lightning-paced new adventure from #1<i> New York Times</i> bestselling author Clive Cussler.</b><br /><br />Husband-and-wife team Sam and Remi Fargo are in Mexico when they come upon a remarkable discovery—the mummified remainsof a man clutching an ancient sealed pot. Within the pot is a Mayan book larger than any known before.<br /><br />The book contains astonishing information about the Mayans, their cities, and about mankind itself. The secrets are so powerful that some people would do anything to possess them—as the Fargos are about to find out. Many men and women are going to die for that book.",
|
|
15
|
+
imageUrl: "https://dlotdqc6pnwqb.cloudfront.net/3M/crrmnr9/cover.jpg",
|
|
16
|
+
borrowUrl: "borrow url",
|
|
17
|
+
openAccessLinks: [{ url: "secrets.epub", type: "application/epub+zip" }],
|
|
18
|
+
publisher: "Penguin Publishing Group",
|
|
19
|
+
published: "February 29, 2016",
|
|
20
|
+
categories: ["Children", "10-12", "Fiction", "Adventure", "Fantasy"],
|
|
21
|
+
raw: {
|
|
22
|
+
category: [
|
|
23
|
+
{
|
|
24
|
+
$: {
|
|
25
|
+
scheme: { value: "http://schema.org/audience" },
|
|
26
|
+
label: { value: "Children" },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
$: {
|
|
31
|
+
scheme: { value: "http://schema.org/typicalAgeRange" },
|
|
32
|
+
label: { value: "10-12" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
$: {
|
|
37
|
+
scheme: { value: "http://librarysimplified.org/terms/fiction/" },
|
|
38
|
+
label: { value: "Fiction" },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
$: {
|
|
43
|
+
scheme: {
|
|
44
|
+
value: "http://librarysimplified.org/terms/genres/Simplified/",
|
|
45
|
+
},
|
|
46
|
+
label: { value: "Adventure" },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
$: {
|
|
51
|
+
scheme: {
|
|
52
|
+
value: "http://librarysimplified.org/terms/genres/Simplified/",
|
|
53
|
+
},
|
|
54
|
+
label: { value: "Fantasy" },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
"bibframe:distribution": [
|
|
59
|
+
{
|
|
60
|
+
$: {
|
|
61
|
+
"bibframe:ProviderName": {
|
|
62
|
+
value: "Overdrive",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
link: [
|
|
68
|
+
{
|
|
69
|
+
$: {
|
|
70
|
+
rel: { value: "issues" },
|
|
71
|
+
href: { value: "http://example.com/report" },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
$: {
|
|
76
|
+
rel: { value: "http://librarysimplified.org/terms/rel/revoke" },
|
|
77
|
+
href: { value: "http://example.com/revoke" },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
describe("BookDetails", () => {
|
|
85
|
+
const updateBook = jest.fn();
|
|
86
|
+
|
|
87
|
+
it("shows audience and target age", () => {
|
|
88
|
+
const { container } = render(
|
|
89
|
+
<BookDetails book={book} updateBook={updateBook} />
|
|
90
|
+
);
|
|
91
|
+
const audience = container.querySelector(".audience");
|
|
92
|
+
expect(audience).toBeInTheDocument();
|
|
93
|
+
expect(audience).toHaveTextContent("Audience: Children (age 10-12)");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("shows categories", () => {
|
|
97
|
+
const { container } = render(
|
|
98
|
+
<BookDetails book={book} updateBook={updateBook} />
|
|
99
|
+
);
|
|
100
|
+
const categories = container.querySelector(".categories");
|
|
101
|
+
expect(categories).toBeInTheDocument();
|
|
102
|
+
expect(categories).toHaveTextContent("Categories: Adventure, Fantasy");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("doesn't show categories when there aren't any", () => {
|
|
106
|
+
const bookCopy: BookData = {
|
|
107
|
+
...book,
|
|
108
|
+
raw: { category: [], link: [] },
|
|
109
|
+
};
|
|
110
|
+
const { container } = render(
|
|
111
|
+
<BookDetails book={bookCopy} updateBook={updateBook} />
|
|
112
|
+
);
|
|
113
|
+
expect(container.querySelector(".categories")).not.toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("shows distributor", () => {
|
|
117
|
+
const { container } = render(
|
|
118
|
+
<BookDetails book={book} updateBook={updateBook} />
|
|
119
|
+
);
|
|
120
|
+
const distributor = container.querySelector(".distributed-by");
|
|
121
|
+
expect(distributor).toBeInTheDocument();
|
|
122
|
+
expect(distributor).toHaveTextContent("Distributed By: Overdrive");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("doesn't render any circulation link content", () => {
|
|
126
|
+
const { container } = render(
|
|
127
|
+
<BookDetails book={book} updateBook={updateBook} />
|
|
128
|
+
);
|
|
129
|
+
const circulationLinks = container.querySelector(".circulation-links");
|
|
130
|
+
expect(circulationLinks).toBeInTheDocument();
|
|
131
|
+
expect(circulationLinks).toBeEmptyDOMElement();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as PropTypes from "prop-types";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
import buildStore from "../../../src/store";
|
|
6
|
+
import { BookData } from "@thepalaceproject/web-opds-client/lib/interfaces";
|
|
7
|
+
|
|
8
|
+
// BookDetailsTabContainer is a connected TabContainer that mounts every one of its
|
|
9
|
+
// tab panels on render (the metadata editor, classifications, cover, and lists
|
|
10
|
+
// editors), each of which fetches over the network on mount. That machinery is
|
|
11
|
+
// incidental to what BookDetailsContainer composes, so mock it to a marker that
|
|
12
|
+
// echoes the props it receives and renders the book child it is handed.
|
|
13
|
+
jest.mock("../../../src/components/BookDetailsTabContainer", () => ({
|
|
14
|
+
__esModule: true,
|
|
15
|
+
default: (props: any) => (
|
|
16
|
+
<div
|
|
17
|
+
data-testid="book-details-tab-container"
|
|
18
|
+
data-book-url={props.bookUrl}
|
|
19
|
+
data-collection-url={props.collectionUrl}
|
|
20
|
+
data-csrf-token={props.csrfToken}
|
|
21
|
+
data-has-store={String(!!props.store)}
|
|
22
|
+
data-has-library={String(!!props.library)}
|
|
23
|
+
data-has-refresh-catalog={String(!!props.refreshCatalog)}
|
|
24
|
+
>
|
|
25
|
+
{props.children}
|
|
26
|
+
</div>
|
|
27
|
+
),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
import BookDetailsContainer from "../../../src/components/BookDetailsContainer";
|
|
31
|
+
import BookDetails from "../../../src/components/BookDetails";
|
|
32
|
+
|
|
33
|
+
// BookDetailsContainer reads its configuration from the legacy React context that
|
|
34
|
+
// the OPDS web client supplies in production. `renderWithProviders` does not supply
|
|
35
|
+
// the `library` (nor `tab`) keys it reads, so wrap it in a small legacy context
|
|
36
|
+
// provider that hands it everything it needs.
|
|
37
|
+
class LegacyContextProvider extends React.Component<{ context: any }> {
|
|
38
|
+
static childContextTypes = {
|
|
39
|
+
editorStore: PropTypes.object,
|
|
40
|
+
csrfToken: PropTypes.string,
|
|
41
|
+
tab: PropTypes.string,
|
|
42
|
+
library: PropTypes.func,
|
|
43
|
+
admin: PropTypes.object,
|
|
44
|
+
};
|
|
45
|
+
getChildContext() {
|
|
46
|
+
return this.props.context;
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
return this.props.children;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const bookData: BookData = {
|
|
54
|
+
id: "book id",
|
|
55
|
+
url: "book url",
|
|
56
|
+
title: "book title",
|
|
57
|
+
raw: { category: [], link: [] },
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe("BookDetailsContainer", () => {
|
|
61
|
+
let store;
|
|
62
|
+
let context;
|
|
63
|
+
let refreshCatalog;
|
|
64
|
+
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
store = buildStore();
|
|
67
|
+
refreshCatalog = jest.fn();
|
|
68
|
+
context = {
|
|
69
|
+
editorStore: store,
|
|
70
|
+
csrfToken: "token",
|
|
71
|
+
library: jest.fn(),
|
|
72
|
+
admin: { isLibraryManager: () => true },
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const renderContainer = () =>
|
|
77
|
+
render(
|
|
78
|
+
<LegacyContextProvider context={context}>
|
|
79
|
+
<BookDetailsContainer
|
|
80
|
+
book={bookData}
|
|
81
|
+
bookUrl="book url"
|
|
82
|
+
collectionUrl="collection url"
|
|
83
|
+
refreshCatalog={refreshCatalog}
|
|
84
|
+
>
|
|
85
|
+
<BookDetails book={bookData} updateBook={jest.fn()} />
|
|
86
|
+
</BookDetailsContainer>
|
|
87
|
+
</LegacyContextProvider>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
it("renders BookDetails with its child's props", () => {
|
|
91
|
+
renderContainer();
|
|
92
|
+
// The container recreates the real BookDetails from the child element's props,
|
|
93
|
+
// so the book it was handed shows up (its title is rendered as the heading).
|
|
94
|
+
expect(
|
|
95
|
+
screen.getByRole("heading", { name: "book title" })
|
|
96
|
+
).toBeInTheDocument();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("shows a tab container with initial tab", () => {
|
|
100
|
+
renderContainer();
|
|
101
|
+
const tabContainer = screen.getByTestId("book-details-tab-container");
|
|
102
|
+
expect(tabContainer).toBeInTheDocument();
|
|
103
|
+
expect(tabContainer).toHaveAttribute("data-book-url", "book url");
|
|
104
|
+
expect(tabContainer).toHaveAttribute(
|
|
105
|
+
"data-collection-url",
|
|
106
|
+
"collection url"
|
|
107
|
+
);
|
|
108
|
+
expect(tabContainer).toHaveAttribute("data-csrf-token", "token");
|
|
109
|
+
// The library function, redux store, and refreshCatalog callback are forwarded
|
|
110
|
+
// from context/props; they are not serializable to the DOM, so assert they were
|
|
111
|
+
// passed through.
|
|
112
|
+
expect(tabContainer).toHaveAttribute("data-has-store", "true");
|
|
113
|
+
expect(tabContainer).toHaveAttribute("data-has-library", "true");
|
|
114
|
+
expect(tabContainer).toHaveAttribute("data-has-refresh-catalog", "true");
|
|
115
|
+
});
|
|
116
|
+
});
|