@thepalaceproject/circulation-admin 1.43.0-post.9 → 1.44.0
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 +22 -10
- package/README.md +11 -5
- package/dist/circulation-admin.js +1 -1
- package/jest.config.js +11 -44
- package/package.json +1 -5
- package/tests/jest/components/AdvancedSearchBuilder.test.tsx +111 -0
- package/tests/jest/components/Announcement.test.tsx +76 -0
- package/tests/jest/components/AnnouncementForm.test.tsx +229 -0
- package/tests/jest/components/AnnouncementsSection.test.tsx +146 -0
- package/tests/jest/components/Autocomplete.test.tsx +67 -0
- package/tests/jest/components/BookCoverEditor.test.tsx +393 -0
- package/tests/jest/components/BookDetailsEditor.test.tsx +275 -0
- package/tests/jest/components/BookDetailsTabContainer.test.tsx +237 -0
- package/tests/jest/components/BookEditForm.test.tsx +352 -0
- package/tests/jest/components/BookEditor.test.tsx +20 -21
- package/tests/jest/components/CatalogPage.test.tsx +158 -0
- package/tests/jest/components/CatalogServices.test.tsx +38 -1
- package/tests/jest/components/ChangePasswordForm.test.tsx +163 -0
- package/tests/jest/components/Classifications.test.tsx +166 -0
- package/tests/jest/components/ClassificationsForm.test.tsx +458 -0
- package/tests/jest/components/ClassificationsTable.test.tsx +57 -0
- package/tests/jest/components/Collections.test.tsx +335 -7
- package/tests/jest/components/ColorPicker.test.tsx +58 -0
- package/tests/jest/components/ComplaintForm.test.tsx +171 -0
- package/tests/jest/components/Complaints.test.tsx +259 -0
- package/tests/jest/components/ConfigTabContainer.test.tsx +196 -0
- package/tests/jest/components/ContextProvider.test.tsx +138 -0
- package/tests/jest/components/Contributors.test.tsx +157 -0
- package/tests/jest/components/CustomListEditor.test.tsx +367 -0
- package/tests/jest/components/CustomListEntriesEditor.test.tsx +1240 -0
- package/tests/jest/components/CustomLists.test.tsx +621 -4
- package/tests/jest/components/CustomListsForBook.test.tsx +353 -0
- package/tests/jest/components/DiagnosticsServiceTabs.test.tsx +141 -0
- package/tests/jest/components/DiagnosticsServiceType.test.tsx +75 -0
- package/tests/jest/components/DiscoveryServices.test.tsx +154 -7
- package/tests/jest/components/EditableConfigList.test.tsx +598 -7
- package/tests/jest/components/EditableInput.test.tsx +250 -1
- package/tests/jest/components/EditorField.test.tsx +95 -0
- package/tests/jest/components/GenreForm.test.tsx +152 -0
- package/tests/jest/components/Header.test.tsx +421 -0
- package/tests/jest/components/IndividualAdminEditForm.test.tsx +506 -1
- package/tests/jest/components/IndividualAdmins.test.tsx +124 -8
- package/tests/jest/components/InputList.test.tsx +493 -0
- package/tests/jest/components/Lane.test.tsx +132 -10
- package/tests/jest/components/LaneCustomListsEditor.test.tsx +450 -0
- package/tests/jest/components/LaneEditor.test.tsx +377 -9
- package/tests/jest/components/Lanes.test.tsx +446 -0
- package/tests/jest/components/LanesSidebar.test.tsx +621 -0
- package/tests/jest/components/Libraries.test.tsx +48 -0
- package/tests/jest/components/LibraryEditForm.test.tsx +383 -0
- package/tests/jest/components/LibraryRegistration.test.tsx +354 -0
- package/tests/jest/components/LibraryRegistrationForm.test.tsx +203 -0
- package/tests/jest/components/MetadataServices.test.tsx +37 -1
- package/tests/jest/components/NeighborhoodAnalyticsForm.test.tsx +167 -0
- package/tests/jest/components/PairedMenus.test.tsx +220 -0
- package/tests/jest/components/PatronAuthServices.test.tsx +114 -0
- package/tests/jest/components/ProtocolFormField.test.tsx +443 -7
- package/tests/jest/components/ResetAdobeId.test.tsx +302 -0
- package/tests/jest/components/SelfTests.test.tsx +601 -0
- package/tests/jest/components/SelfTestsTabContainer.test.tsx +216 -0
- package/tests/jest/components/ServiceEditForm.test.tsx +1092 -0
- package/tests/jest/components/SitewideAnnouncements.test.tsx +134 -0
- package/tests/jest/components/Stats.test.tsx +0 -7
- package/tests/jest/components/TextWithEditMode.test.tsx +218 -0
- package/tests/jest/components/ToolTip.test.tsx +46 -0
- package/tests/jest/components/TroubleshootingCategoryPage.test.tsx +69 -0
- package/tests/jest/components/TroubleshootingPage.test.tsx +94 -0
- package/tests/jest/features/book.test.ts +75 -80
- package/tests/jest/fixtures/classificationsData.ts +45 -0
- package/tests/jest/fixtures/genreData.ts +811 -0
- package/tests/jest/README.md +0 -6
- package/tests/jest/legacy-setup.ts +0 -13
- package/tests/jest/legacyJsdomEnvironment.js +0 -49
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { installFormDataShim } from "../testUtils/formDataShim";
|
|
3
|
+
import { fireEvent, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
3
5
|
import { DiscoveryServices } from "../../../src/components/DiscoveryServices";
|
|
6
|
+
import DiscoveryServicesConnected from "../../../src/components/DiscoveryServices";
|
|
4
7
|
import renderWithContext from "../testUtils/renderWithContext";
|
|
8
|
+
import { renderWithProviders } from "../testUtils/withProviders";
|
|
9
|
+
import buildStore from "../../../src/store";
|
|
5
10
|
import {
|
|
6
11
|
ConfigurationSettings,
|
|
7
12
|
DiscoveryServicesData,
|
|
8
13
|
} from "../../../src/interfaces";
|
|
9
14
|
import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
|
|
10
15
|
|
|
11
|
-
// NB: This adds tests to the already existing tests in:
|
|
12
|
-
// - `src/components/__tests__/DiscoveryServices-test.tsx`.
|
|
13
|
-
//
|
|
14
|
-
// Those tests should eventually be migrated here and
|
|
15
|
-
// adapted to the Jest/React Testing Library paradigm.
|
|
16
|
-
|
|
17
16
|
describe("DiscoveryServices - registered library disclosure", () => {
|
|
18
17
|
// ── Shared fixtures ───────────────────────────────────────────────────────
|
|
19
18
|
|
|
@@ -543,3 +542,151 @@ describe("DiscoveryServices - registered library disclosure", () => {
|
|
|
543
542
|
expect(container.querySelectorAll(".associated-items")).toHaveLength(0);
|
|
544
543
|
});
|
|
545
544
|
});
|
|
545
|
+
|
|
546
|
+
// These exercise behavior the disclosure tests above do not: the connect()
|
|
547
|
+
// wiring (mapStateToProps / mapDispatchToProps, which only run when the CONNECTED
|
|
548
|
+
// default export mounts) and the getChildContext().registerLibrary closure
|
|
549
|
+
// (which only runs when a library is registered from the edit form).
|
|
550
|
+
|
|
551
|
+
describe("DiscoveryServices - connected wiring and registration", () => {
|
|
552
|
+
const allLibraries = [
|
|
553
|
+
{ short_name: "nypl", name: "NYPL", uuid: "uuid-nypl" },
|
|
554
|
+
];
|
|
555
|
+
|
|
556
|
+
const sysAdminConfig: Partial<ConfigurationSettings> = {
|
|
557
|
+
csrfToken: "",
|
|
558
|
+
featureFlags: defaultFeatureFlags,
|
|
559
|
+
roles: [{ role: "system" }],
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// A loaded `libraries` slice persists through the on-mount discovery fetches
|
|
563
|
+
// (the libraries reducer ignores those actions), so mapStateToProps takes its
|
|
564
|
+
// `data.allLibraries` branch on every render.
|
|
565
|
+
const loadedLibrariesState = {
|
|
566
|
+
data: { libraries: allLibraries },
|
|
567
|
+
isFetching: false,
|
|
568
|
+
isEditing: false,
|
|
569
|
+
fetchError: null,
|
|
570
|
+
formError: null,
|
|
571
|
+
isLoaded: true,
|
|
572
|
+
responseBody: null,
|
|
573
|
+
successMessage: null,
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Stub `fetch` so the panel's on-mount fetches resolve with `body`. A fresh
|
|
578
|
+
* Response per call avoids "body already used" when several fetches run.
|
|
579
|
+
*/
|
|
580
|
+
const stubFetch = (body: unknown) =>
|
|
581
|
+
jest.spyOn(globalThis, "fetch").mockImplementation(
|
|
582
|
+
async () =>
|
|
583
|
+
new Response(JSON.stringify(body), {
|
|
584
|
+
status: 200,
|
|
585
|
+
headers: { "Content-Type": "application/json" },
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
afterEach(() => {
|
|
590
|
+
jest.restoreAllMocks();
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
describe("connected default export", () => {
|
|
594
|
+
it("wires mapStateToProps/mapDispatchToProps: fetches on mount and renders the list", async () => {
|
|
595
|
+
const listData = {
|
|
596
|
+
discovery_services: [
|
|
597
|
+
{ id: 2, protocol: "test protocol", name: "Test Discovery" },
|
|
598
|
+
],
|
|
599
|
+
protocols: [{ name: "test protocol", label: "TP", settings: [] }],
|
|
600
|
+
};
|
|
601
|
+
stubFetch(listData);
|
|
602
|
+
// A fresh store, preloaded with a loaded libraries slice, isolates this
|
|
603
|
+
// test and exercises mapStateToProps' allLibraries branch.
|
|
604
|
+
const store = buildStore({
|
|
605
|
+
editor: { libraries: loadedLibrariesState },
|
|
606
|
+
} as any);
|
|
607
|
+
|
|
608
|
+
const { container } = renderWithProviders(
|
|
609
|
+
<DiscoveryServicesConnected csrfToken="token" />,
|
|
610
|
+
{ reduxProviderProps: { store } }
|
|
611
|
+
);
|
|
612
|
+
|
|
613
|
+
// The list appears once the connected component's on-mount fetch resolves
|
|
614
|
+
// and mapStateToProps feeds the fetched data back in as props.
|
|
615
|
+
expect(
|
|
616
|
+
await screen.findByRole("heading", { level: 3, name: "Test Discovery" })
|
|
617
|
+
).toBeInTheDocument();
|
|
618
|
+
|
|
619
|
+
const editLink = container.querySelector("a.edit-item");
|
|
620
|
+
expect(editLink).not.toBeNull();
|
|
621
|
+
expect(editLink.getAttribute("href")).toBe(
|
|
622
|
+
"/admin/web/config/discovery/edit/2"
|
|
623
|
+
);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
describe("registerLibrary child context (edit mode)", () => {
|
|
628
|
+
// The reusable-components `Form` builds `new FormData(formElement)` on
|
|
629
|
+
// submit, which the unit jsdom env's undici FormData rejects; install the
|
|
630
|
+
// shared shim that reads the form's successful controls.
|
|
631
|
+
installFormDataShim();
|
|
632
|
+
const renderEditMode = (
|
|
633
|
+
registerLibrary: jest.Mock,
|
|
634
|
+
fetchLibraryRegistrations: jest.Mock
|
|
635
|
+
) =>
|
|
636
|
+
renderWithContext(
|
|
637
|
+
<DiscoveryServices
|
|
638
|
+
data={
|
|
639
|
+
{
|
|
640
|
+
discovery_services: [
|
|
641
|
+
{ id: "2", protocol: "test protocol", name: "Test Discovery" },
|
|
642
|
+
],
|
|
643
|
+
protocols: [
|
|
644
|
+
{
|
|
645
|
+
name: "test protocol",
|
|
646
|
+
supports_registration: true,
|
|
647
|
+
settings: [],
|
|
648
|
+
library_settings: [],
|
|
649
|
+
},
|
|
650
|
+
],
|
|
651
|
+
allLibraries,
|
|
652
|
+
} as any
|
|
653
|
+
}
|
|
654
|
+
editOrCreate="edit"
|
|
655
|
+
identifier="2"
|
|
656
|
+
fetchData={jest.fn()}
|
|
657
|
+
editItem={jest.fn().mockResolvedValue(undefined)}
|
|
658
|
+
deleteItem={jest.fn().mockResolvedValue(undefined)}
|
|
659
|
+
registerLibrary={registerLibrary}
|
|
660
|
+
fetchLibraryRegistrations={fetchLibraryRegistrations}
|
|
661
|
+
csrfToken="token"
|
|
662
|
+
isFetching={false}
|
|
663
|
+
/>,
|
|
664
|
+
sysAdminConfig
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
it("fetches library registrations on mount, and registers a library (building the right FormData) and refetches on click", async () => {
|
|
668
|
+
const user = userEvent.setup();
|
|
669
|
+
const registerLibrary = jest.fn().mockResolvedValue(undefined);
|
|
670
|
+
const fetchLibraryRegistrations = jest.fn().mockResolvedValue(undefined);
|
|
671
|
+
renderEditMode(registerLibrary, fetchLibraryRegistrations);
|
|
672
|
+
|
|
673
|
+
// getChildContext supplies registerLibrary to the edit form; the edit form
|
|
674
|
+
// surfaces a "Register" button for each library.
|
|
675
|
+
expect(fetchLibraryRegistrations).toHaveBeenCalledTimes(1);
|
|
676
|
+
expect(registerLibrary).not.toHaveBeenCalled();
|
|
677
|
+
|
|
678
|
+
await user.click(screen.getByRole("button", { name: "Register" }));
|
|
679
|
+
|
|
680
|
+
expect(registerLibrary).toHaveBeenCalledTimes(1);
|
|
681
|
+
const formData = registerLibrary.mock.calls[0][0];
|
|
682
|
+
expect(formData.get("library_short_name")).toBe("nypl");
|
|
683
|
+
expect(formData.get("integration_id")).toBe("2");
|
|
684
|
+
expect(formData.get("registration_stage")).toBe("testing");
|
|
685
|
+
|
|
686
|
+
// After a successful registration, the child context refetches.
|
|
687
|
+
await waitFor(() =>
|
|
688
|
+
expect(fetchLibraryRegistrations).toHaveBeenCalledTimes(2)
|
|
689
|
+
);
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
});
|