@thepalaceproject/circulation-admin 1.42.2 → 1.43.0-post.10

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 (78) hide show
  1. package/.node-version +1 -1
  2. package/.nvmrc +1 -1
  3. package/CLAUDE.md +17 -8
  4. package/README.md +7 -7
  5. package/dist/circulation-admin.js +1 -1
  6. package/eslint.config.mjs +9 -1
  7. package/jest.config.js +56 -9
  8. package/package.json +10 -20
  9. package/tests/jest/actions.test.ts +962 -0
  10. package/tests/jest/components/AccountPage.test.tsx +41 -0
  11. package/tests/jest/components/AdvancedSearchBooleanFilter.test.tsx +231 -0
  12. package/tests/jest/components/AdvancedSearchFilter.test.tsx +142 -0
  13. package/tests/jest/components/AdvancedSearchFilterInput.test.tsx +212 -0
  14. package/tests/jest/components/AdvancedSearchFilterViewer.test.tsx +52 -0
  15. package/tests/jest/components/AdvancedSearchValueFilter.test.tsx +123 -0
  16. package/tests/jest/components/BookDetails.test.tsx +133 -0
  17. package/tests/jest/components/BookDetailsContainer.test.tsx +116 -0
  18. package/tests/jest/components/CatalogServices.test.tsx +63 -0
  19. package/tests/jest/components/CirculationEventsDownloadForm.test.tsx +41 -0
  20. package/tests/jest/components/ConfigPage.test.tsx +58 -0
  21. package/tests/jest/components/CustomListPage.test.tsx +57 -0
  22. package/tests/jest/components/CustomListSearch.test.tsx +275 -0
  23. package/tests/jest/components/CustomListsSidebar.test.tsx +251 -0
  24. package/tests/jest/components/DashboardPage.test.tsx +76 -0
  25. package/tests/jest/components/DebugAuthentication.test.tsx +1 -5
  26. package/tests/jest/components/DiagnosticsTabContainer.test.tsx +147 -0
  27. package/tests/jest/components/EditableConfigList.test.tsx +8 -2
  28. package/tests/jest/components/EntryPointsContainer.test.tsx +97 -0
  29. package/tests/jest/components/EntryPointsTabs.test.tsx +88 -0
  30. package/tests/jest/components/ErrorMessage.test.tsx +97 -0
  31. package/tests/jest/components/Footer.test.tsx +141 -0
  32. package/tests/jest/components/InventoryReportRequestModal.test.tsx +16 -42
  33. package/tests/jest/components/JsonField.test.tsx +20 -0
  34. package/tests/jest/components/LaneEditor.test.tsx +2 -6
  35. package/tests/jest/components/LanePage.test.tsx +68 -0
  36. package/tests/jest/components/LanguageField.test.tsx +40 -0
  37. package/tests/jest/components/LoadButton.test.tsx +49 -0
  38. package/tests/jest/components/ManagePatrons.test.tsx +73 -0
  39. package/tests/jest/components/ManagePatronsForm.test.tsx +180 -0
  40. package/tests/jest/components/ManagePatronsTabContainer.test.tsx +143 -0
  41. package/tests/jest/components/MetadataServices.test.tsx +59 -0
  42. package/tests/jest/components/PatronBlockingRulesEditor.test.tsx +3 -1
  43. package/tests/jest/components/PatronInfo.test.tsx +54 -0
  44. package/tests/jest/components/ProtocolFormField.test.tsx +36 -0
  45. package/tests/jest/components/SaveButton.test.tsx +47 -0
  46. package/tests/jest/components/SelfTestResult.test.tsx +164 -0
  47. package/tests/jest/components/SelfTestsCategory.test.tsx +200 -0
  48. package/tests/jest/components/ServiceWithRegistrationsEditForm.test.tsx +110 -0
  49. package/tests/jest/components/SetupPage.test.tsx +41 -0
  50. package/tests/jest/components/SingleStatListItem.test.tsx +62 -0
  51. package/tests/jest/components/Stats.test.tsx +4 -8
  52. package/tests/jest/components/TabContainer.test.tsx +68 -0
  53. package/tests/jest/components/Timestamp.test.tsx +74 -0
  54. package/tests/jest/components/TroubleshootingTabContainer.test.tsx +68 -0
  55. package/tests/jest/components/UpdatingLoader.test.tsx +36 -0
  56. package/tests/jest/components/WelcomePage.test.tsx +43 -0
  57. package/tests/jest/components/WithEditButton.test.tsx +55 -0
  58. package/tests/jest/components/WithRemoveButton.test.tsx +95 -0
  59. package/tests/jest/editorAdapter.test.ts +245 -0
  60. package/tests/jest/index.test.tsx +50 -0
  61. package/tests/jest/legacy-setup.ts +13 -0
  62. package/tests/jest/legacyJsdomEnvironment.js +49 -0
  63. package/tests/jest/models/Admin.test.ts +206 -0
  64. package/tests/jest/reducers/bookCoverPreview.test.ts +81 -0
  65. package/tests/jest/reducers/classifications.test.ts +161 -0
  66. package/tests/jest/reducers/collections.test.ts +96 -0
  67. package/tests/jest/reducers/complaints.test.ts +166 -0
  68. package/tests/jest/reducers/createFetchEditReducer.test.ts +220 -0
  69. package/tests/jest/reducers/createRegisterLibraryReducer.test.ts +51 -0
  70. package/tests/jest/reducers/customListDetails.test.ts +120 -0
  71. package/tests/jest/reducers/customListEditor.test.ts +2823 -0
  72. package/tests/jest/reducers/managePatrons.test.ts +71 -0
  73. package/tests/jest/testUtils/formDataShim.test.ts +135 -0
  74. package/tests/jest/testUtils/formDataShim.ts +112 -0
  75. package/tests/jest/utils/sharedFunctions.test.ts +121 -0
  76. package/tsconfig.json +3 -4
  77. package/testReporter.js +0 -29
  78. 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
+ });
@@ -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
+ });
@@ -0,0 +1,74 @@
1
+ import * as React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+
4
+ import Timestamp from "../../../src/components/Timestamp";
5
+
6
+ describe("Timestamp", () => {
7
+ const timestamp = {
8
+ service: "test_service",
9
+ id: "1",
10
+ start: "start_time_string",
11
+ duration: "60",
12
+ collection_name: "collection1",
13
+ };
14
+
15
+ describe("rendering", () => {
16
+ it("renders a success panel that is not collapsible", () => {
17
+ const { container } = render(<Timestamp timestamp={timestamp} />);
18
+
19
+ expect(container.querySelector(".panel-success")).toBeInTheDocument();
20
+ expect(container.querySelector(".panel-danger")).not.toBeInTheDocument();
21
+ // A non-collapsible panel is a static panel with no toggle button.
22
+ expect(container.querySelector(".static-panel")).toBeInTheDocument();
23
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
24
+ });
25
+
26
+ it("renders the start time", () => {
27
+ const { container } = render(<Timestamp timestamp={timestamp} />);
28
+
29
+ expect(container.querySelector(".panel-title")).toHaveTextContent(
30
+ "start_time_string"
31
+ );
32
+ });
33
+
34
+ it("renders the duration", () => {
35
+ const { container } = render(<Timestamp timestamp={timestamp} />);
36
+
37
+ expect(container.querySelectorAll("ul li")).toHaveLength(1);
38
+ expect(screen.getByText("Duration: 60 seconds")).toBeInTheDocument();
39
+ });
40
+ });
41
+
42
+ describe("rendering with achievements", () => {
43
+ it("renders achievements", () => {
44
+ const { container } = render(
45
+ <Timestamp timestamp={{ ...timestamp, achievements: "Ran a script" }} />
46
+ );
47
+
48
+ expect(container.querySelectorAll("ul li")).toHaveLength(2);
49
+ const achievements = container.querySelector(".well pre");
50
+ expect(achievements).toBeInTheDocument();
51
+ expect(achievements).toHaveTextContent("Ran a script");
52
+ });
53
+ });
54
+
55
+ describe("rendering with exception", () => {
56
+ it("determines style based on whether there is an exception", () => {
57
+ const { container } = render(
58
+ <Timestamp timestamp={{ ...timestamp, exception: "Stack trace" }} />
59
+ );
60
+
61
+ expect(container.querySelector(".panel-danger")).toBeInTheDocument();
62
+ });
63
+
64
+ it("renders an exception", () => {
65
+ const { container } = render(
66
+ <Timestamp timestamp={{ ...timestamp, exception: "Stack trace" }} />
67
+ );
68
+
69
+ const exception = container.querySelector(".exception pre");
70
+ expect(exception).toBeInTheDocument();
71
+ expect(exception).toHaveTextContent("Stack trace");
72
+ });
73
+ });
74
+ });
@@ -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
+ // The tab content (TroubleshootingCategoryPage) renders the connected
6
+ // Diagnostics/Self-tests containers, which need Redux store + csrf context this
7
+ // test does not supply. That content is incidental here — the test is about the
8
+ // tab navigation — so mock it to a marker.
9
+ jest.mock("../../../src/components/TroubleshootingCategoryPage", () => ({
10
+ __esModule: true,
11
+ default: () => <div data-testid="category-page" />,
12
+ }));
13
+
14
+ import TroubleshootingTabContainer from "../../../src/components/TroubleshootingTabContainer";
15
+
16
+ describe("TroubleshootingTabContainer", () => {
17
+ let goToTab: jest.Mock;
18
+
19
+ beforeEach(() => {
20
+ goToTab = jest.fn();
21
+ });
22
+
23
+ it("renders tabs and defaults to showing the Diagnostics tab", () => {
24
+ const { container } = render(
25
+ <TroubleshootingTabContainer goToTab={goToTab} tab="diagnostics" />
26
+ );
27
+
28
+ const nav = container.querySelector("ul.nav-tabs");
29
+ expect(nav).not.toBeNull();
30
+
31
+ const tabs = nav.querySelectorAll("li");
32
+ expect(tabs).toHaveLength(2);
33
+
34
+ expect(tabs[0]).toHaveTextContent("Diagnostics");
35
+ expect(tabs[0]).toHaveClass("active");
36
+
37
+ expect(tabs[1]).toHaveTextContent("Self-tests");
38
+ expect(tabs[1]).not.toHaveClass("active");
39
+ });
40
+
41
+ it("calls goToTab when another tab is clicked", async () => {
42
+ const user = userEvent.setup();
43
+ render(<TroubleshootingTabContainer goToTab={goToTab} tab="diagnostics" />);
44
+
45
+ await user.click(screen.getByRole("link", { name: "Self-tests" }));
46
+
47
+ expect(goToTab).toHaveBeenCalledTimes(1);
48
+ expect(goToTab).toHaveBeenCalledWith("self-tests");
49
+ });
50
+
51
+ it("switches the active tab when the tab prop changes", () => {
52
+ const { container, rerender } = render(
53
+ <TroubleshootingTabContainer goToTab={goToTab} tab="diagnostics" />
54
+ );
55
+
56
+ let tabs = container.querySelectorAll("ul.nav-tabs li");
57
+ expect(tabs[0]).toHaveClass("active");
58
+ expect(tabs[1]).not.toHaveClass("active");
59
+
60
+ rerender(
61
+ <TroubleshootingTabContainer goToTab={goToTab} tab="self-tests" />
62
+ );
63
+
64
+ tabs = container.querySelectorAll("ul.nav-tabs li");
65
+ expect(tabs[0]).not.toHaveClass("active");
66
+ expect(tabs[1]).toHaveClass("active");
67
+ });
68
+ });
@@ -0,0 +1,36 @@
1
+ import * as React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+
4
+ import UpdatingLoader from "../../../src/components/UpdatingLoader";
5
+
6
+ describe("UpdatingLoader", () => {
7
+ it("renders only its container when not showing", () => {
8
+ const { container } = render(<UpdatingLoader show={false} />);
9
+
10
+ expect(
11
+ container.querySelector(".updating-loader-container")
12
+ ).toBeInTheDocument();
13
+ expect(container.querySelector(".updating-loader")).not.toBeInTheDocument();
14
+ expect(screen.queryByText("Updating")).not.toBeInTheDocument();
15
+ });
16
+
17
+ it("renders the default message when showing", () => {
18
+ render(<UpdatingLoader show={true} />);
19
+
20
+ expect(screen.getByText("Updating")).toBeInTheDocument();
21
+ });
22
+
23
+ it("renders the text it is given instead of the default", () => {
24
+ render(<UpdatingLoader show={true} text="Doing something" />);
25
+
26
+ expect(screen.getByText("Doing something")).toBeInTheDocument();
27
+ expect(screen.queryByText("Updating")).not.toBeInTheDocument();
28
+ });
29
+
30
+ it("renders a spinner", () => {
31
+ const { container } = render(<UpdatingLoader show={true} />);
32
+
33
+ // The spinner is a Font Awesome <i>, which carries no accessible role.
34
+ expect(container.querySelector("i.fa-spinner")).toBeInTheDocument();
35
+ });
36
+ });