diff --git a/api/package.json b/api/package.json index 2ca2edee9..2151d8883 100644 --- a/api/package.json +++ b/api/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "npx tsc", "format": "prettier --check --write *.js src/**", - "lint": "ESLINT_USE_FLAT_CONFIG=true eslint *.js src/ -c eslint.config.mjs --max-warnings 0", + "lint": "prettier --check *.js src/** && ESLINT_USE_FLAT_CONFIG=true eslint *.js src/ -c eslint.config.mjs --max-warnings 0", "start:serverWatch": "nodemon --watch 'vudl.ini' --watch '**/*.ts' --watch '**/*.ejs' --ignore node_modules/ src/server.ts", "start:workerWatch": "nodemon --watch 'vudl.ini' --watch '**/*.ts' src/worker-start.ts", "start:server": "ts-node src/server.ts", diff --git a/client/components/LogoutButton.test.tsx b/client/components/LogoutButton.test.tsx index 06498f9c0..0f2347bb6 100644 --- a/client/components/LogoutButton.test.tsx +++ b/client/components/LogoutButton.test.tsx @@ -2,7 +2,6 @@ import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; import LogoutButton from "./LogoutButton"; const mockUseFetchContext = jest.fn(); @@ -27,20 +26,14 @@ describe("LogoutButton", () => { }); it("renders correctly when logged in", async () => { - let tree; - await renderer.act(async () => { - tree = renderer.create(); - }); - expect(tree.toJSON()).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders correctly when logged out", async () => { fetchValues.state.token = null; - let tree; - await renderer.act(async () => { - tree = renderer.create(); - }); - expect(tree.toJSON()).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("clears the token", async () => { diff --git a/client/components/__snapshots__/LogoutButton.test.tsx.snap b/client/components/__snapshots__/LogoutButton.test.tsx.snap index 0d00f8a7e..5fd696da2 100644 --- a/client/components/__snapshots__/LogoutButton.test.tsx.snap +++ b/client/components/__snapshots__/LogoutButton.test.tsx.snap @@ -1,17 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`LogoutButton renders correctly when logged in 1`] = ` -
- + + + Log Out + +
+ `; -exports[`LogoutButton renders correctly when logged out 1`] = `null`; +exports[`LogoutButton renders correctly when logged out 1`] = ``; diff --git a/client/components/bulk/BulkEditor.test.tsx b/client/components/bulk/BulkEditor.test.tsx index 71948f366..72caf6ddc 100644 --- a/client/components/bulk/BulkEditor.test.tsx +++ b/client/components/bulk/BulkEditor.test.tsx @@ -1,8 +1,6 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import { fireEvent, render, screen } from "@testing-library/react"; -import renderer from "react-test-renderer"; import BulkEditor from "./BulkEditor"; const mockUseEditorContext = jest.fn(); @@ -46,8 +44,8 @@ describe("BulkEditor", () => { }); it("renders", () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("reports failure if it receives bad JSON", async () => { diff --git a/client/components/bulk/__snapshots__/BulkEditor.test.tsx.snap b/client/components/bulk/__snapshots__/BulkEditor.test.tsx.snap index fa61936d3..9bb43a66c 100644 --- a/client/components/bulk/__snapshots__/BulkEditor.test.tsx.snap +++ b/client/components/bulk/__snapshots__/BulkEditor.test.tsx.snap @@ -1,210 +1,184 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`BulkEditor renders 1`] = ` -
- BasicBreadcrumbs -

- Bulk Editor -

-

- Record Selector -

-
+ +
+ BasicBreadcrumbs +

+ Bulk Editor +

+

+ Record Selector +

- + +
+ + +
+
+
+
- -
- +
+ + + + + Result Limit + + +
+
-
-
+ +
+

+ 0 selected. +

+
+    

+ Changes to Apply +

+
+ +
- Result Limit + Choose New License
-
-
- -
-

- 0 selected. -

-
-  

- Changes to Apply -

-
-
- - - - - -
- - - Choose New License - - -
+ Apply Changes +
+

+ Results: +

+
   
-
- -
-

- Results: -

-
-
+
 `;
diff --git a/client/components/edit/Breadcrumbs.test.tsx b/client/components/edit/Breadcrumbs.test.tsx
index b8c296bcc..79c090d71 100644
--- a/client/components/edit/Breadcrumbs.test.tsx
+++ b/client/components/edit/Breadcrumbs.test.tsx
@@ -1,7 +1,5 @@
-import React from "react";
 import { beforeEach, describe, expect, it, jest } from "@jest/globals";
-import { waitFor } from "@testing-library/react";
-import renderer from "react-test-renderer";
+import { render, waitFor } from "@testing-library/react";
 import Breadcrumbs from "./Breadcrumbs";
 import { EditorContextProvider } from "../../context/EditorContext";
 import { FetchContextProvider } from "../../context/FetchContext";
@@ -26,21 +24,18 @@ describe("Breadcrumb", () => {
     });
 
     async function runStandardSnapshotTest(initiallyShallow: boolean) {
-        let tree;
-        await renderer.act(async () => {
-            tree = renderer.create(
-                
-                    
-                        
-                    
-                ,
-            );
-            await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1));
-        });
+        const { asFragment } = render(
+            
+                
+                    
+                
+            ,
+        );
+        await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1));
         expect(lastRequestUrl).toEqual(
             "http://localhost:9000/api/edit/object/foo%3A1234/parents" + (initiallyShallow ? "?shallow=1" : ""),
         );
-        expect(tree.toJSON()).toMatchSnapshot();
+        expect(asFragment()).toMatchSnapshot();
     }
 
     function getObject(pid, title, parents = []) {
@@ -49,14 +44,14 @@ describe("Breadcrumb", () => {
 
     it("renders without a pid", () => {
         props = {};
-        const tree = renderer.create(
+        const { asFragment } = render(
             
                 
                     
                 
             ,
         );
-        expect(tree.toJSON()).toMatchSnapshot();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("renders using ajax-loaded object data (no parents, shallow mode)", async () => {
diff --git a/client/components/edit/CopyPidButton.test.tsx b/client/components/edit/CopyPidButton.test.tsx
index 0d6bed51f..796e80ef8 100644
--- a/client/components/edit/CopyPidButton.test.tsx
+++ b/client/components/edit/CopyPidButton.test.tsx
@@ -1,5 +1,3 @@
-import React from "react";
-import renderer from "react-test-renderer";
 import CopyPidButton from "./CopyPidButton";
 import userEvent from "@testing-library/user-event";
 import { render, screen } from "@testing-library/react";
@@ -13,8 +11,8 @@ jest.mock(
 
 describe("CopyPidButton", () => {
     it("renders", async () => {
-        const tree = renderer.create();
-        expect(tree.toJSON()).toMatchSnapshot();
+        const { asFragment } = render();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("copies text to clipboard", async () => {
diff --git a/client/components/edit/DeleteObjectButton.test.tsx b/client/components/edit/DeleteObjectButton.test.tsx
index ee47f2add..0ba6d94d1 100644
--- a/client/components/edit/DeleteObjectButton.test.tsx
+++ b/client/components/edit/DeleteObjectButton.test.tsx
@@ -1,9 +1,7 @@
-import React from "react";
 import { beforeEach, describe, expect, it, jest } from "@jest/globals";
-import { act } from "react-dom/test-utils";
+import { act } from "react";
 import { render, screen, waitFor } from "@testing-library/react";
 import userEvent from "@testing-library/user-event";
-import renderer from "react-test-renderer";
 import DeleteObjectButton from "./DeleteObjectButton";
 
 const mockUseGlobalContext = jest.fn();
@@ -71,22 +69,16 @@ describe("DeleteObjectButton", () => {
     });
 
     it("renders correctly when data is not loaded", () => {
-        let tree;
-        renderer.act(() => {
-            tree = renderer.create();
-        });
-        expect(tree.toJSON()).toEqual(null);
+        const { asFragment } = render();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("renders correctly when data is loaded", async () => {
         editorValues.state.objectDetailsStorage[pid] = { foo: "bar" };
         fetchContextValues.action.fetchJSON.mockResolvedValue({ numFound: 100 });
-        let tree;
-        renderer.act(() => {
-            tree = renderer.create();
-        });
+        const { asFragment } = render();
         await waitFor(() => expect(fetchContextValues.action.fetchJSON).toHaveBeenCalled());
-        expect(tree.toJSON()).toMatchSnapshot();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("can be aborted via confirm", async () => {
diff --git a/client/components/edit/EditHome.test.tsx b/client/components/edit/EditHome.test.tsx
index 35c42029b..6c7ca9040 100644
--- a/client/components/edit/EditHome.test.tsx
+++ b/client/components/edit/EditHome.test.tsx
@@ -1,7 +1,5 @@
-import React from "react";
 import { describe, expect, it } from "@jest/globals";
-import { waitFor } from "@testing-library/react";
-import renderer from "react-test-renderer";
+import { render, waitFor } from "@testing-library/react";
 import EditHome from "./EditHome";
 
 const mockUseEditorContext = jest.fn();
@@ -28,13 +26,8 @@ describe("EditHome", () => {
         mockUseEditorContext.mockReturnValue(editorValues);
     });
     it("renders", async () => {
-        let tree;
-        await renderer.act(async () => {
-            tree = renderer.create();
-
-            await waitFor(() => expect(editorValues.action.initializeCatalog).toHaveBeenCalled());
-        });
-
-        expect(tree.toJSON()).toMatchSnapshot();
+        const { asFragment } = render();
+        await waitFor(() => expect(editorValues.action.initializeCatalog).toHaveBeenCalled());
+        expect(asFragment()).toMatchSnapshot();
     });
 });
diff --git a/client/components/edit/EditParentsButton.test.tsx b/client/components/edit/EditParentsButton.test.tsx
index c968f5089..6f3bcc768 100644
--- a/client/components/edit/EditParentsButton.test.tsx
+++ b/client/components/edit/EditParentsButton.test.tsx
@@ -1,8 +1,6 @@
-import React from "react";
 import { describe, beforeEach, expect, it, jest } from "@jest/globals";
 import { render, screen } from "@testing-library/react";
 import userEvent from "@testing-library/user-event";
-import renderer from "react-test-renderer";
 import EditParentsButton from "./EditParentsButton";
 
 const mockUseEditorContext = jest.fn();
@@ -40,8 +38,8 @@ describe("EditParentsButton", () => {
     });
 
     it("renders", () => {
-        const tree = renderer.create().toJSON();
-        expect(tree).toMatchSnapshot();
+        const { asFragment } = render();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("sets up modal on click", async () => {
diff --git a/client/components/edit/EditorSnackbar.test.tsx b/client/components/edit/EditorSnackbar.test.tsx
index 351f887b8..0648d4059 100644
--- a/client/components/edit/EditorSnackbar.test.tsx
+++ b/client/components/edit/EditorSnackbar.test.tsx
@@ -1,8 +1,6 @@
-import React from "react";
 import { beforeEach, describe, expect, it, jest } from "@jest/globals";
 import { render, screen } from "@testing-library/react";
 import userEvent from "@testing-library/user-event";
-import renderer from "react-test-renderer";
 import EditorSnackbar from "./EditorSnackbar";
 
 const mockUseGlobalContext = jest.fn();
@@ -32,14 +30,12 @@ describe("EditorSnackbar", () => {
     });
 
     it("renders", () => {
-        const tree = renderer
-            .create(, {
-                createNodeMock: (node: Node) => {
-                    return document.createElement(node.type);
-                },
-            })
-            .toJSON();
-        expect(tree).toMatchSnapshot();
+        const { asFragment } = render(, {
+            createNodeMock: (node: Node) => {
+                return document.createElement(node.type);
+            },
+        });
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("closes", async () => {
diff --git a/client/components/edit/ObjectButtonBar.test.tsx b/client/components/edit/ObjectButtonBar.test.tsx
index 3efa27095..07a094edb 100644
--- a/client/components/edit/ObjectButtonBar.test.tsx
+++ b/client/components/edit/ObjectButtonBar.test.tsx
@@ -1,9 +1,7 @@
-import React from "react";
 import { beforeEach, describe, expect, it, jest } from "@jest/globals";
 import { waitFor } from "@testing-library/react";
 import { render, screen } from "@testing-library/react";
 import userEvent from "@testing-library/user-event";
-import renderer from "react-test-renderer";
 import * as EditorContextModule from "../../context/EditorContext";
 import ObjectButtonBar from "./ObjectButtonBar";
 
@@ -34,8 +32,8 @@ describe("ObjectButtonBar", () => {
     });
 
     it("renders correctly", async () => {
-        const tree = renderer.create().toJSON();
-        expect(tree).toMatchSnapshot();
+        const { asFragment } = render();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("can refresh a list of children", async () => {
diff --git a/client/components/edit/ObjectChildCounts.test.tsx b/client/components/edit/ObjectChildCounts.test.tsx
index 27e9d7d6b..e7ebca1c2 100644
--- a/client/components/edit/ObjectChildCounts.test.tsx
+++ b/client/components/edit/ObjectChildCounts.test.tsx
@@ -1,16 +1,15 @@
-import React from "react";
 import { beforeEach, describe, expect, it, jest } from "@jest/globals";
-import { waitFor } from "@testing-library/react";
-import renderer from "react-test-renderer";
+import { render, waitFor } from "@testing-library/react";
 import { ObjectChildCountsProps, ObjectChildCounts } from "./ObjectChildCounts";
 import { EditorContextProvider, ChildCounts } from "../../context/EditorContext";
 import { FetchContextProvider } from "../../context/FetchContext";
 import { GlobalContextProvider } from "../../context/GlobalContext";
+import { act } from "react";
 
 jest.mock("./ObjectLoader", () => (args) => JSON.stringify(args));
 
 function getMountedObjectChildCountsComponent(props: ObjectChildCountsProps) {
-    return renderer.create(
+    return render(
         
             
                 
@@ -43,12 +42,12 @@ describe("ObjectChildCounts", () => {
     });
 
     it("displays the data found in the response", async () => {
-        let tree;
-        await renderer.act(async () => {
-            tree = getMountedObjectChildCountsComponent(props);
-            await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1));
+        let asFragment;
+        await act(async () => {
+            asFragment = getMountedObjectChildCountsComponent(props).asFragment;
         });
+        await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1));
         expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/childCounts");
-        expect(tree.toJSON()).toMatchSnapshot();
+        expect(asFragment()).toMatchSnapshot();
     });
 });
diff --git a/client/components/edit/ObjectEditor.test.tsx b/client/components/edit/ObjectEditor.test.tsx
index 431ae8dad..6a0049f43 100644
--- a/client/components/edit/ObjectEditor.test.tsx
+++ b/client/components/edit/ObjectEditor.test.tsx
@@ -1,6 +1,5 @@
-import React from "react";
 import { beforeEach, describe, expect, it, jest } from "@jest/globals";
-import renderer from "react-test-renderer";
+import { render } from "@testing-library/react";
 import ObjectEditor from "./ObjectEditor";
 
 const mockUseEditorContext = jest.fn();
@@ -31,14 +30,12 @@ describe("ObjectEditor", () => {
         mockUseEditorContext.mockReturnValue(editorValues);
     });
     it("renders", () => {
-        const tree = renderer.create().toJSON();
-        expect(tree).toMatchSnapshot();
+        const { asFragment } = render();
+        expect(asFragment()).toMatchSnapshot();
     });
 
     it("calls initializeCatalog", () => {
-        renderer.act(() => {
-            renderer.create();
-        });
+        render();
         expect(editorValues.action.initializeCatalog).toHaveBeenCalled();
         expect(editorValues.action.setCurrentPid).toHaveBeenCalledWith("foo:123");
         expect(editorValues.action.loadCurrentObjectDetails).toHaveBeenCalled();
diff --git a/client/components/edit/ObjectEditor.tsx b/client/components/edit/ObjectEditor.tsx
index d12805267..28b3a7104 100644
--- a/client/components/edit/ObjectEditor.tsx
+++ b/client/components/edit/ObjectEditor.tsx
@@ -33,7 +33,11 @@ const ObjectEditor = ({ pid }: ObjectEditorProps): React.ReactElement => {
             

Editor: Object {pid}

- +

Object Tools

    @@ -43,14 +47,17 @@ const ObjectEditor = ({ pid }: ObjectEditorProps): React.ReactElement => {
- +

Datastreams

- diff --git a/client/components/edit/ObjectLoader.test.tsx b/client/components/edit/ObjectLoader.test.tsx index 7d106abd4..564e5b9d7 100644 --- a/client/components/edit/ObjectLoader.test.tsx +++ b/client/components/edit/ObjectLoader.test.tsx @@ -1,7 +1,5 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { render } from "@testing-library/react"; -import renderer from "react-test-renderer"; import ObjectLoader from "./ObjectLoader"; const mockUseEditorContext = jest.fn(); @@ -25,14 +23,14 @@ describe("ObjectLoader", () => { mockUseEditorContext.mockReturnValue(editorValues); }); it("renders correctly for a pending object", () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders correctly for a loaded object", () => { editorValues.state.objectDetailsStorage["foo:123"] = { foo: "bar" }; - const tree = renderer.create().toJSON(); - expect(tree).toBeNull(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("loads the object as needed when optional callback is omitted", () => { diff --git a/client/components/edit/ObjectModels.test.tsx b/client/components/edit/ObjectModels.test.tsx index 4995b585a..f2e6949a4 100644 --- a/client/components/edit/ObjectModels.test.tsx +++ b/client/components/edit/ObjectModels.test.tsx @@ -1,6 +1,5 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import renderer from "react-test-renderer"; +import { render } from "@testing-library/react"; import ObjectModels from "./ObjectModels"; const mockUseEditorContext = jest.fn(); @@ -25,12 +24,12 @@ describe("ObjectModels", () => { editorValues.state.objectDetailsStorage["foo:123"] = { models: ["vudl-system:CoreModel", "vudl-system:CollectionModel", "vudl-system:FolderCollection"], }; - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders nothing when data is missing", async () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/client/components/edit/ObjectOrder.test.tsx b/client/components/edit/ObjectOrder.test.tsx index 00d49c25a..7a3f242b4 100644 --- a/client/components/edit/ObjectOrder.test.tsx +++ b/client/components/edit/ObjectOrder.test.tsx @@ -1,9 +1,7 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import ObjectOrder from "./ObjectOrder"; const mockUseEditorContext = jest.fn(); @@ -24,7 +22,7 @@ describe("ObjectOrder", () => { let editorValues; let fetchContextValues; const pid = "foo:123"; - beforeEach(() => { + beforeEach(async () => { editorValues = { state: { objectDetailsStorage: {}, @@ -34,7 +32,9 @@ describe("ObjectOrder", () => { removeFromObjectDetailsStorage: jest.fn(), }, }; - mockUseEditorContext.mockReturnValue(editorValues); + await act(async () => { + mockUseEditorContext.mockReturnValue(editorValues); + }); fetchContextValues = { action: { fetchJSON: jest.fn(), @@ -48,18 +48,21 @@ describe("ObjectOrder", () => { jest.resetAllMocks(); }); - function checkSnapshot() { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - } - - it("defaults to title order for a pending object", () => { - checkSnapshot(); + it("defaults to title order for a pending object", async () => { + let asFragment; + await act(async () => { + asFragment = render().asFragment; + }); + expect(asFragment()).toMatchSnapshot(); }); - it("displays a custom-sorted object correctly", () => { + it("displays a custom-sorted object correctly", async () => { editorValues.state.objectDetailsStorage[pid] = { pid, sortOn: "custom" }; - checkSnapshot(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; + }); + expect(asFragment()).toMatchSnapshot(); }); it("can be aborted via confirmation dialog", async () => { diff --git a/client/components/edit/ObjectPreviewButton.test.tsx b/client/components/edit/ObjectPreviewButton.test.tsx index 7673b1b38..59640451e 100644 --- a/client/components/edit/ObjectPreviewButton.test.tsx +++ b/client/components/edit/ObjectPreviewButton.test.tsx @@ -2,7 +2,6 @@ import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; import * as EditorContextModule from "../../context/EditorContext"; import ObjectPreviewButton from "./ObjectPreviewButton"; @@ -19,14 +18,15 @@ describe("ObjectPreviewButton", () => { }); it("renders correctly without VuFind URL", async () => { - const tree = renderer.create().toJSON(); - expect(tree).toBeNull(); + render(); + const previewButton = screen.queryByRole("button"); + expect(previewButton).toBeNull(); }); it("renders correctly with VuFind URL", async () => { mockContext.state.vufindUrl = "http://localhost"; - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("can open a VuFind preview URL", async () => { diff --git a/client/components/edit/ObjectStatus.module.css b/client/components/edit/ObjectStatus.module.css index 752f9b9da..8fa771ac6 100644 --- a/client/components/edit/ObjectStatus.module.css +++ b/client/components/edit/ObjectStatus.module.css @@ -9,7 +9,8 @@ .status_btn.active { background-color: var(--object-status-active); - &:hover, &:focus { + &:hover, + &:focus { color: white; background-color: var(--object-status-active-text); border-color: var(--object-status-active-text); @@ -19,7 +20,8 @@ .status_btn.inactive { background-color: var(--object-status-inactive); - &:hover, &:focus { + &:hover, + &:focus { color: white; background-color: var(--object-status-inactive-text); border-color: var(--object-status-inactive-text); @@ -29,7 +31,8 @@ .status_btn.deleted { background-color: var(--object-status-deleted); - &:hover, &:focus { + &:hover, + &:focus { color: white; background-color: var(--object-status-deleted-text); border-color: var(--object-status-deleted-text); @@ -39,7 +42,8 @@ .status_btn.unknown { background-color: var(--object-status-unknown); - &:hover, &:focus { + &:hover, + &:focus { color: white; background-color: var(--object-status-unknown-text); border-color: var(--object-status-unknown-text); diff --git a/client/components/edit/ObjectStatus.test.tsx b/client/components/edit/ObjectStatus.test.tsx index 66e8ce92a..88809a3a3 100644 --- a/client/components/edit/ObjectStatus.test.tsx +++ b/client/components/edit/ObjectStatus.test.tsx @@ -1,14 +1,13 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { waitFor } from "@testing-library/react"; -import renderer from "react-test-renderer"; +import { render, waitFor } from "@testing-library/react"; import { ObjectStatusProps, ObjectStatus } from "./ObjectStatus"; import { EditorContextProvider, ObjectDetails } from "../../context/EditorContext"; import { FetchContextProvider } from "../../context/FetchContext"; import { GlobalContextProvider } from "../../context/GlobalContext"; +import { act } from "react"; function getMountedObjectStatusComponent(props: ObjectStatusProps) { - return renderer.create( + return render( @@ -41,23 +40,23 @@ describe("ObjectStatus", () => { }); it("defaults to unknown state", async () => { - let tree; - await renderer.act(async () => { - tree = getMountedObjectStatusComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + let asFragment; + await act(async () => { + asFragment = getMountedObjectStatusComponent(props).asFragment; }); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/details"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("displays the state found in the response", async () => { response.state = "Inactive"; - let tree; - await renderer.act(async () => { - tree = getMountedObjectStatusComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + let asFragment; + await act(async () => { + asFragment = getMountedObjectStatusComponent(props).asFragment; }); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/details"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/client/components/edit/ObjectSummary.module.css b/client/components/edit/ObjectSummary.module.css index ca95a6355..b5cda245e 100644 --- a/client/components/edit/ObjectSummary.module.css +++ b/client/components/edit/ObjectSummary.module.css @@ -14,7 +14,7 @@ min-width: unset; padding-block: 0.5em 0.4em; - &:not(:hover,:focus) { + &:not(:hover, :focus) { background-color: white; border-color: black; } diff --git a/client/components/edit/ObjectSummary.test.tsx b/client/components/edit/ObjectSummary.test.tsx index 4295c49ff..2f6374ea7 100644 --- a/client/components/edit/ObjectSummary.test.tsx +++ b/client/components/edit/ObjectSummary.test.tsx @@ -1,8 +1,8 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import renderer from "react-test-renderer"; +import { render } from "@testing-library/react"; import ObjectSummary from "./ObjectSummary"; import { updateRecentPidsCatalog } from "../../util/RecentPidsCatalog"; +import { act } from "react"; const mockUseEditorContext = jest.fn(); jest.mock("../../context/EditorContext", () => ({ @@ -37,12 +37,12 @@ describe("ObjectSummary", () => { it("displays loading message when appropriate", async () => { jest.spyOn(editorValues.action, "extractFirstMetadataValue").mockReturnValue(""); const loadSpy = jest.spyOn(editorValues.action, "loadCurrentObjectDetails"); - let tree; - renderer.act(() => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); - expect(tree.toJSON()).toMatchSnapshot(); expect(loadSpy).toHaveBeenCalledTimes(1); + expect(asFragment()).toMatchSnapshot(); }); it("renders information from metadata when available", async () => { @@ -56,15 +56,15 @@ describe("ObjectSummary", () => { .spyOn(editorValues.action, "extractFirstMetadataValue") .mockReturnValueOnce("My title") .mockReturnValueOnce("

Hello world!

"); - let tree; - renderer.act(() => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); expect(metaSpy).toHaveBeenCalledTimes(2); expect(metaSpy).toHaveBeenNthCalledWith(1, "dc:title", "Title not available"); expect(metaSpy).toHaveBeenNthCalledWith(2, "dc:description", ""); - expect(tree.toJSON()).toMatchSnapshot(); // Expected side-effect: register that PID has been recently viewed: expect(updateRecentPidsCatalog).toHaveBeenCalledWith("foo:123", "My title"); + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/client/components/edit/ObjectThumbnail.test.tsx b/client/components/edit/ObjectThumbnail.test.tsx index 676a80cc9..b255ec836 100644 --- a/client/components/edit/ObjectThumbnail.test.tsx +++ b/client/components/edit/ObjectThumbnail.test.tsx @@ -1,6 +1,5 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import renderer from "react-test-renderer"; +import { render } from "@testing-library/react"; import ObjectThumbnail from "./ObjectThumbnail"; const mockUseEditorContext = jest.fn(); @@ -24,14 +23,14 @@ describe("ObjectThumbnail", () => { }); it("displays unavailable message when appropriate", async () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders thumbnail when available", async () => { editorValues.state.vufindUrl = "http://localhost"; editorValues.state.objectDetailsStorage[pid] = { datastreams: ["THUMBNAIL"] }; - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/client/components/edit/PidPicker.test.tsx b/client/components/edit/PidPicker.test.tsx index 302b787d0..948642de2 100644 --- a/client/components/edit/PidPicker.test.tsx +++ b/client/components/edit/PidPicker.test.tsx @@ -2,7 +2,6 @@ import React from "react"; import { describe, beforeEach, expect, it, jest } from "@jest/globals"; import { fireEvent, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; import PidPicker from "./PidPicker"; import { Parent } from "./PidPicker"; import { getRecentPidsCatalog } from "../../util/RecentPidsCatalog"; @@ -28,8 +27,8 @@ describe("PidPicker", () => { }; const checkSnapshot = (selected = "", parents: Array = []) => { - const tree = renderer.create(getPicker(selected, parents)).toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(getPicker(selected, parents)); + expect(asFragment()).toMatchSnapshot(); }; beforeEach(() => { diff --git a/client/components/edit/StateModal.test.tsx b/client/components/edit/StateModal.test.tsx index 75719efea..657ffc256 100644 --- a/client/components/edit/StateModal.test.tsx +++ b/client/components/edit/StateModal.test.tsx @@ -1,9 +1,7 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; import StateModal from "./StateModal"; const mockUseGlobalContext = jest.fn(); @@ -85,47 +83,47 @@ describe("StateModal", () => { jest.resetAllMocks(); }); - it("renders correctly when closed", () => { + it("renders correctly when closed", async () => { globalValues.action.isModalOpen.mockReturnValue(false); - let tree; - renderer.act(() => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); expect(globalValues.action.isModalOpen).toHaveBeenCalledWith("state"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); - it("renders correctly for a pending object", () => { - let tree; - renderer.act(() => { - tree = renderer.create(); + it("renders correctly for a pending object", async () => { + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); expect(globalValues.action.isModalOpen).toHaveBeenCalledWith("state"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders correctly for a loaded object with children", async () => { editorValues.state.objectDetailsStorage[pid] = { pid, state: "Active" }; fetchContextValues.action.fetchJSON.mockResolvedValue({ numFound: 100 }); - let tree; - await renderer.act(async () => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); await waitFor(() => expect(fetchContextValues.action.fetchJSON).toHaveBeenCalled()); expect(globalValues.action.isModalOpen).toHaveBeenCalledWith("state"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders correctly for a loaded object without children", async () => { editorValues.state.objectDetailsStorage[pid] = { pid, state: "Active" }; fetchContextValues.action.fetchJSON.mockResolvedValue({ numFound: 0 }); - let tree; - await renderer.act(async () => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); await waitFor(() => expect(fetchContextValues.action.fetchJSON).toHaveBeenCalled()); expect(globalValues.action.isModalOpen).toHaveBeenCalledWith("state"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("saves data correctly", async () => { diff --git a/client/components/edit/StateModal.tsx b/client/components/edit/StateModal.tsx index 9e130f9cf..a3f15f033 100644 --- a/client/components/edit/StateModal.tsx +++ b/client/components/edit/StateModal.tsx @@ -109,7 +109,7 @@ const StateModal = (): React.ReactElement => {

{statusMessage}

) : ( - + State { - - {childrenCheckbox} - - + {childrenCheckbox} + @@ -136,10 +134,8 @@ const StateModal = (): React.ReactElement => { - - State Editor ({stateModalActivePid}) - - + State Editor ({stateModalActivePid}) + diff --git a/client/components/edit/__snapshots__/Breadcrumbs.test.tsx.snap b/client/components/edit/__snapshots__/Breadcrumbs.test.tsx.snap index 22d02b6b1..7dfee4517 100644 --- a/client/components/edit/__snapshots__/Breadcrumbs.test.tsx.snap +++ b/client/components/edit/__snapshots__/Breadcrumbs.test.tsx.snap @@ -1,193 +1,141 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Breadcrumb renders using ajax-loaded object data (deep parent chain) 1`] = ` - + + + `; exports[`Breadcrumb renders using ajax-loaded object data (many parents, deep mode) 1`] = ` -[ + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , -] + + `; exports[`Breadcrumb renders using ajax-loaded object data (many parents, shallow mode) 1`] = ` -[ + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , -] + + `; exports[`Breadcrumb renders using ajax-loaded object data (multiple parents with common grandparent) 1`] = ` -[ + , + , -] + + `; exports[`Breadcrumb renders using ajax-loaded object data (no parents, deep mode) 1`] = ` - + + + `; exports[`Breadcrumb renders using ajax-loaded object data (no parents, shallow mode) 1`] = ` - + + + Loading... + + `; exports[`Breadcrumb renders using ajax-loaded object data (simple case, deep mode) 1`] = ` - + + + `; exports[`Breadcrumb renders using ajax-loaded object data (simple case, shallow mode) 1`] = ` - + + + `; exports[`Breadcrumb renders without a pid 1`] = ` - + + + `; diff --git a/client/components/edit/__snapshots__/CopyPidButton.test.tsx.snap b/client/components/edit/__snapshots__/CopyPidButton.test.tsx.snap index 40eab7c8f..c6b005f15 100644 --- a/client/components/edit/__snapshots__/CopyPidButton.test.tsx.snap +++ b/client/components/edit/__snapshots__/CopyPidButton.test.tsx.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`CopyPidButton renders 1`] = ` - + + + `; diff --git a/client/components/edit/__snapshots__/DeleteObjectButton.test.tsx.snap b/client/components/edit/__snapshots__/DeleteObjectButton.test.tsx.snap index cfcd3a8e3..2ea1d4226 100644 --- a/client/components/edit/__snapshots__/DeleteObjectButton.test.tsx.snap +++ b/client/components/edit/__snapshots__/DeleteObjectButton.test.tsx.snap @@ -1,10 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DeleteObjectButton renders correctly when data is loaded 1`] = ` - + + + `; + +exports[`DeleteObjectButton renders correctly when data is not loaded 1`] = ``; diff --git a/client/components/edit/__snapshots__/EditHome.test.tsx.snap b/client/components/edit/__snapshots__/EditHome.test.tsx.snap index 5dbff990a..832bdc384 100644 --- a/client/components/edit/__snapshots__/EditHome.test.tsx.snap +++ b/client/components/edit/__snapshots__/EditHome.test.tsx.snap @@ -1,32 +1,28 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`EditHome renders 1`] = ` -
- Breadcrumbs -

- Editor -

-

- Tools -

- -

- Contents -

- ParentsModal - StateModal - ChildList - EditorSnackbar -
+ +
+ Breadcrumbs +

+ Editor +

+

+ Tools +

+ +

+ Contents +

+ ParentsModalStateModalChildListEditorSnackbar +
+
`; diff --git a/client/components/edit/__snapshots__/EditParentsButton.test.tsx.snap b/client/components/edit/__snapshots__/EditParentsButton.test.tsx.snap index ccb25102a..2b36a1bfc 100644 --- a/client/components/edit/__snapshots__/EditParentsButton.test.tsx.snap +++ b/client/components/edit/__snapshots__/EditParentsButton.test.tsx.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`EditParentsButton renders 1`] = ` - + + + `; diff --git a/client/components/edit/__snapshots__/EditorSnackbar.test.tsx.snap b/client/components/edit/__snapshots__/EditorSnackbar.test.tsx.snap index f9a3bb836..3552eaf2a 100644 --- a/client/components/edit/__snapshots__/EditorSnackbar.test.tsx.snap +++ b/client/components/edit/__snapshots__/EditorSnackbar.test.tsx.snap @@ -1,88 +1,60 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`EditorSnackbar renders 1`] = ` -
+
- +
`; diff --git a/client/components/edit/__snapshots__/ObjectButtonBar.test.tsx.snap b/client/components/edit/__snapshots__/ObjectButtonBar.test.tsx.snap index 76bc51279..9fdbdad3f 100644 --- a/client/components/edit/__snapshots__/ObjectButtonBar.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectButtonBar.test.tsx.snap @@ -1,20 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectButtonBar renders correctly 1`] = ` -
- ObjectStatus - EditParentsButton - - ObjectPreviewButton - DeleteObjectButton -
+ ObjectStatusEditParentsButton + + ObjectPreviewButtonDeleteObjectButton + + `; diff --git a/client/components/edit/__snapshots__/ObjectChildCounts.test.tsx.snap b/client/components/edit/__snapshots__/ObjectChildCounts.test.tsx.snap index 55fbad747..bf1dbc4c9 100644 --- a/client/components/edit/__snapshots__/ObjectChildCounts.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectChildCounts.test.tsx.snap @@ -1,14 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectChildCounts displays the data found in the response 1`] = ` -[ - "{"pid":"foo:123"}", + + {"pid":"foo:123"}
- 5 - children, - 100 - descendants -
, - ",", -] + 5 children, 100 descendants + + , +
`; diff --git a/client/components/edit/__snapshots__/ObjectEditor.test.tsx.snap b/client/components/edit/__snapshots__/ObjectEditor.test.tsx.snap index 678bfcda0..ea815f259 100644 --- a/client/components/edit/__snapshots__/ObjectEditor.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectEditor.test.tsx.snap @@ -1,59 +1,54 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectEditor renders 1`] = ` -
- Breadcrumbs -

- Editor: Object - foo:123 -

- ObjectSummary -
+ +
+ Breadcrumbs +

+ Editor: Object foo:123 +

+ ObjectSummary
-

- Object Tools -

- +
+

+ Object Tools +

+ +
-
-
-

- Datastreams -

- DatastreamList +
+

+ Datastreams +

+ DatastreamList +
+ DatastreamModalParentsModalStateModal +

+ Contents +

+ ChildListEditorSnackbar
- DatastreamModal - ParentsModal - StateModal -

- Contents -

- ChildList - EditorSnackbar -
+ `; diff --git a/client/components/edit/__snapshots__/ObjectLoader.test.tsx.snap b/client/components/edit/__snapshots__/ObjectLoader.test.tsx.snap index 5ea83f617..51f763bf5 100644 --- a/client/components/edit/__snapshots__/ObjectLoader.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectLoader.test.tsx.snap @@ -1,32 +1,28 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ObjectLoader renders correctly for a loaded object 1`] = ``; + exports[`ObjectLoader renders correctly for a pending object 1`] = ` -[ - " ", + +   - , -] + + `; diff --git a/client/components/edit/__snapshots__/ObjectModels.test.tsx.snap b/client/components/edit/__snapshots__/ObjectModels.test.tsx.snap index 2fc671aa7..37b0c69ad 100644 --- a/client/components/edit/__snapshots__/ObjectModels.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectModels.test.tsx.snap @@ -1,40 +1,34 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectModels renders models 1`] = ` -
- - Models: - -
    -
  • - CollectionModel -
  • -
  • - CoreModel -
  • -
  • - FolderCollection -
  • -
-
+ +
+ + Models: + +
    +
  • + CollectionModel +
  • +
  • + CoreModel +
  • +
  • + FolderCollection +
  • +
+
+
`; -exports[`ObjectModels renders nothing when data is missing 1`] = `
`; +exports[`ObjectModels renders nothing when data is missing 1`] = ` + +
+ +`; diff --git a/client/components/edit/__snapshots__/ObjectOrder.test.tsx.snap b/client/components/edit/__snapshots__/ObjectOrder.test.tsx.snap index d8b597aa3..467c02d2d 100644 --- a/client/components/edit/__snapshots__/ObjectOrder.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectOrder.test.tsx.snap @@ -1,29 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectOrder defaults to title order for a pending object 1`] = ` -
- Current sort: - title -   - -
+ +
+ Current sort: title  + +
+
`; exports[`ObjectOrder displays a custom-sorted object correctly 1`] = ` -
- Current sort: - custom -   - -
+ +
+ Current sort: custom  + +
+
`; diff --git a/client/components/edit/__snapshots__/ObjectPreviewButton.test.tsx.snap b/client/components/edit/__snapshots__/ObjectPreviewButton.test.tsx.snap index a158c9083..896a7f854 100644 --- a/client/components/edit/__snapshots__/ObjectPreviewButton.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectPreviewButton.test.tsx.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectPreviewButton renders correctly with VuFind URL 1`] = ` - + + + `; diff --git a/client/components/edit/__snapshots__/ObjectStatus.test.tsx.snap b/client/components/edit/__snapshots__/ObjectStatus.test.tsx.snap index 79ce7af0a..a8394565e 100644 --- a/client/components/edit/__snapshots__/ObjectStatus.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectStatus.test.tsx.snap @@ -1,57 +1,53 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectStatus defaults to unknown state 1`] = ` -[ + , - ",", -] +  Unknown + + , + `; exports[`ObjectStatus displays the state found in the response 1`] = ` -[ + , - ",", -] +  Inactive + + , + `; diff --git a/client/components/edit/__snapshots__/ObjectSummary.test.tsx.snap b/client/components/edit/__snapshots__/ObjectSummary.test.tsx.snap index efa42b9ca..6cff8b1b0 100644 --- a/client/components/edit/__snapshots__/ObjectSummary.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectSummary.test.tsx.snap @@ -1,83 +1,58 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectSummary displays loading message when appropriate 1`] = ` -
+
- ObjectThumbnail +
+ ObjectThumbnail +
+

+ Loading... +

+
+ PID: foo:123 CopyPidButton +
-

- Loading... -

-
- PID: - foo:123 - - CopyPidButton -
-
+ `; exports[`ObjectSummary renders information from metadata when available 1`] = ` -
+
- ObjectThumbnail - ObjectModels +
+ ObjectThumbnailObjectModels +
+

+ My title +

+
+

+ Hello + + world + + ! +

+
+
+ ObjectButtonBar +
+ ObjectOrderObjectChildCountsPID: foo:123 CopyPidButton +
-

- My title -

-
-

- Hello - - world - - ! -

-
-
- ObjectButtonBar -
- ObjectOrder - ObjectChildCounts - PID: - foo:123 - - CopyPidButton -
-
+ `; diff --git a/client/components/edit/__snapshots__/ObjectThumbnail.test.tsx.snap b/client/components/edit/__snapshots__/ObjectThumbnail.test.tsx.snap index f9d020471..599d233d0 100644 --- a/client/components/edit/__snapshots__/ObjectThumbnail.test.tsx.snap +++ b/client/components/edit/__snapshots__/ObjectThumbnail.test.tsx.snap @@ -1,19 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ObjectThumbnail displays unavailable message when appropriate 1`] = ` - - No Thumbnail - + + + No Thumbnail + + `; exports[`ObjectThumbnail renders thumbnail when available 1`] = ` - + + + `; diff --git a/client/components/edit/__snapshots__/PidPicker.test.tsx.snap b/client/components/edit/__snapshots__/PidPicker.test.tsx.snap index 21dbc2c61..c48851acc 100644 --- a/client/components/edit/__snapshots__/PidPicker.test.tsx.snap +++ b/client/components/edit/__snapshots__/PidPicker.test.tsx.snap @@ -1,57 +1,50 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`PidPicker renders correctly with a selected PID 1`] = ` -[ - "Selected pid: ", - "selected:123", - ". ", - , -] + + `; exports[`PidPicker renders correctly with favorite PIDs 1`] = ` -[ +
- AccordionSummary: "Enter PID manually" +

+ AccordionSummary: "Enter PID manually" +

-
@@ -59,31 +52,32 @@ exports[`PidPicker renders correctly with favorite PIDs 1`] = `
-
, +
- AccordionSummary: "Choose PID from Tree" +

+ AccordionSummary: "Choose PID from Tree" +

ChildList
@@ -91,44 +85,41 @@ exports[`PidPicker renders correctly with favorite PIDs 1`] = `
-
, +
- AccordionSummary: "Choose PID from Favorites" +

+ AccordionSummary: "Choose PID from Favorites" +

  • -
  • -
  • @@ -138,49 +129,46 @@ exports[`PidPicker renders correctly with favorite PIDs 1`] = `
-
, -] +
+ `; exports[`PidPicker renders correctly with parents 1`] = ` -[ +
- AccordionSummary: "Enter PID manually" +

+ AccordionSummary: "Enter PID manually" +

-
@@ -188,31 +176,32 @@ exports[`PidPicker renders correctly with parents 1`] = `
-
, +
- AccordionSummary: "Choose PID from Tree" +

+ AccordionSummary: "Choose PID from Tree" +

ChildList
@@ -220,31 +209,32 @@ exports[`PidPicker renders correctly with parents 1`] = `
-
, +
- AccordionSummary: ["Choose PID from Parent (","Foo",")"] +

+ AccordionSummary: ["Choose PID from Parent (","Foo",")"] +

ChildList
@@ -252,31 +242,32 @@ exports[`PidPicker renders correctly with parents 1`] = `
-
, +
- AccordionSummary: ["Choose PID from Parent (","Bar",")"] +

+ AccordionSummary: ["Choose PID from Parent (","Bar",")"] +

ChildList
@@ -284,44 +275,41 @@ exports[`PidPicker renders correctly with parents 1`] = `
-
, +
- AccordionSummary: "Choose PID from Favorites" +

+ AccordionSummary: "Choose PID from Favorites" +

  • -
  • -
  • @@ -331,49 +319,46 @@ exports[`PidPicker renders correctly with parents 1`] = `
-
, -] +
+ `; exports[`PidPicker renders correctly with recent PIDs 1`] = ` -[ +
- AccordionSummary: "Enter PID manually" +

+ AccordionSummary: "Enter PID manually" +

-
@@ -381,31 +366,32 @@ exports[`PidPicker renders correctly with recent PIDs 1`] = `
-
, +
- AccordionSummary: "Choose PID from Tree" +

+ AccordionSummary: "Choose PID from Tree" +

ChildList
@@ -413,44 +399,41 @@ exports[`PidPicker renders correctly with recent PIDs 1`] = `
-
, +
- AccordionSummary: "Choose PID from Favorites" +

+ AccordionSummary: "Choose PID from Favorites" +

  • -
  • -
  • @@ -460,44 +443,41 @@ exports[`PidPicker renders correctly with recent PIDs 1`] = `
-
, +
- AccordionSummary: "Choose PID from Recently Viewed" +

+ AccordionSummary: "Choose PID from Recently Viewed" +

  • -
  • -
  • @@ -507,49 +487,46 @@ exports[`PidPicker renders correctly with recent PIDs 1`] = `
-
, -] +
+ `; exports[`PidPicker renders correctly without favorite PIDs 1`] = ` -[ +
- AccordionSummary: "Enter PID manually" +

+ AccordionSummary: "Enter PID manually" +

-
@@ -557,31 +534,32 @@ exports[`PidPicker renders correctly without favorite PIDs 1`] = `
-
, +
- AccordionSummary: "Choose PID from Tree" +

+ AccordionSummary: "Choose PID from Tree" +

ChildList
@@ -589,6 +567,6 @@ exports[`PidPicker renders correctly without favorite PIDs 1`] = `
-
, -] +
+
`; diff --git a/client/components/edit/__snapshots__/StateModal.test.tsx.snap b/client/components/edit/__snapshots__/StateModal.test.tsx.snap index 8222bb942..cc97d98cc 100644 --- a/client/components/edit/__snapshots__/StateModal.test.tsx.snap +++ b/client/components/edit/__snapshots__/StateModal.test.tsx.snap @@ -1,86 +1,48 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`StateModal renders correctly for a loaded object with children 1`] = ` -[ - "Dialog", - "open", - "State Editor (", - "foo:123", - ")", + + DialogopenState Editor (foo:123) , - "{"pid":"foo:123"}", + + {"pid":"foo:123"}
-
, +
-
, -
+ , -] + +
`; exports[`StateModal renders correctly for a loaded object without children 1`] = ` -[ - "Dialog", - "open", - "State Editor (", - "foo:123", - ")", + + DialogopenState Editor (foo:123) , - "{"pid":"foo:123"}", + + {"pid":"foo:123"}
-
, -
+ , -] + +
`; exports[`StateModal renders correctly for a pending object 1`] = ` -[ - "Dialog", - "open", - "State Editor (", - "foo:123", - ")", + + DialogopenState Editor (foo:123) , - "{"pid":"foo:123"}", + + {"pid":"foo:123"}
-
, +

Loading... -

, - , -] + +
`; exports[`StateModal renders correctly when closed 1`] = ` -[ - "Dialog", - "closed", - "State Editor (", - "foo:123", - ")", + + DialogclosedState Editor (foo:123) , - "{"pid":"foo:123"}", + + {"pid":"foo:123"}
-
, +

Loading... -

, - , -] + +
`; diff --git a/client/components/edit/children/Child.test.tsx b/client/components/edit/children/Child.test.tsx index 4d7196419..b39981514 100644 --- a/client/components/edit/children/Child.test.tsx +++ b/client/components/edit/children/Child.test.tsx @@ -1,8 +1,6 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { render, screen, waitFor } from "@testing-library/react"; -import renderer from "react-test-renderer"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import userEvent from "@testing-library/user-event"; import { ChildProps, Child } from "./Child"; import { EditorContextProvider, ObjectDetails } from "../../../context/EditorContext"; @@ -60,58 +58,58 @@ describe("Child", () => { }); it("renders using ajax-loaded data", async () => { - let tree; - await renderer.act(async () => { - tree = renderer.create(getChildComponent(props)); + let asFragment; + await act(async () => { + asFragment = render(getChildComponent(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/details"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders a thumbnail", async () => { props.thumbnail = true; - let tree; - await renderer.act(async () => { - tree = renderer.create(getChildComponent(props)); + let asFragment; + await act(async () => { + asFragment = render(getChildComponent(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/details"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders child counts", async () => { props.showChildCounts = true; - let tree; - await renderer.act(async () => { - tree = renderer.create(getChildComponent(props)); + let asFragment; + await act(async () => { + asFragment = render(getChildComponent(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/details"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders thumbnail and child counts", async () => { props.thumbnail = true; props.showChildCounts = true; - let tree; - await renderer.act(async () => { - tree = renderer.create(getChildComponent(props)); + let asFragment; + await act(async () => { + asFragment = render(getChildComponent(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/details"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("handles empty titles appropriately", async () => { props.initialTitle = ""; response.metadata = {}; - let tree; - await renderer.act(async () => { - tree = renderer.create(getChildComponent(props)); + let asFragment; + await act(async () => { + asFragment = render(getChildComponent(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("can be expanded to show children", async () => { diff --git a/client/components/edit/children/Child.tsx b/client/components/edit/children/Child.tsx index 4ca6b3f17..555123cae 100644 --- a/client/components/edit/children/Child.tsx +++ b/client/components/edit/children/Child.tsx @@ -62,7 +62,7 @@ export const Child = ({ ) : null; const hasExtraTools = thumbnail || models || showChildCounts; const extraTools = hasExtraTools ? ( - + {thumbnail ? : ""} {showChildCounts ? : ""} {models ? : ""} @@ -71,18 +71,18 @@ export const Child = ({ return (
- + {expandControl} {loaded && parentPid ? : ""} {title || "(no title)"} {extraTools} - + {pid} - + - + {loaded ? : ""} diff --git a/client/components/edit/children/ChildList.test.tsx b/client/components/edit/children/ChildList.test.tsx index 4cd0e5b9e..baf17fa08 100644 --- a/client/components/edit/children/ChildList.test.tsx +++ b/client/components/edit/children/ChildList.test.tsx @@ -1,7 +1,7 @@ -import React from "react"; +import { act } from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { waitFor } from "@testing-library/react"; -import renderer from "react-test-renderer"; +import { render, screen, waitFor } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; import { ChildListProps, ChildList } from "./ChildList"; import { EditorContextProvider } from "../../../context/EditorContext"; import { FetchContextProvider } from "../../../context/FetchContext"; @@ -11,7 +11,7 @@ jest.mock("./Child", () => () => "Child"); jest.mock("./SelectableChild", () => () => "SelectableChild"); function getMountedChildListComponent(props: ChildListProps) { - return renderer.create( + return render( @@ -41,69 +41,68 @@ describe("ChildList", () => { }); it("renders using ajax-loaded root data", async () => { - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("allows thumbnails to be toggled on", async () => { - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); - expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); - tree.root - .find((element) => { - return element?.children[0] === "Show Thumbnails"; - }) - .props.onClick(); + const user = userEvent.setup(); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); - expect(tree.toJSON()).toMatchSnapshot(); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); + const thumbnailsButton = await waitFor(() => screen.getByRole("button", { name: /show thumbnails/i })); + await user.click(thumbnailsButton); + expect(screen.getByRole("button", { name: /hide thumbnails/i })).toBeInTheDocument(); + expect(asFragment()).toMatchSnapshot(); }); it("allows models to be toggled on", async () => { - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); - expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); - tree.root - .find((element) => { - return element?.children[0] === "Show Models"; - }) - .props.onClick(); + const user = userEvent.setup(); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); - expect(tree.toJSON()).toMatchSnapshot(); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); + const modelsButton = await waitFor(() => screen.getByRole("button", { name: /show models/i })); + await user.click(modelsButton); + expect(screen.getByRole("button", { name: /hide models/i })).toBeInTheDocument(); + expect(asFragment()).toMatchSnapshot(); }); it("allows child counts to be toggled on", async () => { - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); - expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); - tree.root - .find((element) => { - return element?.children[0] === "Show Child Counts"; - }) - .props.onClick(); + const user = userEvent.setup(); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); - expect(tree.toJSON()).toMatchSnapshot(); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); + const childCountsButton = await waitFor(() => screen.getByRole("button", { name: /show child counts/i })); + await user.click(childCountsButton); + expect(screen.getByRole("button", { name: /hide child counts/i })).toBeInTheDocument(); + expect(asFragment()).toMatchSnapshot(); }); it("renders using SelectableChild when a callback is provided", async () => { props.selectCallback = jest.fn(); - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); - expect(tree.toJSON()).toMatchSnapshot(); + await waitFor(() => expect(screen.getByText("SelectableChild")).toBeInTheDocument()); + expect(screen.queryByText("Child")).not.toBeInTheDocument(); + expect(asFragment()).toMatchSnapshot(); }); it("displays a paginator when appropriate", async () => { @@ -125,23 +124,23 @@ describe("ChildList", () => { { id: "foo:133", title: "hello10" }, ], }; - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/topLevelObjects?start=0&rows=10"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders using ajax-loaded object data", async () => { props.pid = "foo:123"; - let tree; - await renderer.act(async () => { - tree = getMountedChildListComponent(props); - await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); + let asFragment; + await act(async () => { + asFragment = getMountedChildListComponent(props).asFragment; }); + await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1)); expect(lastRequestUrl).toEqual("http://localhost:9000/api/edit/object/foo%3A123/children?start=0&rows=10"); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/client/components/edit/children/ChildList.tsx b/client/components/edit/children/ChildList.tsx index b646e5a08..8df400218 100644 --- a/client/components/edit/children/ChildList.tsx +++ b/client/components/edit/children/ChildList.tsx @@ -135,16 +135,10 @@ export const ChildList = ({ return (
- - {paginatorLabel} - - - {paginator} - - -   - - + {paginatorLabel} + {paginator} +   + {thumbsButton} {modelsButton} {childButton} diff --git a/client/components/edit/children/ChildPosition.test.tsx b/client/components/edit/children/ChildPosition.test.tsx index 3783ff46b..280765a1a 100644 --- a/client/components/edit/children/ChildPosition.test.tsx +++ b/client/components/edit/children/ChildPosition.test.tsx @@ -1,8 +1,6 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import { fireEvent, render, screen } from "@testing-library/react"; -import renderer from "react-test-renderer"; import ChildPosition from "./ChildPosition"; const mockUseEditorContext = jest.fn(); @@ -46,24 +44,24 @@ describe("ChildPosition", () => { it("renders correctly when no sort or sequence exists", () => { editorValues.state.objectDetailsStorage[pid] = { pid }; editorValues.state.objectDetailsStorage[parentPid] = { pid: parentPid }; - const tree = renderer.create().toJSON(); - expect(tree).toBeNull(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders correctly when a sequence exists and parent is not custom sorted", () => { const sequences = [`${parentPid}#73`]; editorValues.state.objectDetailsStorage[pid] = { pid, sequences }; editorValues.state.objectDetailsStorage[parentPid] = { pid: parentPid, sortOn: "title" }; - const tree = renderer.create().toJSON(); - expect(tree).toBeNull(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders correctly when a sequence exists and parent is custom sorted", () => { const sequences = [`${parentPid}#73`]; editorValues.state.objectDetailsStorage[pid] = { pid, sequences }; editorValues.state.objectDetailsStorage[parentPid] = { pid: parentPid, sortOn: "custom" }; - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("saves changes when the input is changed", async () => { diff --git a/client/components/edit/children/SelectableChild.test.tsx b/client/components/edit/children/SelectableChild.test.tsx index 525edd98d..6fe7f23d5 100644 --- a/client/components/edit/children/SelectableChild.test.tsx +++ b/client/components/edit/children/SelectableChild.test.tsx @@ -1,8 +1,6 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; import { SelectableChildProps, SelectableChild } from "./SelectableChild"; jest.mock("./ChildList", () => () => "ChildList"); @@ -27,8 +25,8 @@ describe("SelectableChild", () => { }); function checkSnapshot() { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); } it("renders using provided default data", async () => { diff --git a/client/components/edit/children/__snapshots__/Child.test.tsx.snap b/client/components/edit/children/__snapshots__/Child.test.tsx.snap index bb5ad869c..b32bc0c20 100644 --- a/client/components/edit/children/__snapshots__/Child.test.tsx.snap +++ b/client/components/edit/children/__snapshots__/Child.test.tsx.snap @@ -1,327 +1,291 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Child handles empty titles appropriately 1`] = ` -
+
- - + + + + Expand Tree + + + + + - - - Expand Tree - - - - - +
+ -
- foo:123 -
-
- CopyPidButton -
-
- ObjectButtonBar:{"pid":"foo:123"} + foo:123 +
+
+ CopyPidButton +
+
+ ObjectButtonBar:{"pid":"foo:123"} +
-
+ `; exports[`Child renders a thumbnail 1`] = ` -
+
- - + + + + Expand Tree + + + + + - - - Expand Tree - - - - - +
+ -
- ObjectThumbnail: {"pid":"foo:123"} -
-
- foo:123 -
-
- CopyPidButton -
-
- ObjectButtonBar:{"pid":"foo:123"} + ObjectThumbnail: {"pid":"foo:123"} +
+
+ foo:123 +
+
+ CopyPidButton +
+
+ ObjectButtonBar:{"pid":"foo:123"} +
-
+ `; exports[`Child renders child counts 1`] = ` -
+
- - + + + + Expand Tree + + + + + - - - Expand Tree - - - - - +
+ -
- ObjectChildCounts:{"pid":"foo:123"} -
-
- foo:123 -
-
- CopyPidButton -
-
- ObjectButtonBar:{"pid":"foo:123"} + ObjectChildCounts:{"pid":"foo:123"} +
+
+ foo:123 +
+
+ CopyPidButton +
+
+ ObjectButtonBar:{"pid":"foo:123"} +
-
+ `; exports[`Child renders thumbnail and child counts 1`] = ` -
+
- - + + + + Expand Tree + + + + + - - - Expand Tree - - - - - +
+ -
- ObjectThumbnail: {"pid":"foo:123"} - ObjectChildCounts:{"pid":"foo:123"} -
-
- foo:123 -
-
- CopyPidButton -
-
- ObjectButtonBar:{"pid":"foo:123"} + ObjectThumbnail: {"pid":"foo:123"}ObjectChildCounts:{"pid":"foo:123"} +
+
+ foo:123 +
+
+ CopyPidButton +
+
+ ObjectButtonBar:{"pid":"foo:123"} +
-
+
`; exports[`Child renders using ajax-loaded data 1`] = ` -
+
- - + + + + Expand Tree + + + + + - - - Expand Tree - - - - - +
+ -
- foo:123 -
-
- CopyPidButton -
-
- ObjectButtonBar:{"pid":"foo:123"} + foo:123 +
+
+ CopyPidButton +
+
+ ObjectButtonBar:{"pid":"foo:123"} +
-
+
`; diff --git a/client/components/edit/children/__snapshots__/ChildList.test.tsx.snap b/client/components/edit/children/__snapshots__/ChildList.test.tsx.snap index 1f6c7c5a0..fae9c1ea3 100644 --- a/client/components/edit/children/__snapshots__/ChildList.test.tsx.snap +++ b/client/components/edit/children/__snapshots__/ChildList.test.tsx.snap @@ -1,378 +1,344 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ChildList allows child counts to be toggled on 1`] = ` -
+
-
-
-   -
-
- - - + + + +
+
    +
  • + Child +
  • +
-
    -
  • - Child -
  • -
-
+
`; exports[`ChildList allows models to be toggled on 1`] = ` -
+
-
-
-   -
-
- - - + + + +
+
    +
  • + Child +
  • +
-
    -
  • - Child -
  • -
-
+
`; exports[`ChildList allows thumbnails to be toggled on 1`] = ` -
+
-
-
-   -
-
- - - + + + +
+
    +
  • + Child +
  • +
-
    -
  • - Child -
  • -
-
+
`; exports[`ChildList displays a paginator when appropriate 1`] = ` -
+
-

- Showing - 1 - - - 10 - of - - 10000 -

-
-
- Pagination -
-
-   -
-
-
+
- Show Thumbnails - - - + + + +
+
    +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
  • + Child +
  • +
-
    -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
  • - Child -
  • -
-
+ `; exports[`ChildList renders using SelectableChild when a callback is provided 1`] = ` -
+
-
-
-   -
-
- - - + + + +
+
    +
  • + SelectableChild +
  • +
-
    -
  • - SelectableChild -
  • -
-
+
`; exports[`ChildList renders using ajax-loaded object data 1`] = ` -
+
-
-
-   -
-
- - - + + + +
+
    +
  • + Child +
  • +
-
    -
  • - Child -
  • -
-
+
`; exports[`ChildList renders using ajax-loaded root data 1`] = ` -
+
-
-
-   -
-
- - - + + + +
+
    +
  • + Child +
  • +
-
    -
  • - Child -
  • -
-
+
`; diff --git a/client/components/edit/children/__snapshots__/ChildPosition.test.tsx.snap b/client/components/edit/children/__snapshots__/ChildPosition.test.tsx.snap index 648a22105..126bfa0c2 100644 --- a/client/components/edit/children/__snapshots__/ChildPosition.test.tsx.snap +++ b/client/components/edit/children/__snapshots__/ChildPosition.test.tsx.snap @@ -1,42 +1,41 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ChildPosition renders correctly when a sequence exists and parent is custom sorted 1`] = ` -
+
- -
- + + + +
+
-
+ `; + +exports[`ChildPosition renders correctly when a sequence exists and parent is not custom sorted 1`] = ``; + +exports[`ChildPosition renders correctly when no sort or sequence exists 1`] = ``; diff --git a/client/components/edit/children/__snapshots__/SelectableChild.test.tsx.snap b/client/components/edit/children/__snapshots__/SelectableChild.test.tsx.snap index 92ff62511..7cce539c8 100644 --- a/client/components/edit/children/__snapshots__/SelectableChild.test.tsx.snap +++ b/client/components/edit/children/__snapshots__/SelectableChild.test.tsx.snap @@ -1,143 +1,123 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`SelectableChild handles empty initial titles appropriately 1`] = ` -[ - + + Expand Tree - , - , -] + + `; exports[`SelectableChild handles missing object details storage title metadata correctly 1`] = ` -[ - + + Expand Tree - , - , -] + + `; exports[`SelectableChild renders thumbnails 1`] = ` -[ - + + Expand Tree - , - , -] + + `; exports[`SelectableChild renders using object details storage data 1`] = ` -[ - + + Expand Tree - , - , -] + + `; exports[`SelectableChild renders using provided default data 1`] = ` -[ - + + Expand Tree - , - , -] + + `; diff --git a/client/components/edit/create/CategoryTreeView.tsx b/client/components/edit/create/CategoryTreeView.tsx index f7560cb98..f2664062e 100644 --- a/client/components/edit/create/CategoryTreeView.tsx +++ b/client/components/edit/create/CategoryTreeView.tsx @@ -1,6 +1,6 @@ import React, { Dispatch } from "react"; import { TreeItem } from "@mui/x-tree-view/TreeItem"; -import { TreeView } from "@mui/x-tree-view/TreeView"; +import { SimpleTreeView } from "@mui/x-tree-view/SimpleTreeView"; interface CategoryTreeViewProps { models: Record; @@ -8,27 +8,30 @@ interface CategoryTreeViewProps { } const CategoryTreeView = ({ models, setSelectedModel }: CategoryTreeViewProps): React.ReactElement => { - function handleSelect(event, model) { - event.preventDefault(); - // Ignore categories - if (model.slice(0, 2) == "__") { + const handleItemSelectionToggle = (event: React.SyntheticEvent | null, itemId: string, isSelected: boolean) => { + // Only process when item is selected (not deselected) + if (!isSelected) { return; } - setSelectedModel(model); - return false; - } + // Ignore categories (those that start with __) + if (itemId.startsWith("__")) { + return; + } + setSelectedModel(itemId); + }; + return ( - + {Object.entries(models).map(([category, categoryValue]) => { return ( - + {Object.entries(categoryValue).map(([model, value]) => { - return ; + return ; })} ); })} - + ); }; diff --git a/client/components/edit/create/CreateObject.test.tsx b/client/components/edit/create/CreateObject.test.tsx index 8a36e3c4d..be482c3a7 100644 --- a/client/components/edit/create/CreateObject.test.tsx +++ b/client/components/edit/create/CreateObject.test.tsx @@ -1,10 +1,8 @@ -import React from "react"; import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import { waitFor } from "@testing-library/react"; import { fireEvent, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import renderer from "react-test-renderer"; import CreateObject from "./CreateObject"; import { FetchContextProvider } from "../../../context/FetchContext"; @@ -15,10 +13,10 @@ jest.mock("@mui/x-tree-view/TreeItem", function () { return { TreeItem: () => "TreeItem" }; }); -jest.mock("@mui/x-tree-view/TreeView", function () { +jest.mock("@mui/x-tree-view/SimpleTreeView", function () { return { - TreeView: ({ onNodeSelect, children }) => { - nodeSelectFunction = onNodeSelect; + SimpleTreeView: ({ onItemSelectionToggle, children }) => { + nodeSelectFunction = onItemSelectionToggle; treeItems = children; return children; }, @@ -39,13 +37,19 @@ describe("CreateObject", () => { global.fetch = jest.fn((url, data) => { if (url == "http://localhost:9000/api/edit/models") { // If models were requested, set up fake data: - const setFakeModels = function (callback) { - callback(["model-foo", "model-bar", "model-baz"]); + const modelsData = { + category1: { + "model-foo": "model-foo", + "model-bar": "model-bar", + }, + category2: { + "model-baz": "model-baz", + }, }; return { ok: true, status: 200, - json: () => new Promise(setFakeModels, jest.fn()), + json: async () => modelsData, }; } else if (url == "http://localhost:9000/api/edit/object/new") { // If the form was submitted, save the data so we can make assertions about it: @@ -68,33 +72,33 @@ describe("CreateObject", () => { } it("renders appropriately with default settings", async () => { - let tree; - await renderer.act(async () => { - tree = renderer.create(getCreateObjectToTest({})); + let asFragment; + await act(async () => { + asFragment = render(getCreateObjectToTest(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders appropriately with noParent and parent change enabled", async () => { props.allowNoParentPid = true; - let tree; - await renderer.act(async () => { - tree = renderer.create(getCreateObjectToTest(props)); + let asFragment; + await act(async () => { + asFragment = render(getCreateObjectToTest(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("renders appropriately with editing disabled", async () => { props.parentPid = "foo:1234"; props.allowChangeParentPid = false; - let tree; - await renderer.act(async () => { - tree = renderer.create(getCreateObjectToTest(props)); + let asFragment; + await act(async () => { + asFragment = render(getCreateObjectToTest(props)).asFragment; }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("submits appropriate data in default case", async () => { @@ -103,14 +107,14 @@ describe("CreateObject", () => { }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); await act(async () => { - nodeSelectFunction(new Event("event-foo"), "model-foo"); + nodeSelectFunction(new Event("event-foo"), "model-foo", true); // Test that category select has no effect: - nodeSelectFunction(new Event("event-foo"), "__categoryWillBeIgnored"); + nodeSelectFunction(new Event("event-foo"), "__categoryWillBeIgnored", true); }); fireEvent.change(screen.getByRole("textbox", { name: "Title" }), { target: { value: "Test Title" } }); fireEvent.change(screen.getByRole("textbox", { name: "Parent ID" }), { target: { value: "foo:1234" } }); await userEvent.setup().click(screen.getByRole("button", { name: "Create Object" })); - expect(treeItems.length).toEqual(3); // make sure setFakeModels is working + expect(treeItems.length).toEqual(2); // two categories expect(submittedData).toEqual({ body: JSON.stringify({ title: "Test Title", @@ -137,11 +141,11 @@ describe("CreateObject", () => { }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); await act(async () => { - nodeSelectFunction(new Event("event-foo"), "model-foo"); + nodeSelectFunction(new Event("event-foo"), "model-foo", true); fireEvent.change(screen.getByRole("textbox", { name: "Title" }), { target: { value: "Test Title" } }); }); await userEvent.setup().click(screen.getByRole("button", { name: "Create Object" })); - expect(treeItems.length).toEqual(3); // make sure setFakeModels is working + expect(treeItems.length).toEqual(2); // two categories expect(submittedData).toEqual({ body: JSON.stringify({ title: "Test Title", @@ -167,7 +171,7 @@ describe("CreateObject", () => { }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); await act(async () => { - nodeSelectFunction(new Event("event-foo"), "model-foo"); + nodeSelectFunction(new Event("event-foo"), "model-foo", true); fireEvent.change(screen.getByRole("textbox", { name: "Title" }), { target: { value: "Test Title" } }); }); const user = userEvent.setup(); @@ -199,7 +203,7 @@ describe("CreateObject", () => { }); await waitFor(() => expect(global.fetch).toHaveBeenCalled()); await act(async () => { - nodeSelectFunction(new Event("event-foo"), "model-foo"); + nodeSelectFunction(new Event("event-foo"), "model-foo", true); }); const user = userEvent.setup(); await act(async () => { diff --git a/client/components/edit/create/__snapshots__/CreateObject.test.tsx.snap b/client/components/edit/create/__snapshots__/CreateObject.test.tsx.snap index 51bbb6af9..4fb1b5e0f 100644 --- a/client/components/edit/create/__snapshots__/CreateObject.test.tsx.snap +++ b/client/components/edit/create/__snapshots__/CreateObject.test.tsx.snap @@ -1,196 +1,171 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`CreateObject renders appropriately with default settings 1`] = ` -
- - - - - - - TreeItem - TreeItem - TreeItem - + +
+ + + + + + + TreeItemTreeItem + +
`; exports[`CreateObject renders appropriately with editing disabled 1`] = ` -
- - - - - - TreeItem - TreeItem - TreeItem - + +
+ + + + + + TreeItemTreeItem + +
`; exports[`CreateObject renders appropriately with noParent and parent change enabled 1`] = ` -
- - - - - - - - TreeItem - TreeItem - TreeItem - + +
+ + + + + + + + TreeItemTreeItem + +
`; diff --git a/client/components/edit/datastream/Datastream.test.tsx b/client/components/edit/datastream/Datastream.test.tsx index 7f7ebc067..403115b60 100644 --- a/client/components/edit/datastream/Datastream.test.tsx +++ b/client/components/edit/datastream/Datastream.test.tsx @@ -1,9 +1,5 @@ -/** - * @jest-environment node - */ -import React from "react"; import { describe, expect, it, jest } from "@jest/globals"; -import renderer from "react-test-renderer"; +import { render } from "@testing-library/react"; import Datastream from "./Datastream"; const mockDatastreamControls = jest.fn(); jest.mock("./DatastreamControls", () => (props) => { @@ -17,12 +13,8 @@ describe("Datastream", () => { stream: "test1", disabled: true, }; - // Mocking the datastream controls causes a console error; let's suppress it - // by mocking out console.error(). - // TODO: figure out why and come up with a better solution than hiding the errors. - jest.spyOn(console, "error").mockImplementation(jest.fn()); - const tree = renderer.create(); - expect(tree.toJSON()).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); expect(mockDatastreamControls).toHaveBeenCalled(); }); }); diff --git a/client/components/edit/datastream/DatastreamAgentsAddContentRow.test.tsx b/client/components/edit/datastream/DatastreamAgentsAddContentRow.test.tsx index 65a66d7ab..c25c2637a 100644 --- a/client/components/edit/datastream/DatastreamAgentsAddContentRow.test.tsx +++ b/client/components/edit/datastream/DatastreamAgentsAddContentRow.test.tsx @@ -1,6 +1,5 @@ -import React from "react"; import { describe, afterEach, expect, it, jest } from "@jest/globals"; -import renderer from "react-test-renderer"; +import { render } from "@testing-library/react"; import DatastreamAgentsAddContentRow from "./DatastreamAgentsAddContentRow"; const mockDatastreamAgentsContentRow = jest.fn(); @@ -47,8 +46,8 @@ describe("DatastreamAgentsAddContentRow", () => { }); it("proxies DatastreamAgentsContextRow", () => { - const tree = renderer.create().toJSON(); - expect(tree).toEqual("DatastreamAgentsContentRow"); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); expect(datastreamAgentsContentRowProps.agent).toEqual(props.agent); }); }); diff --git a/client/components/edit/datastream/DatastreamAgentsContent.test.tsx b/client/components/edit/datastream/DatastreamAgentsContent.test.tsx index 5702d623e..e094286fa 100644 --- a/client/components/edit/datastream/DatastreamAgentsContent.test.tsx +++ b/client/components/edit/datastream/DatastreamAgentsContent.test.tsx @@ -1,9 +1,7 @@ -import React from "react"; import { describe, beforeEach, afterEach, expect, it, jest } from "@jest/globals"; import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { act } from "react-dom/test-utils"; -import renderer from "react-test-renderer"; +import { act } from "react"; import DatastreamAgentsContent from "./DatastreamAgentsContent"; const mockDatastreamAgentsModifyContentRow = jest.fn(); @@ -94,27 +92,29 @@ describe("DatastreamAgentsContent", () => { it("renders, and calls getAgents on render", async () => { datastreamOperationValues.getAgents.mockResolvedValue([]); - let tree; - await renderer.act(async () => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); await waitFor(() => expect(datastreamOperationValues.getAgents).toHaveBeenCalled()); expect(editorValues.action.setCurrentAgents).toHaveBeenCalled(); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("supports tab switching", async () => { datastreamOperationValues.getAgents.mockResolvedValue([]); - let tree; - await renderer.act(async () => { - tree = renderer.create(); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); await waitFor(() => expect(datastreamOperationValues.getAgents).toHaveBeenCalled()); - await renderer.act(async () => { - tabChangeFunction && tabChangeFunction(null, 1); + await act(async () => { + if (tabChangeFunction) { + tabChangeFunction(null, 1); + } }); expect(editorValues.action.setCurrentAgents).toHaveBeenCalled(); - expect(tree.toJSON()).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it("saves current changes on save changes click", async () => { @@ -157,7 +157,9 @@ describe("DatastreamAgentsContent", () => { await renderComponent(); expect(pidPickerFunction).not.toBeNull(); await act(async () => { - pidPickerFunction && pidPickerFunction(""); + if (pidPickerFunction) { + pidPickerFunction(""); + } }); expect(editorValues.action.loadObjectDetailsIntoStorage).not.toHaveBeenCalled(); }); @@ -174,7 +176,9 @@ describe("DatastreamAgentsContent", () => { ); expect(pidPickerFunction).not.toBeNull(); await act(async () => { - pidPickerFunction && pidPickerFunction("foo:123"); + if (pidPickerFunction) { + pidPickerFunction("foo:123"); + } }); expect(alertSpy).toHaveBeenCalledWith("Cannot load PID: foo:123"); }); @@ -184,7 +188,9 @@ describe("DatastreamAgentsContent", () => { await renderComponent(); expect(pidPickerFunction).not.toBeNull(); await act(async () => { - pidPickerFunction && pidPickerFunction("foo:123"); + if (pidPickerFunction) { + pidPickerFunction("foo:123"); + } }); expect(editorValues.action.loadObjectDetailsIntoStorage).toHaveBeenCalledWith("foo:123", expect.anything()); }); @@ -200,7 +206,9 @@ describe("DatastreamAgentsContent", () => { await renderComponent(); expect(pidPickerFunction).not.toBeNull(); await act(async () => { - pidPickerFunction && pidPickerFunction("foo:123"); + if (pidPickerFunction) { + pidPickerFunction("foo:123"); + } }); await userEvent.setup().click(screen.getByText("Clone")); expect(alertSpy).toHaveBeenCalledWith("foo:123 does not contain an AGENTS datastream."); @@ -216,7 +224,9 @@ describe("DatastreamAgentsContent", () => { await renderComponent(); expect(pidPickerFunction).not.toBeNull(); await act(async () => { - pidPickerFunction && pidPickerFunction("foo:123"); + if (pidPickerFunction) { + pidPickerFunction("foo:123"); + } }); await userEvent.setup().click(screen.getByText("Clone")); expect(datastreamOperationValues.getAgents).toHaveBeenCalledWith("foo:123", true); diff --git a/client/components/edit/datastream/DatastreamAgentsContent.tsx b/client/components/edit/datastream/DatastreamAgentsContent.tsx index bac7d2c84..8cded5637 100644 --- a/client/components/edit/datastream/DatastreamAgentsContent.tsx +++ b/client/components/edit/datastream/DatastreamAgentsContent.tsx @@ -82,7 +82,7 @@ const DatastreamAgentsContent = (): React.ReactElement => { await uploadAgents(agents); setIsLoading(false); }; - const contentRef = useRef(); + const contentRef = useRef(undefined); useLayoutEffect(() => { if (contentRef.current) { @@ -130,16 +130,16 @@ const DatastreamAgentsContent = (): React.ReactElement => {
- + Role - + Type - + Name - + Actions @@ -173,7 +173,7 @@ const DatastreamAgentsContent = (): React.ReactElement => { - + {hasChanges && ( { )} - + {hasChanges && ( @@ -76,9 +76,9 @@ const DatastreamProcessMetadataTask = ({ <>
- + - + - + - + - + {presetControl} - + - + - + - + - + - + diff --git a/client/components/edit/datastream/DatastreamUploadModalContent.test.tsx b/client/components/edit/datastream/DatastreamUploadModalContent.test.tsx index 59496551d..09a95e148 100644 --- a/client/components/edit/datastream/DatastreamUploadModalContent.test.tsx +++ b/client/components/edit/datastream/DatastreamUploadModalContent.test.tsx @@ -1,8 +1,6 @@ -import React from "react"; import { describe, beforeEach, expect, it, jest } from "@jest/globals"; -import { act } from "react-dom/test-utils"; +import { act } from "react"; import { fireEvent, render, screen } from "@testing-library/react"; -import renderer from "react-test-renderer"; import DatastreamUploadModalContent from "./DatastreamUploadModalContent"; const mockUseDatastreamOperation = jest.fn(); @@ -37,22 +35,22 @@ describe("DatastreamUploadModalContent", () => { }); it("renders", () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); }); it("renders DatastreamLicenseContent", () => { editorValues.state.activeDatastream = "LICENSE"; - const tree = renderer.create().toJSON(); - expect(tree).toEqual("DatastreamLicenseContent"); + const { container } = render(); + expect(container.innerHTML).toEqual("DatastreamLicenseContent"); }); it("renders DatastreamAgentContent", () => { editorValues.state.activeDatastream = "AGENTS"; - const tree = renderer.create().toJSON(); - expect(tree).toEqual("DatastreamAgentsContent"); + const { container } = render(); + expect(container.innerHTML).toEqual("DatastreamAgentsContent"); }); it("calls uploadFile on click", async () => { diff --git a/client/components/edit/datastream/DatastreamViewModalContent.test.tsx b/client/components/edit/datastream/DatastreamViewModalContent.test.tsx index 7e9e0b907..795e33f75 100644 --- a/client/components/edit/datastream/DatastreamViewModalContent.test.tsx +++ b/client/components/edit/datastream/DatastreamViewModalContent.test.tsx @@ -1,8 +1,7 @@ -import React from "react"; import { describe, beforeEach, expect, it, jest } from "@jest/globals"; -import renderer from "react-test-renderer"; +import { render, waitFor } from "@testing-library/react"; import DatastreamViewModalContent from "./DatastreamViewModalContent"; -import { waitFor } from "@testing-library/react"; +import { act } from "react"; const mockUseEditorContext = jest.fn(); jest.mock("../../../context/EditorContext", () => ({ @@ -54,13 +53,13 @@ describe("DatastreamViewModalContent", () => { mimeType: "test2", }; datastreamOperationValues.viewDatastream.mockResolvedValue(response); - let tree; - await renderer.act(async () => { - tree = renderer.create(); - await waitFor(() => expect(datastreamOperationValues.viewDatastream).toHaveBeenCalled()); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); - expect(tree.toJSON()).toMatchSnapshot(); - expect(mockDatatypeContent).toHaveBeenCalledWith(response); + await waitFor(() => expect(datastreamOperationValues.viewDatastream).toHaveBeenCalled()); + await waitFor(() => expect(mockDatatypeContent).toHaveBeenCalledWith(response)); + expect(asFragment()).toMatchSnapshot(); }); it("renders for download-only content", async () => { @@ -69,12 +68,12 @@ describe("DatastreamViewModalContent", () => { mimeType: "image/tiff", }; datastreamOperationValues.viewDatastream.mockResolvedValue(response); - let tree; - await renderer.act(async () => { - tree = renderer.create(); - await waitFor(() => expect(datastreamOperationValues.viewDatastream).toHaveBeenCalled()); + let asFragment; + await act(async () => { + asFragment = render().asFragment; }); - expect(tree.toJSON()).toMatchSnapshot(); + await waitFor(() => expect(datastreamOperationValues.viewDatastream).toHaveBeenCalled()); expect(mockDatatypeContent).not.toHaveBeenCalled(); + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/client/components/edit/datastream/__snapshots__/Datastream.test.tsx.snap b/client/components/edit/datastream/__snapshots__/Datastream.test.tsx.snap index e726d5a6d..aee3bc0e4 100644 --- a/client/components/edit/datastream/__snapshots__/Datastream.test.tsx.snap +++ b/client/components/edit/datastream/__snapshots__/Datastream.test.tsx.snap @@ -1,57 +1,24 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Datastream renders 1`] = ` -[ -