@thepalaceproject/circulation-admin 1.43.0-post.11 → 1.43.0-post.15
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/BookCoverEditor.test.tsx +393 -0
- package/tests/jest/components/CatalogPage.test.tsx +158 -0
- package/tests/jest/components/ClassificationsForm.test.tsx +458 -0
- package/tests/jest/components/Collections.test.tsx +335 -7
- package/tests/jest/components/Contributors.test.tsx +157 -0
- package/tests/jest/components/CustomListEntriesEditor.test.tsx +1240 -0
- package/tests/jest/components/CustomLists.test.tsx +621 -4
- package/tests/jest/components/EditableConfigList.test.tsx +598 -7
- package/tests/jest/components/EditorField.test.tsx +95 -0
- package/tests/jest/components/GenreForm.test.tsx +152 -0
- package/tests/jest/components/InputList.test.tsx +493 -0
- package/tests/jest/components/Lane.test.tsx +130 -7
- package/tests/jest/components/LaneCustomListsEditor.test.tsx +450 -0
- package/tests/jest/components/LaneEditor.test.tsx +367 -2
- package/tests/jest/components/Lanes.test.tsx +446 -0
- package/tests/jest/components/LanesSidebar.test.tsx +621 -0
- package/tests/jest/components/PairedMenus.test.tsx +220 -0
- package/tests/jest/components/ProtocolFormField.test.tsx +443 -7
- package/tests/jest/components/SelfTests.test.tsx +601 -0
- package/tests/jest/components/ServiceEditForm.test.tsx +1092 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { RichUtils } from "draft-js";
|
|
4
|
+
|
|
5
|
+
import EditorField from "../../../src/components/EditorField";
|
|
6
|
+
|
|
7
|
+
describe("EditorField", () => {
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.restoreAllMocks();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("renders the three inline-style buttons and toggles the matching style on mouse-down", () => {
|
|
13
|
+
// There is no DOM-observable effect of toggling an inline style over a
|
|
14
|
+
// collapsed (unfocused) selection, so we drive the real mouse-down interaction
|
|
15
|
+
// and observe the actual `RichUtils.toggleInlineStyle` call the button triggers.
|
|
16
|
+
const toggleSpy = jest.spyOn(RichUtils, "toggleInlineStyle");
|
|
17
|
+
|
|
18
|
+
const { container } = render(
|
|
19
|
+
<EditorField content="This is a summary." disabled={false} />
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const buttons = Array.from(container.querySelectorAll("button"));
|
|
23
|
+
expect(buttons).toHaveLength(3);
|
|
24
|
+
const [bold, italic, underline] = buttons;
|
|
25
|
+
|
|
26
|
+
expect(bold).toHaveTextContent("Bold");
|
|
27
|
+
expect(bold.querySelector("b")).toBeInTheDocument();
|
|
28
|
+
expect(italic).toHaveTextContent("Italic");
|
|
29
|
+
expect(italic.querySelector("i")).toBeInTheDocument();
|
|
30
|
+
expect(underline).toHaveTextContent("Underline");
|
|
31
|
+
expect(underline.querySelector("u")).toBeInTheDocument();
|
|
32
|
+
|
|
33
|
+
expect(toggleSpy).not.toHaveBeenCalled();
|
|
34
|
+
|
|
35
|
+
fireEvent.mouseDown(bold);
|
|
36
|
+
expect(toggleSpy).toHaveBeenCalledTimes(1);
|
|
37
|
+
expect(toggleSpy.mock.calls[0][1]).toBe("BOLD");
|
|
38
|
+
|
|
39
|
+
fireEvent.mouseDown(italic);
|
|
40
|
+
expect(toggleSpy).toHaveBeenCalledTimes(2);
|
|
41
|
+
expect(toggleSpy.mock.calls[1][1]).toBe("ITALIC");
|
|
42
|
+
|
|
43
|
+
fireEvent.mouseDown(underline);
|
|
44
|
+
expect(toggleSpy).toHaveBeenCalledTimes(3);
|
|
45
|
+
expect(toggleSpy.mock.calls[2][1]).toBe("UNDERLINE");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("exposes the current content as HTML through getValue()", () => {
|
|
49
|
+
// `getValue()` is EditorField's real imperative API (BookEditForm reads it via a
|
|
50
|
+
// ref), so mirror that: render with a ref and call it.
|
|
51
|
+
const ref = React.createRef<EditorField>();
|
|
52
|
+
render(
|
|
53
|
+
<EditorField ref={ref} content="This is a summary." disabled={false} />
|
|
54
|
+
);
|
|
55
|
+
expect(ref.current?.getValue()).toBe("<p>This is a summary.</p>");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("falls back to the default content when the content is empty", () => {
|
|
59
|
+
const expected = "<p>Update the content for this field.</p>";
|
|
60
|
+
|
|
61
|
+
const emptyParagraphRef = React.createRef<EditorField>();
|
|
62
|
+
render(
|
|
63
|
+
<EditorField ref={emptyParagraphRef} content="<p></p>" disabled={false} />
|
|
64
|
+
);
|
|
65
|
+
expect(emptyParagraphRef.current?.getValue()).toBe(expected);
|
|
66
|
+
|
|
67
|
+
const emptyStringRef = React.createRef<EditorField>();
|
|
68
|
+
render(<EditorField ref={emptyStringRef} content="" disabled={false} />);
|
|
69
|
+
expect(emptyStringRef.current?.getValue()).toBe(expected);
|
|
70
|
+
|
|
71
|
+
const undefinedRef = React.createRef<EditorField>();
|
|
72
|
+
render(
|
|
73
|
+
<EditorField ref={undefinedRef} content={undefined} disabled={false} />
|
|
74
|
+
);
|
|
75
|
+
expect(undefinedRef.current?.getValue()).toBe(expected);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("disables the toolbar buttons and the editor when disabled", () => {
|
|
79
|
+
const { container, rerender } = render(
|
|
80
|
+
<EditorField content="This is a summary." disabled={false} />
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const buttons = () => Array.from(container.querySelectorAll("button"));
|
|
84
|
+
const editable = () => container.querySelector("[contenteditable]");
|
|
85
|
+
|
|
86
|
+
expect(buttons()).toHaveLength(3);
|
|
87
|
+
buttons().forEach((button) => expect(button).not.toBeDisabled());
|
|
88
|
+
expect(editable()).toHaveAttribute("contenteditable", "true");
|
|
89
|
+
|
|
90
|
+
rerender(<EditorField content="This is a summary." disabled={true} />);
|
|
91
|
+
|
|
92
|
+
buttons().forEach((button) => expect(button).toBeDisabled());
|
|
93
|
+
expect(editable()).toHaveAttribute("contenteditable", "false");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import GenreForm from "../../../src/components/GenreForm";
|
|
6
|
+
import genreData from "../../../src/components/__tests__/genreData";
|
|
7
|
+
|
|
8
|
+
const genreOptions = Object.keys(genreData["Fiction"]).map(
|
|
9
|
+
(name) => genreData["Fiction"][name]
|
|
10
|
+
);
|
|
11
|
+
const nonfictionOptions = Object.keys(genreData["Nonfiction"]).map(
|
|
12
|
+
(name) => genreData["Nonfiction"][name]
|
|
13
|
+
);
|
|
14
|
+
const bookGenres = ["Adventure", "Epic Fantasy"];
|
|
15
|
+
|
|
16
|
+
const renderForm = (props: Record<string, unknown> = {}) => {
|
|
17
|
+
const addGenre = jest.fn();
|
|
18
|
+
const result = render(
|
|
19
|
+
<GenreForm
|
|
20
|
+
genreOptions={genreOptions}
|
|
21
|
+
bookGenres={bookGenres}
|
|
22
|
+
addGenre={addGenre}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
return { ...result, addGenre };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const genreSelect = (container: HTMLElement) =>
|
|
30
|
+
container.querySelector("select[name='genre']") as HTMLSelectElement;
|
|
31
|
+
const genreOptionEls = (container: HTMLElement) =>
|
|
32
|
+
Array.from(
|
|
33
|
+
genreSelect(container).querySelectorAll<HTMLOptionElement>("option")
|
|
34
|
+
);
|
|
35
|
+
const subgenreSelect = (container: HTMLElement) =>
|
|
36
|
+
container.querySelector(
|
|
37
|
+
"select[name='subgenre']"
|
|
38
|
+
) as HTMLSelectElement | null;
|
|
39
|
+
|
|
40
|
+
describe("GenreForm", () => {
|
|
41
|
+
describe("rendering", () => {
|
|
42
|
+
it("shows multiple select with top-level genres", () => {
|
|
43
|
+
const { container } = renderForm();
|
|
44
|
+
const topLevelGenres = genreOptions.filter(
|
|
45
|
+
(genre) => genre.parents.length === 0
|
|
46
|
+
);
|
|
47
|
+
const options = genreOptionEls(container);
|
|
48
|
+
|
|
49
|
+
expect(options).toHaveLength(topLevelGenres.length);
|
|
50
|
+
options.forEach((option, i) => {
|
|
51
|
+
const name = topLevelGenres[i].name;
|
|
52
|
+
const hasGenre = bookGenres.indexOf(name) !== -1;
|
|
53
|
+
const hasSubgenre = topLevelGenres[i].subgenres.length > 0;
|
|
54
|
+
const displayName = name + (hasSubgenre ? " >" : "");
|
|
55
|
+
expect(option.value).toBe(name);
|
|
56
|
+
expect(option.disabled).toBe(hasGenre);
|
|
57
|
+
expect(option.textContent).toBe(displayName);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("behavior", () => {
|
|
63
|
+
it("shows multiple select with subgenres when genre is selected", () => {
|
|
64
|
+
const { container, rerender } = renderForm();
|
|
65
|
+
|
|
66
|
+
// Nothing is selected yet: no subgenre select and no Add button.
|
|
67
|
+
expect(subgenreSelect(container)).toBeNull();
|
|
68
|
+
expect(screen.queryByRole("button", { name: "Add" })).toBeNull();
|
|
69
|
+
|
|
70
|
+
// Select a genre with no subgenres (the first option). The component wires
|
|
71
|
+
// selection to `onClick` on each <option>, so fire a click there.
|
|
72
|
+
const firstGenre = genreOptionEls(container)[0];
|
|
73
|
+
fireEvent.click(firstGenre);
|
|
74
|
+
expect(firstGenre).toHaveAttribute("aria-selected", "true");
|
|
75
|
+
expect(subgenreSelect(container)).toBeNull();
|
|
76
|
+
expect(screen.getByRole("button", { name: "Add" })).toBeInTheDocument();
|
|
77
|
+
|
|
78
|
+
// Select a genre that has subgenres.
|
|
79
|
+
const fantasy = genreOptionEls(container).find(
|
|
80
|
+
(option) => option.value === "Fantasy"
|
|
81
|
+
);
|
|
82
|
+
fireEvent.click(fantasy);
|
|
83
|
+
expect(fantasy).toHaveAttribute("aria-selected", "true");
|
|
84
|
+
|
|
85
|
+
const subSelect = subgenreSelect(container);
|
|
86
|
+
expect(subSelect).not.toBeNull();
|
|
87
|
+
const subOptions = Array.from(
|
|
88
|
+
subSelect.querySelectorAll<HTMLOptionElement>("option")
|
|
89
|
+
);
|
|
90
|
+
const subgenres = [...genreData["Fiction"]["Fantasy"].subgenres].sort();
|
|
91
|
+
|
|
92
|
+
expect(subOptions).toHaveLength(subgenres.length);
|
|
93
|
+
subOptions.forEach((option, i) => {
|
|
94
|
+
const name = subgenres[i];
|
|
95
|
+
const hasGenre = bookGenres.indexOf(name) !== -1;
|
|
96
|
+
expect(option.value).toBe(name);
|
|
97
|
+
expect(option.disabled).toBe(hasGenre);
|
|
98
|
+
expect(option.textContent).toBe(name);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Selecting a subgenre marks it as selected.
|
|
102
|
+
fireEvent.click(subOptions[0]);
|
|
103
|
+
expect(
|
|
104
|
+
subgenreSelect(container).querySelector('option[value="Epic Fantasy"]')
|
|
105
|
+
).toHaveAttribute("aria-selected", "true");
|
|
106
|
+
|
|
107
|
+
// Changing the genre options (fiction -> nonfiction) drops the subgenres,
|
|
108
|
+
// since the selected genre no longer exists in the new options.
|
|
109
|
+
rerender(
|
|
110
|
+
<GenreForm
|
|
111
|
+
genreOptions={nonfictionOptions}
|
|
112
|
+
bookGenres={bookGenres}
|
|
113
|
+
addGenre={jest.fn()}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
expect(subgenreSelect(container)).toBeNull();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("shows add button only if genre is selected", () => {
|
|
120
|
+
const { container } = renderForm();
|
|
121
|
+
expect(screen.queryByRole("button", { name: "Add" })).toBeNull();
|
|
122
|
+
|
|
123
|
+
const womensFiction = genreOptionEls(container).find(
|
|
124
|
+
(option) => option.value === "Women's Fiction"
|
|
125
|
+
);
|
|
126
|
+
fireEvent.click(womensFiction);
|
|
127
|
+
|
|
128
|
+
expect(screen.getByRole("button", { name: "Add" })).toBeInTheDocument();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("adds genre", async () => {
|
|
132
|
+
const user = userEvent.setup();
|
|
133
|
+
const { container, addGenre } = renderForm();
|
|
134
|
+
|
|
135
|
+
const scienceFiction = genreOptionEls(container).find(
|
|
136
|
+
(option) => option.value === "Science Fiction"
|
|
137
|
+
);
|
|
138
|
+
fireEvent.click(scienceFiction);
|
|
139
|
+
|
|
140
|
+
const spaceOpera = Array.from(
|
|
141
|
+
subgenreSelect(container).querySelectorAll<HTMLOptionElement>("option")
|
|
142
|
+
).find((option) => option.value === "Space Opera");
|
|
143
|
+
fireEvent.click(spaceOpera);
|
|
144
|
+
|
|
145
|
+
await user.click(screen.getByRole("button", { name: "Add" }));
|
|
146
|
+
|
|
147
|
+
// The subgenre takes precedence over the top-level genre.
|
|
148
|
+
expect(addGenre).toHaveBeenCalledTimes(1);
|
|
149
|
+
expect(addGenre.mock.calls[0][0]).toBe("Space Opera");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|