@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.
Files changed (94) hide show
  1. package/CLAUDE.md +16 -7
  2. package/dist/circulation-admin.js +1 -1
  3. package/eslint.config.mjs +9 -1
  4. package/jest.config.js +56 -9
  5. package/package.json +6 -16
  6. package/tests/jest/actions.test.ts +962 -0
  7. package/tests/jest/components/AccountPage.test.tsx +41 -0
  8. package/tests/jest/components/AdvancedSearchBooleanFilter.test.tsx +231 -0
  9. package/tests/jest/components/AdvancedSearchFilter.test.tsx +142 -0
  10. package/tests/jest/components/AdvancedSearchFilterInput.test.tsx +212 -0
  11. package/tests/jest/components/AdvancedSearchFilterViewer.test.tsx +52 -0
  12. package/tests/jest/components/AdvancedSearchValueFilter.test.tsx +123 -0
  13. package/tests/jest/components/Announcement.test.tsx +76 -0
  14. package/tests/jest/components/Autocomplete.test.tsx +67 -0
  15. package/tests/jest/components/BookDetails.test.tsx +133 -0
  16. package/tests/jest/components/BookDetailsContainer.test.tsx +116 -0
  17. package/tests/jest/components/BookDetailsEditor.test.tsx +275 -0
  18. package/tests/jest/components/BookEditForm.test.tsx +352 -0
  19. package/tests/jest/components/CatalogServices.test.tsx +63 -0
  20. package/tests/jest/components/CirculationEventsDownloadForm.test.tsx +41 -0
  21. package/tests/jest/components/Classifications.test.tsx +166 -0
  22. package/tests/jest/components/ClassificationsTable.test.tsx +57 -0
  23. package/tests/jest/components/ColorPicker.test.tsx +58 -0
  24. package/tests/jest/components/ComplaintForm.test.tsx +171 -0
  25. package/tests/jest/components/Complaints.test.tsx +259 -0
  26. package/tests/jest/components/ConfigPage.test.tsx +58 -0
  27. package/tests/jest/components/ContextProvider.test.tsx +138 -0
  28. package/tests/jest/components/CustomListEditor.test.tsx +367 -0
  29. package/tests/jest/components/CustomListPage.test.tsx +57 -0
  30. package/tests/jest/components/CustomListSearch.test.tsx +275 -0
  31. package/tests/jest/components/CustomListsForBook.test.tsx +315 -0
  32. package/tests/jest/components/CustomListsSidebar.test.tsx +251 -0
  33. package/tests/jest/components/DashboardPage.test.tsx +76 -0
  34. package/tests/jest/components/DebugAuthentication.test.tsx +1 -5
  35. package/tests/jest/components/DiagnosticsServiceTabs.test.tsx +141 -0
  36. package/tests/jest/components/DiagnosticsServiceType.test.tsx +75 -0
  37. package/tests/jest/components/DiagnosticsTabContainer.test.tsx +147 -0
  38. package/tests/jest/components/EditableConfigList.test.tsx +8 -2
  39. package/tests/jest/components/EntryPointsContainer.test.tsx +97 -0
  40. package/tests/jest/components/EntryPointsTabs.test.tsx +88 -0
  41. package/tests/jest/components/ErrorMessage.test.tsx +97 -0
  42. package/tests/jest/components/Footer.test.tsx +141 -0
  43. package/tests/jest/components/InventoryReportRequestModal.test.tsx +16 -42
  44. package/tests/jest/components/LaneEditor.test.tsx +2 -6
  45. package/tests/jest/components/LanePage.test.tsx +68 -0
  46. package/tests/jest/components/LanguageField.test.tsx +40 -0
  47. package/tests/jest/components/LibraryEditForm.test.tsx +383 -0
  48. package/tests/jest/components/LibraryRegistrationForm.test.tsx +203 -0
  49. package/tests/jest/components/LoadButton.test.tsx +49 -0
  50. package/tests/jest/components/ManagePatrons.test.tsx +73 -0
  51. package/tests/jest/components/ManagePatronsForm.test.tsx +180 -0
  52. package/tests/jest/components/ManagePatronsTabContainer.test.tsx +143 -0
  53. package/tests/jest/components/MetadataServices.test.tsx +59 -0
  54. package/tests/jest/components/PatronAuthServices.test.tsx +114 -0
  55. package/tests/jest/components/PatronBlockingRulesEditor.test.tsx +3 -1
  56. package/tests/jest/components/PatronInfo.test.tsx +54 -0
  57. package/tests/jest/components/ResetAdobeId.test.tsx +302 -0
  58. package/tests/jest/components/SaveButton.test.tsx +47 -0
  59. package/tests/jest/components/SelfTestResult.test.tsx +164 -0
  60. package/tests/jest/components/SelfTestsCategory.test.tsx +200 -0
  61. package/tests/jest/components/ServiceWithRegistrationsEditForm.test.tsx +110 -0
  62. package/tests/jest/components/SetupPage.test.tsx +41 -0
  63. package/tests/jest/components/SingleStatListItem.test.tsx +62 -0
  64. package/tests/jest/components/SitewideAnnouncements.test.tsx +134 -0
  65. package/tests/jest/components/Stats.test.tsx +4 -8
  66. package/tests/jest/components/TabContainer.test.tsx +68 -0
  67. package/tests/jest/components/Timestamp.test.tsx +74 -0
  68. package/tests/jest/components/TroubleshootingCategoryPage.test.tsx +69 -0
  69. package/tests/jest/components/TroubleshootingPage.test.tsx +94 -0
  70. package/tests/jest/components/TroubleshootingTabContainer.test.tsx +68 -0
  71. package/tests/jest/components/UpdatingLoader.test.tsx +36 -0
  72. package/tests/jest/components/WelcomePage.test.tsx +43 -0
  73. package/tests/jest/components/WithEditButton.test.tsx +55 -0
  74. package/tests/jest/components/WithRemoveButton.test.tsx +95 -0
  75. package/tests/jest/editorAdapter.test.ts +245 -0
  76. package/tests/jest/index.test.tsx +50 -0
  77. package/tests/jest/legacy-setup.ts +13 -0
  78. package/tests/jest/legacyJsdomEnvironment.js +49 -0
  79. package/tests/jest/models/Admin.test.ts +206 -0
  80. package/tests/jest/reducers/bookCoverPreview.test.ts +81 -0
  81. package/tests/jest/reducers/classifications.test.ts +161 -0
  82. package/tests/jest/reducers/collections.test.ts +96 -0
  83. package/tests/jest/reducers/complaints.test.ts +166 -0
  84. package/tests/jest/reducers/createFetchEditReducer.test.ts +220 -0
  85. package/tests/jest/reducers/createRegisterLibraryReducer.test.ts +51 -0
  86. package/tests/jest/reducers/customListDetails.test.ts +120 -0
  87. package/tests/jest/reducers/customListEditor.test.ts +2823 -0
  88. package/tests/jest/reducers/managePatrons.test.ts +71 -0
  89. package/tests/jest/testUtils/formDataShim.test.ts +135 -0
  90. package/tests/jest/testUtils/formDataShim.ts +112 -0
  91. package/tests/jest/utils/sharedFunctions.test.ts +121 -0
  92. package/tsconfig.json +3 -4
  93. package/testReporter.js +0 -29
  94. package/tests/jest/components/AdvancedSearchBuilder.test.tsx +0 -38
@@ -0,0 +1,200 @@
1
+ import * as React from "react";
2
+ import { screen } from "@testing-library/react";
3
+
4
+ import { renderWithProviders } from "../testUtils/withProviders";
5
+ import buildStore from "../../../src/store";
6
+
7
+ // `SelfTests` is a connected component that fetches self-test results on mount.
8
+ // It is incidental to what `SelfTestsCategory` itself does (build one panel per
9
+ // item, color-code them, decide `openByDefault`, and compute `sortByCollection`),
10
+ // so mock it to a marker that exposes the props the category passes down.
11
+ jest.mock("../../../src/components/SelfTests", () => ({
12
+ __esModule: true,
13
+ default: (props: any) => (
14
+ <div
15
+ data-testid="self-tests"
16
+ data-type={props.type}
17
+ data-item-id={props.item?.id}
18
+ data-item-name={props.item?.name}
19
+ data-sort-by-collection={String(props.sortByCollection)}
20
+ />
21
+ ),
22
+ }));
23
+
24
+ import SelfTestsCategory from "../../../src/components/SelfTestsCategory";
25
+
26
+ const initialSetupResult = {
27
+ duration: 0.000119,
28
+ end: "2018-08-07T19:34:54Z",
29
+ exception: null,
30
+ name: "Initial setup.",
31
+ result: null,
32
+ start: "2018-08-07T19:34:54Z",
33
+ success: true,
34
+ };
35
+
36
+ const collections: any[] = [
37
+ {
38
+ id: 1,
39
+ name: "collection with success",
40
+ protocol: "protocol",
41
+ self_test_results: {
42
+ duration: 1.75,
43
+ start: "2018-08-07T19:34:54Z",
44
+ end: "2018-08-07T19:34:55Z",
45
+ results: [initialSetupResult],
46
+ },
47
+ },
48
+ {
49
+ id: 2,
50
+ name: "collection with failure",
51
+ protocol: "protocol",
52
+ self_test_results: {
53
+ duration: 1.75,
54
+ start: "2018-08-07T19:34:54Z",
55
+ end: "2018-08-07T19:34:55Z",
56
+ results: [
57
+ initialSetupResult,
58
+ {
59
+ duration: 0,
60
+ end: "2018-08-07T19:34:55Z",
61
+ exception: {
62
+ class: "IntegrationException",
63
+ debug_message:
64
+ "Add the collection to a library that has a patron authentication service.",
65
+ message: "Collection is not associated with any libraries.",
66
+ },
67
+ name: "Acquiring test patron credentials.",
68
+ result: null,
69
+ start: "2018-08-07T19:34:55Z",
70
+ success: false,
71
+ },
72
+ ],
73
+ },
74
+ },
75
+ {
76
+ id: 3,
77
+ name: "collection with no results",
78
+ protocol: "protocol",
79
+ },
80
+ ];
81
+
82
+ const renderCategory = (items: any[] = collections) =>
83
+ renderWithProviders(
84
+ <SelfTestsCategory
85
+ type="collection"
86
+ linkName="collections"
87
+ csrfToken="token"
88
+ items={items}
89
+ store={buildStore()}
90
+ />
91
+ );
92
+
93
+ describe("SelfTestsCategory", () => {
94
+ it("renders a list of items", () => {
95
+ const { container } = renderCategory();
96
+
97
+ const root = container.querySelector(".self-tests-category");
98
+ expect(root).toBeInTheDocument();
99
+ expect(root).toHaveClass("has-additional-content");
100
+
101
+ const titles = Array.from(
102
+ container.querySelectorAll("ul .panel-title")
103
+ ).map((el) => el.textContent);
104
+ expect(titles).toStrictEqual([
105
+ "collection with success",
106
+ "collection with failure",
107
+ "collection with no results",
108
+ ]);
109
+
110
+ // One SelfTests per item, each carrying the category's type and its item.
111
+ const selfTests = screen.getAllByTestId("self-tests");
112
+ expect(selfTests).toHaveLength(3);
113
+ selfTests.forEach((el, idx) => {
114
+ expect(el).toHaveAttribute("data-type", "collection");
115
+ expect(el).toHaveAttribute("data-item-id", String(collections[idx].id));
116
+ });
117
+ });
118
+
119
+ it("color-codes", () => {
120
+ const { container } = renderCategory();
121
+ const panels = container.querySelectorAll(".panel");
122
+ expect(panels[0]).toHaveClass("panel-success");
123
+ expect(panels[1]).toHaveClass("panel-danger");
124
+ expect(panels[2]).toHaveClass("panel-default");
125
+ });
126
+
127
+ it("opens the panel by default if there's only one", () => {
128
+ // With multiple items, none are open by default.
129
+ const multi = renderCategory();
130
+ expect(
131
+ Array.from(multi.container.querySelectorAll(".panel-heading")).some(
132
+ (h) => h.getAttribute("aria-expanded") === "true"
133
+ )
134
+ ).toBe(false);
135
+ multi.unmount();
136
+
137
+ // A fresh render with a single item opens that panel by default.
138
+ // (`openByDefault` seeds the panel's initial state, so a new mount is needed.)
139
+ const single = renderCategory([collections[0]]);
140
+ const singleHeaders = single.container.querySelectorAll(".panel-heading");
141
+ expect(singleHeaders).toHaveLength(1);
142
+ expect(singleHeaders[0]).toHaveAttribute("aria-expanded", "true");
143
+ });
144
+
145
+ it("passes the sortByCollection prop to SelfTests", () => {
146
+ const { rerender } = renderCategory();
147
+ expect(screen.getAllByTestId("self-tests")[0]).toHaveAttribute(
148
+ "data-sort-by-collection",
149
+ "false"
150
+ );
151
+
152
+ const withCollection = {
153
+ id: 99,
154
+ name: "collection with sorting",
155
+ protocol: "protocol",
156
+ self_test_results: {
157
+ duration: 1.75,
158
+ start: "2018-08-07T19:34:54Z",
159
+ end: "2018-08-07T19:34:55Z",
160
+ results: [{ ...initialSetupResult, collection: "sort!" }],
161
+ },
162
+ };
163
+
164
+ rerender(
165
+ <SelfTestsCategory
166
+ type="collection"
167
+ linkName="collections"
168
+ csrfToken="token"
169
+ items={[withCollection, ...collections]}
170
+ store={buildStore()}
171
+ />
172
+ );
173
+
174
+ expect(screen.getAllByTestId("self-tests")[0]).toHaveAttribute(
175
+ "data-sort-by-collection",
176
+ "true"
177
+ );
178
+ });
179
+
180
+ it("handles unnamed items", () => {
181
+ const nameless: any = {
182
+ id: 1,
183
+ name: null,
184
+ protocol: "protocol",
185
+ self_test_results: {
186
+ duration: 1.75,
187
+ start: "2018-08-07T19:34:54Z",
188
+ end: "2018-08-07T19:34:55Z",
189
+ results: [initialSetupResult],
190
+ },
191
+ };
192
+ const { container } = renderCategory([nameless]);
193
+
194
+ expect(screen.getByText("Unnamed collection")).toHaveClass("panel-title");
195
+ // Panel id becomes `${name-without-spaces}-${id}`; its body id appends "-panel".
196
+ expect(
197
+ container.querySelector("#Unnamedcollection-1-panel")
198
+ ).toBeInTheDocument();
199
+ });
200
+ });
@@ -0,0 +1,110 @@
1
+ import * as React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+
4
+ import { DiscoveryServicesData } from "../../../src/interfaces";
5
+ import ServiceWithRegistrationsEditForm from "../../../src/components/ServiceWithRegistrationsEditForm";
6
+
7
+ // `ServiceWithRegistrationsEditForm` is generic/abstract over its data type;
8
+ // the legacy test subclassed it to bind the discovery-services data type.
9
+ class DiscoveryServiceEditForm extends ServiceWithRegistrationsEditForm<DiscoveryServicesData> {}
10
+
11
+ const serviceData = {
12
+ id: 1,
13
+ protocol: "protocol 1",
14
+ };
15
+ const protocolsData = [
16
+ {
17
+ name: "protocol 1",
18
+ label: "protocol 1 label",
19
+ supports_registration: true,
20
+ settings: [],
21
+ library_settings: [],
22
+ },
23
+ ];
24
+ const allLibraries = [
25
+ { short_name: "nypl", name: "New York Public Library" },
26
+ { short_name: "bpl", name: "Brooklyn Public Library" },
27
+ { short_name: "qpl", name: "Queens Public Library" },
28
+ ];
29
+ const libraryRegistrationsData = [
30
+ {
31
+ id: 1,
32
+ libraries: [
33
+ { short_name: "nypl", status: "success", stage: "production" },
34
+ { short_name: "bpl", status: "failure", stage: "testing" },
35
+ ],
36
+ },
37
+ ];
38
+ const servicesData: any = {
39
+ discovery_services: [serviceData],
40
+ protocols: protocolsData,
41
+ allLibraries: allLibraries,
42
+ libraryRegistrations: libraryRegistrationsData,
43
+ };
44
+
45
+ const renderForm = (save = jest.fn()) =>
46
+ render(
47
+ <DiscoveryServiceEditForm
48
+ disabled={false}
49
+ data={servicesData}
50
+ item={serviceData as any}
51
+ save={save}
52
+ urlBase="url base"
53
+ listDataKey="discovery_services"
54
+ />
55
+ );
56
+
57
+ describe("ServiceWithRegistrationsEditForm", () => {
58
+ it("renders the underlying service edit form fields", () => {
59
+ renderForm();
60
+
61
+ // The base ServiceEditForm (via `super.render()`) contributes the Name text
62
+ // field and the Required Fields section.
63
+ expect(screen.getByRole("textbox")).toBeInTheDocument();
64
+ expect(
65
+ screen.getByRole("heading", { name: "Required Fields" })
66
+ ).toBeInTheDocument();
67
+ });
68
+
69
+ it("renders a registration section reflecting each library's status", () => {
70
+ renderForm();
71
+
72
+ // The registration UI only renders when the protocol supports registration
73
+ // and the data carries libraries — i.e. those props flowed to LibraryRegistration.
74
+ expect(
75
+ screen.getByRole("heading", { name: "Register libraries" })
76
+ ).toBeInTheDocument();
77
+
78
+ expect(
79
+ screen.getByRole("link", { name: "New York Public Library" })
80
+ ).toBeInTheDocument();
81
+ expect(
82
+ screen.getByRole("link", { name: "Brooklyn Public Library" })
83
+ ).toBeInTheDocument();
84
+ expect(
85
+ screen.getByRole("link", { name: "Queens Public Library" })
86
+ ).toBeInTheDocument();
87
+
88
+ // Statuses come from `data.libraryRegistrations`.
89
+ expect(screen.getByText("Registered")).toHaveClass("bg-success");
90
+ expect(screen.getByText("Registration failed")).toHaveClass("bg-danger");
91
+ expect(screen.getByText("Not registered")).toHaveClass("bg-warning");
92
+ });
93
+
94
+ it("enables the per-library registration actions when not disabled", () => {
95
+ renderForm();
96
+
97
+ // `disabled={false}` flows through to each registration button.
98
+ const updateButton = screen.getByRole("button", {
99
+ name: "Update registration",
100
+ });
101
+ const retryButton = screen.getByRole("button", {
102
+ name: "Retry registration",
103
+ });
104
+ const registerButton = screen.getByRole("button", { name: "Register" });
105
+
106
+ expect(updateButton).not.toBeDisabled();
107
+ expect(retryButton).not.toBeDisabled();
108
+ expect(registerButton).not.toBeDisabled();
109
+ });
110
+ });
@@ -0,0 +1,41 @@
1
+ import * as React from "react";
2
+ import { screen } from "@testing-library/react";
3
+
4
+ import { renderWithProviders } from "../testUtils/withProviders";
5
+ import SetupPage from "../../../src/components/SetupPage";
6
+
7
+ describe("SetupPage", () => {
8
+ beforeEach(() => {
9
+ // SetupPage renders the connected IndividualAdmins list, which fetches the
10
+ // admin list on mount. Stub fetch so mounting does not hit the network.
11
+ jest.spyOn(globalThis, "fetch").mockResolvedValue(
12
+ new Response(JSON.stringify({ individualAdmins: [] }), {
13
+ status: 200,
14
+ headers: { "Content-Type": "application/json" },
15
+ })
16
+ );
17
+ });
18
+
19
+ afterEach(() => {
20
+ jest.restoreAllMocks();
21
+ });
22
+
23
+ it("shows the individual-admins setup (create) form", async () => {
24
+ renderWithProviders(<SetupPage />);
25
+
26
+ // SetupPage wires IndividualAdmins with settingUp + editOrCreate="create".
27
+ // That combination renders the "Welcome!" heading and the
28
+ // "Set up your system admin account" create-form heading; their presence in
29
+ // the real DOM proves the child received those props (the original shallow
30
+ // test asserted the props directly). No identifier is passed, so there is no
31
+ // per-item "Edit ..." heading — only the create form shows.
32
+ expect(
33
+ await screen.findByRole("heading", { name: "Welcome!" })
34
+ ).toBeInTheDocument();
35
+ expect(
36
+ screen.getByRole("heading", {
37
+ name: "Set up your system admin account",
38
+ })
39
+ ).toBeInTheDocument();
40
+ });
41
+ });
@@ -0,0 +1,62 @@
1
+ import * as React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+
4
+ import SingleStatListItem, {
5
+ SingleStatListItemProps,
6
+ } from "../../../src/components/SingleStatListItem";
7
+
8
+ describe("SingleStatListItem", () => {
9
+ const statWithTooltip: SingleStatListItemProps = {
10
+ label: "Number of Widgets",
11
+ value: 357892,
12
+ tooltip: "Total Widget Count",
13
+ };
14
+ const humanReadableValue = "357.9k";
15
+ const formattedValue = "357,892";
16
+
17
+ it("renders a top-level <li>, with or without a tooltip", () => {
18
+ const { container, rerender } = render(
19
+ <SingleStatListItem {...statWithTooltip} />
20
+ );
21
+ expect(container.firstElementChild?.tagName).toBe("LI");
22
+ expect(container.firstElementChild).toHaveClass("single-stat");
23
+
24
+ // Without a tooltip the <li> is still the top-level element.
25
+ rerender(
26
+ <SingleStatListItem
27
+ label={statWithTooltip.label}
28
+ value={statWithTooltip.value}
29
+ />
30
+ );
31
+ expect(container.firstElementChild?.tagName).toBe("LI");
32
+ expect(container.firstElementChild).toHaveClass("single-stat");
33
+ });
34
+
35
+ it("shows a tooltip wrapping the value and label when one is provided", () => {
36
+ const { container } = render(<SingleStatListItem {...statWithTooltip} />);
37
+
38
+ const tooltip = container.querySelector('[data-toggle="tooltip"]');
39
+ expect(tooltip).not.toBeNull();
40
+
41
+ const title = tooltip?.getAttribute("title") ?? "";
42
+ expect(title).toContain(statWithTooltip.tooltip);
43
+ expect(title).toContain(formattedValue);
44
+
45
+ // When there's a tooltip, it wraps the (rounded) value and the label.
46
+ expect(tooltip).toHaveTextContent(humanReadableValue);
47
+ expect(tooltip).toHaveTextContent(statWithTooltip.label);
48
+ });
49
+
50
+ it("omits the tooltip when none is provided, showing value and label directly", () => {
51
+ const { container } = render(
52
+ <SingleStatListItem
53
+ label={statWithTooltip.label}
54
+ value={statWithTooltip.value}
55
+ />
56
+ );
57
+
58
+ expect(container.querySelector('[data-toggle="tooltip"]')).toBeNull();
59
+ expect(screen.getByText(humanReadableValue)).toBeInTheDocument();
60
+ expect(screen.getByText(statWithTooltip.label)).toBeInTheDocument();
61
+ });
62
+ });
@@ -0,0 +1,134 @@
1
+ import * as React from "react";
2
+ import { installFormDataShim, FormDataShim } from "../testUtils/formDataShim";
3
+ import { screen, waitFor } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ import { renderWithProviders } from "../testUtils/withProviders";
7
+ import buildStore from "../../../src/store";
8
+ // Render the CONNECTED default export so that mapStateToProps / mapDispatchToProps
9
+ // are exercised. The panel fetches its announcements on mount; the fetched data
10
+ // flows back in through the Redux store.
11
+ import SitewideAnnouncements from "../../../src/components/SitewideAnnouncements";
12
+
13
+ const data = {
14
+ announcements: [
15
+ {
16
+ id: "dcf036d9-106b-426c-838f-ce7c57d53801",
17
+ content: "There is nothing to see here.",
18
+ start: "2022-08-31",
19
+ finish: "2022-10-31",
20
+ },
21
+ ],
22
+ settings: [
23
+ {
24
+ category: "Announcements",
25
+ description: "Announcements will be displayed to authenticated patrons.",
26
+ key: "global_announcements",
27
+ label: "Scheduled announcements",
28
+ level: 3,
29
+ type: "announcements",
30
+ },
31
+ ],
32
+ };
33
+ installFormDataShim();
34
+
35
+ const jsonResponse = (body: unknown) =>
36
+ new Response(JSON.stringify(body), {
37
+ status: 200,
38
+ headers: { "Content-Type": "application/json" },
39
+ });
40
+
41
+ const renderConnected = (
42
+ element: React.ReactElement,
43
+ appConfigSettings: Record<string, unknown> = {}
44
+ ) =>
45
+ renderWithProviders(element, {
46
+ reduxProviderProps: { store: buildStore() },
47
+ appConfigSettings,
48
+ });
49
+
50
+ describe("SitewideAnnouncements", () => {
51
+ afterEach(() => {
52
+ jest.restoreAllMocks();
53
+ });
54
+
55
+ it("renders a form containing the announcements section", async () => {
56
+ jest
57
+ .spyOn(globalThis, "fetch")
58
+ .mockImplementation(async () => jsonResponse(data));
59
+ const { container } = renderConnected(
60
+ <SitewideAnnouncements csrfToken="token" />
61
+ );
62
+
63
+ // Once the on-mount fetch resolves, the form renders with the announcement
64
+ // supplied through the store (proving the AnnouncementsSection received the
65
+ // data as its value).
66
+ expect(
67
+ await screen.findByText("There is nothing to see here.")
68
+ ).toBeInTheDocument();
69
+ expect(screen.getByText("Scheduled Announcements:")).toBeInTheDocument();
70
+ expect(container.querySelector("form")).toBeInTheDocument();
71
+ });
72
+
73
+ it("renders a loading indicator instead of a form while data is loading", () => {
74
+ // A never-resolving fetch keeps the panel in its fetching state.
75
+ jest
76
+ .spyOn(globalThis, "fetch")
77
+ .mockImplementation(() => new Promise(() => {}));
78
+ const { container } = renderConnected(
79
+ <SitewideAnnouncements csrfToken="token" />
80
+ );
81
+
82
+ expect(container.querySelector(".loading")).toBeInTheDocument();
83
+ expect(container.querySelector("form")).not.toBeInTheDocument();
84
+ });
85
+
86
+ it("submits the announcements to editItem when the form is submitted", async () => {
87
+ const user = userEvent.setup();
88
+ const fetchSpy = jest
89
+ .spyOn(globalThis, "fetch")
90
+ .mockImplementation(async (_url, opts?: RequestInit) => {
91
+ if (opts?.method === "POST") {
92
+ return new Response("success", { status: 200 });
93
+ }
94
+ return jsonResponse(data);
95
+ });
96
+
97
+ // System admin so the settings' required permission level is satisfied and
98
+ // the submit button is enabled.
99
+ renderConnected(<SitewideAnnouncements csrfToken="token" />, {
100
+ roles: [{ role: "system" }],
101
+ });
102
+
103
+ await screen.findByText("There is nothing to see here.");
104
+
105
+ await user.click(screen.getByRole("button", { name: "Submit" }));
106
+
107
+ // The submit dispatches editSitewideAnnouncements, which POSTs the form.
108
+ await waitFor(() => {
109
+ const postCall = fetchSpy.mock.calls.find(
110
+ ([, opts]) => (opts as RequestInit)?.method === "POST"
111
+ );
112
+ expect(postCall).toBeDefined();
113
+ });
114
+
115
+ const postCall = fetchSpy.mock.calls.find(
116
+ ([, opts]) => (opts as RequestInit)?.method === "POST"
117
+ );
118
+ const body = (postCall[1] as RequestInit).body as unknown as FormDataShim;
119
+ expect(JSON.parse(body.get("announcements"))).toStrictEqual(
120
+ data.announcements
121
+ );
122
+ });
123
+
124
+ it("disables the submit button when the admin lacks the required permission level", async () => {
125
+ jest
126
+ .spyOn(globalThis, "fetch")
127
+ .mockImplementation(async () => jsonResponse(data));
128
+ // No roles => admin level 1, below the settings' required level of 3.
129
+ renderConnected(<SitewideAnnouncements csrfToken="token" />);
130
+
131
+ await screen.findByText("There is nothing to see here.");
132
+ expect(screen.getByRole("button", { name: "Submit" })).toBeDisabled();
133
+ });
134
+ });
@@ -382,14 +382,10 @@ describe("Dashboard Statistics", () => {
382
382
  roles,
383
383
  quicksightPagePath: fakeQuickSightHref,
384
384
  };
385
- const {
386
- container,
387
- getByRole,
388
- queryByRole,
389
- queryByText,
390
- } = renderWithProviders(<Stats library={sampleLibraryKey} />, {
391
- appConfigSettings,
392
- });
385
+ const { container, getByRole, queryByRole, queryByText } =
386
+ renderWithProviders(<Stats library={sampleLibraryKey} />, {
387
+ appConfigSettings,
388
+ });
393
389
 
394
390
  // We should always render a Usage reports group when a library is specified.
395
391
  getByRole("heading", {
@@ -0,0 +1,68 @@
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 {
6
+ TabContainer,
7
+ TabContainerProps,
8
+ } from "../../../src/components/TabContainer";
9
+
10
+ describe("TabContainer", () => {
11
+ let handleSelectSpy: jest.Mock;
12
+
13
+ // A concrete subclass of the abstract TabContainer, mirroring the legacy test's
14
+ // MockTabContainer: it supplies two trivial tabs and records the selected tab
15
+ // key when handleSelect runs.
16
+ class MockTabContainer extends TabContainer<TabContainerProps> {
17
+ handleSelect(event) {
18
+ handleSelectSpy(event.target.dataset.tabkey);
19
+ }
20
+ tabs() {
21
+ return {
22
+ tab1: <div className="tab1" />,
23
+ tab2: <div className="tab2" />,
24
+ };
25
+ }
26
+ }
27
+
28
+ const renderContainer = (tab: string = null) =>
29
+ render(
30
+ <MockTabContainer tab={tab} csrfToken="token">
31
+ <div className="test-child">Moby Dick</div>
32
+ </MockTabContainer>
33
+ );
34
+
35
+ beforeEach(() => {
36
+ handleSelectSpy = jest.fn();
37
+ });
38
+
39
+ it("shows nav tabs", () => {
40
+ const { container } = renderContainer();
41
+ const items = container.querySelectorAll("ul.nav-tabs li");
42
+ const linkTexts = Array.from(items).map((li) => li.textContent);
43
+ expect(linkTexts).toContain("Tab1");
44
+ expect(linkTexts).toContain("Tab2");
45
+ expect(items[0]).toHaveClass("active");
46
+ expect(items[1]).not.toHaveClass("active");
47
+ });
48
+
49
+ it("shows default tab content", () => {
50
+ const { container } = renderContainer();
51
+ expect(container.querySelector("#tab1")).toHaveStyle({ display: "block" });
52
+ expect(container.querySelector("#tab2")).toHaveStyle({ display: "none" });
53
+ });
54
+
55
+ it("shows tab content from tab in props", () => {
56
+ const { container } = renderContainer("tab2");
57
+ expect(container.querySelector("#tab1")).toHaveStyle({ display: "none" });
58
+ expect(container.querySelector("#tab2")).toHaveStyle({ display: "block" });
59
+ });
60
+
61
+ it("uses handleSelect to navigate when tab is clicked", async () => {
62
+ const user = userEvent.setup();
63
+ renderContainer();
64
+ await user.click(screen.getByRole("link", { name: "Tab2" }));
65
+ expect(handleSelectSpy).toHaveBeenCalledTimes(1);
66
+ expect(handleSelectSpy).toHaveBeenCalledWith("tab2");
67
+ });
68
+ });