From f6d2dbe7301ca6b80bb6684d679b40301c3abc2d Mon Sep 17 00:00:00 2001 From: Ryo Okubo Date: Sun, 24 Nov 2024 10:15:51 +0900 Subject: [PATCH] introduce msw to most of page tests --- frontend/src/pages/ACLEditPage.test.tsx | 85 ++++--- frontend/src/pages/ACLHistoryPage.test.tsx | 113 +++++---- .../pages/AdvancedSearchResultsPage.test.tsx | 114 +++++---- frontend/src/pages/DashboardPage.test.tsx | 92 +++---- frontend/src/pages/EntityHistoryPage.test.tsx | 123 +++++----- frontend/src/pages/EntryCopyPage.test.tsx | 56 +++-- frontend/src/pages/EntryDetailsPage.test.tsx | 76 +++--- .../src/pages/EntryHistoryListPage.test.tsx | 60 +++-- frontend/src/pages/EntryRestorePage.test.tsx | 121 +++++---- .../src/pages/UnavailableErrorPage.test.tsx | 23 ++ .../__snapshots__/ACLEditPage.test.tsx.snap | 232 +++++++++++++++--- .../ACLHistoryPage.test.tsx.snap | 188 +++++++++++++- .../AdvancedSearchResultsPage.test.tsx.snap | 18 ++ .../EntityHistoryPage.test.tsx.snap | 6 + .../__snapshots__/EntryCopyPage.test.tsx.snap | 16 +- .../EntryDetailsPage.test.tsx.snap | 12 +- .../EntryHistoryListPage.test.tsx.snap | 12 +- .../EntryRestorePage.test.tsx.snap | 68 ++++- .../UnavailableErrorPage.test.tsx.snap | 148 +++++++++++ 19 files changed, 1115 insertions(+), 448 deletions(-) create mode 100644 frontend/src/pages/UnavailableErrorPage.test.tsx create mode 100644 frontend/src/pages/__snapshots__/UnavailableErrorPage.test.tsx.snap diff --git a/frontend/src/pages/ACLEditPage.test.tsx b/frontend/src/pages/ACLEditPage.test.tsx index f5f59c186..b75b44add 100644 --- a/frontend/src/pages/ACLEditPage.test.tsx +++ b/frontend/src/pages/ACLEditPage.test.tsx @@ -3,15 +3,54 @@ */ import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; import { createMemoryRouter, RouterProvider } from "react-router-dom"; import { TestWrapperWithoutRoutes } from "TestWrapper"; import { ACLEditPage } from "pages/ACLEditPage"; +import { aclPath } from "routes/Routes"; -afterEach(() => { - jest.clearAllMocks(); -}); +const server = setupServer( + // getAcl + http.get("http://localhost/acl/api/v2/acls/1", () => { + return HttpResponse.json({ + name: "acl1", + objtype: 1, + is_public: false, + default_permission: 1, + parent: { + id: 10, + name: "Entity1", + }, + roles: [ + { + id: 1, + name: "member1", + description: "", + current_permission: 1, + }, + ], + }); + }), + // getEntity + http.get("http://localhost/entity/api/v2/1/", () => { + return HttpResponse.json({ + id: 1, + name: "test entity", + note: "", + isToplevel: false, + hasOngoingChanges: false, + attrs: [], + webhooks: [], + }); + }) +); + +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); test("should match snapshot", async () => { Object.defineProperty(window, "django_context", { @@ -23,43 +62,17 @@ test("should match snapshot", async () => { writable: false, }); - const acl = { - name: "acl1", - objtype: "type1", - is_public: false, - default_permission: 1, - parent: { - id: 10, - name: "Entity1", - }, - acltypes: [ + const router = createMemoryRouter( + [ { - id: 1, - name: "type1", + path: aclPath(":objectId"), + element: , }, ], - roles: [ - { - id: 1, - name: "member1", - type: 1, - current_permission: 1, - }, - ], - }; - - /* eslint-disable */ - jest - .spyOn(require("../repository/AironeApiClient").aironeApiClient, "getAcl") - .mockResolvedValue(Promise.resolve(acl)); - /* eslint-enable */ - - const router = createMemoryRouter([ { - path: "/", - element: , - }, - ]); + initialEntries: [aclPath(1)], + } + ); const result = await act(async () => { return render(, { wrapper: TestWrapperWithoutRoutes, diff --git a/frontend/src/pages/ACLHistoryPage.test.tsx b/frontend/src/pages/ACLHistoryPage.test.tsx index 3801cc16d..af82568ea 100644 --- a/frontend/src/pages/ACLHistoryPage.test.tsx +++ b/frontend/src/pages/ACLHistoryPage.test.tsx @@ -2,21 +2,60 @@ * @jest-environment jsdom */ -import { ACLHistory } from "@dmm-com/airone-apiclient-typescript-fetch"; -import { - render, - waitForElementToBeRemoved, - screen, -} from "@testing-library/react"; +import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; +import { createMemoryRouter, RouterProvider } from "react-router-dom"; import { ACLHistoryPage } from "./ACLHistoryPage"; -import { TestWrapper } from "TestWrapper"; +import { TestWrapperWithoutRoutes } from "TestWrapper"; +import { aclHistoryPath } from "routes/Routes"; -afterEach(() => { - jest.clearAllMocks(); -}); +const server = setupServer( + // getAcl + http.get("http://localhost/acl/api/v2/acls/1", () => { + return HttpResponse.json({ + name: "acl1", + objtype: 1, + is_public: false, + default_permission: 1, + parent: { + id: 10, + name: "Entity1", + }, + roles: [ + { + id: 1, + name: "member1", + description: "", + current_permission: 1, + }, + ], + }); + }), + // getAclHistory + http.get("http://localhost/acl/api/v2/acls/1/history", () => { + return HttpResponse.json([]); + }), + // getEntity + http.get("http://localhost/entity/api/v2/1/", () => { + return HttpResponse.json({ + id: 1, + name: "test entity", + note: "", + isToplevel: false, + hasOngoingChanges: false, + attrs: [], + webhooks: [], + }); + }) +); + +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); test("should match snapshot", async () => { Object.defineProperty(window, "django_context", { @@ -28,49 +67,25 @@ test("should match snapshot", async () => { writable: false, }); - const history: Array = []; - const acl = { - name: "acl1", - objtype: "type1", - is_public: false, - default_permission: 1, - parent: { - id: 10, - name: "Entity1", - }, - acltypes: [ - { - id: 1, - name: "type1", - }, - ], - roles: [ + const router = createMemoryRouter( + [ { - id: 1, - name: "member1", - type: 1, - current_permission: 1, + path: aclHistoryPath(":objectId"), + element: , }, ], - }; - - /* eslint-disable */ - jest - .spyOn( - require("../repository/AironeApiClient").aironeApiClient, - "getAclHistory" - ) - .mockResolvedValue(Promise.resolve(history)); - jest - .spyOn(require("../repository/AironeApiClient").aironeApiClient, "getAcl") - .mockResolvedValue(Promise.resolve(acl)); - /* eslint-enable */ - - // wait async calls and get rendered fragment - const result = render(, { - wrapper: TestWrapper, + { + initialEntries: [aclHistoryPath(1)], + } + ); + const result = await act(async () => { + return render(, { + wrapper: TestWrapperWithoutRoutes, + }); + }); + await waitFor(() => { + expect(screen.queryByTestId("loading")).not.toBeInTheDocument(); }); - await waitForElementToBeRemoved(screen.getByTestId("loading")); expect(result).toMatchSnapshot(); }); diff --git a/frontend/src/pages/AdvancedSearchResultsPage.test.tsx b/frontend/src/pages/AdvancedSearchResultsPage.test.tsx index b95ec57af..9aeb074a3 100644 --- a/frontend/src/pages/AdvancedSearchResultsPage.test.tsx +++ b/frontend/src/pages/AdvancedSearchResultsPage.test.tsx @@ -2,20 +2,59 @@ * @jest-environment jsdom */ -import { AdvancedSearchResultValue } from "@dmm-com/airone-apiclient-typescript-fetch"; -import { - render, - waitForElementToBeRemoved, - screen, -} from "@testing-library/react"; +import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; import { TestWrapper } from "TestWrapper"; import { AdvancedSearchResultsPage } from "pages/AdvancedSearchResultsPage"; -afterEach(() => { - jest.clearAllMocks(); -}); +const server = setupServer( + // getEntityAttrs + http.get( + "http://localhost/entity/api/v2/attrs?entity_ids=1&referral_attr=", + () => { + return HttpResponse.json([]); + } + ), + // advancedSearch + http.post("http://localhost/entry/api/v2/advanced_search/", () => { + return HttpResponse.json({ + count: 1, + total_count: 1, + values: [ + { + entry: { + id: 2, + name: "entry1", + }, + entity: { + id: 1, + name: "entity1", + }, + attrs: { + attr1: { + type: 2, + value: { asString: "attr1" }, + isReadable: true, + }, + attr2: { + type: 2, + value: { asString: "attr1" }, + isReadable: true, + }, + }, + isReadable: true, + }, + ], + }); + }) +); + +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); test("should match snapshot", async () => { Object.defineProperty(window, "django_context", { @@ -27,58 +66,15 @@ test("should match snapshot", async () => { writable: false, }); - const results: AdvancedSearchResultValue[] = [ - { - entry: { - id: 2, - name: "entry1", - }, - entity: { - id: 1, - name: "entity1", - }, - attrs: { - attr1: { - type: 2, - value: { asString: "attr1" }, - isReadable: true, - }, - attr2: { - type: 2, - value: { asString: "attr1" }, - isReadable: true, - }, - }, - isReadable: true, - }, - ]; - - /* eslint-disable */ - jest - .spyOn( - require("repository/AironeApiClient").aironeApiClient, - "advancedSearch" - ) - .mockResolvedValue( - Promise.resolve({ - count: 1, - values: results, - totalCount: 1, - }) - ); - jest - .spyOn( - require("repository/AironeApiClient").aironeApiClient, - "getEntityAttrs" - ) - .mockResolvedValue(Promise.resolve([])); - /* eslint-enable */ - // wait async calls and get rendered fragment - const result = render(, { - wrapper: TestWrapper, + const result = await act(async () => { + return render(, { + wrapper: TestWrapper, + }); + }); + await waitFor(() => { + expect(screen.queryByTestId("loading")).not.toBeInTheDocument(); }); - await waitForElementToBeRemoved(screen.getByTestId("loading")); expect(result).toMatchSnapshot(); }); diff --git a/frontend/src/pages/DashboardPage.test.tsx b/frontend/src/pages/DashboardPage.test.tsx index adb963a02..c0320005e 100644 --- a/frontend/src/pages/DashboardPage.test.tsx +++ b/frontend/src/pages/DashboardPage.test.tsx @@ -2,20 +2,52 @@ * @jest-environment jsdom */ -import { - render, - waitForElementToBeRemoved, - screen, -} from "@testing-library/react"; +import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; import { DashboardPage } from "./DashboardPage"; import { TestWrapper } from "TestWrapper"; -afterEach(() => { - jest.clearAllMocks(); -}); +const server = setupServer( + // getEntities + http.get("http://localhost/entity/api/v2/", () => { + return HttpResponse.json({ + count: 3, + next: null, + previous: null, + results: [ + { + id: 1, + name: "aaa", + note: "", + isToplevel: false, + status: 1, + }, + { + id: 2, + name: "aaaaa", + note: "", + isToplevel: false, + status: 1, + }, + { + id: 3, + name: "bbbbb", + note: "", + isToplevel: false, + status: 1, + }, + ], + }); + }) +); + +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); test("should match snapshot", async () => { Object.defineProperty(window, "django_context", { @@ -27,44 +59,14 @@ test("should match snapshot", async () => { writable: false, }); - const entities = [ - { - id: 1, - name: "aaa", - note: "", - isToplevel: false, - status: 1, - }, - { - id: 2, - name: "aaaaa", - note: "", - isToplevel: false, - status: 1, - }, - { - id: 3, - name: "bbbbb", - note: "", - isToplevel: false, - status: 1, - }, - ]; - - /* eslint-disable */ - jest - .spyOn( - require("../repository/AironeApiClient").aironeApiClient, - "getEntities" - ) - .mockResolvedValue(Promise.resolve({ results: entities })); - /* eslint-enable */ - - // wait async calls and get rendered fragment - const result = render(, { - wrapper: TestWrapper, + const result = await act(() => { + return render(, { + wrapper: TestWrapper, + }); + }); + await waitFor(() => { + expect(screen.queryByTestId("loading")).not.toBeInTheDocument(); }); - await waitForElementToBeRemoved(screen.getByTestId("loading")); expect(result).toMatchSnapshot(); }); diff --git a/frontend/src/pages/EntityHistoryPage.test.tsx b/frontend/src/pages/EntityHistoryPage.test.tsx index 1a10038b4..b533076b4 100644 --- a/frontend/src/pages/EntityHistoryPage.test.tsx +++ b/frontend/src/pages/EntityHistoryPage.test.tsx @@ -2,71 +2,84 @@ * @jest-environment jsdom */ -import { PaginatedEntityHistoryList } from "@dmm-com/airone-apiclient-typescript-fetch"; -import { - render, - waitForElementToBeRemoved, - screen, -} from "@testing-library/react"; +import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; +import { createMemoryRouter, RouterProvider } from "react-router-dom"; -import { TestWrapper } from "TestWrapper"; +import { TestWrapperWithoutRoutes } from "TestWrapper"; import { EntityHistoryPage } from "pages/EntityHistoryPage"; +import { entityHistoryPath } from "routes/Routes"; -afterEach(() => { - jest.clearAllMocks(); -}); +const entity = { + id: 1, + name: "aaa", + note: "", + is_toplevel: false, + has_ongoing_changes: false, + attrs: [], + webhooks: [], +}; +const histories = { + count: 1, + results: [ + { + operation: 1, + time: new Date(2022, 0, 1, 0, 0, 0), + username: "aaa", + target_obj: "aaa", + text: "text", + is_detail: false, + }, + { + operation: 1, + time: new Date(2022, 0, 1, 0, 0, 0), + username: "bbb", + target_obj: "bbb", + text: "text", + is_detail: false, + }, + ], +}; + +const server = setupServer( + // getEntityHistories + http.get("http://localhost/entity/api/v2/1/histories", () => { + return HttpResponse.json(histories); + }), + // getEntity + http.get("http://localhost/entity/api/v2/1/", () => { + return HttpResponse.json(entity); + }) +); + +beforeAll(() => server.listen()); + +afterEach(() => server.resetHandlers()); + +afterAll(() => server.close()); test("should match snapshot", async () => { - const entity = { - id: 1, - name: "aaa", - note: "", - isToplevel: false, - attrs: [], - }; - const histories: PaginatedEntityHistoryList = { - count: 1, - results: [ + const router = createMemoryRouter( + [ { - operation: 1, - time: new Date(2022, 0, 1, 0, 0, 0), - username: "aaa", - targetObj: "aaa", - text: "text", - isDetail: false, - }, - { - operation: 1, - time: new Date(2022, 0, 1, 0, 0, 0), - username: "bbb", - targetObj: "bbb", - text: "text", - isDetail: false, + path: entityHistoryPath(":entityId"), + element: , }, ], - }; - - /* eslint-disable */ - jest - .spyOn( - require("../repository/AironeApiClient").aironeApiClient, - "getEntity" - ) - .mockResolvedValue(Promise.resolve(entity)); - jest - .spyOn( - require("../repository/AironeApiClient").aironeApiClient, - "getEntityHistories" - ) - .mockResolvedValue(Promise.resolve(histories)); - /* eslint-enable */ - - // wait async calls and get rendered fragment - const result = render(, { - wrapper: TestWrapper, + { + initialEntries: [entityHistoryPath(1)], + } + ); + const result = await act(async () => { + return render(, { + wrapper: TestWrapperWithoutRoutes, + }); + }); + await waitFor(() => { + expect(screen.queryByTestId("loading")).not.toBeInTheDocument(); }); - await waitForElementToBeRemoved(screen.getByTestId("loading")); expect(result).toMatchSnapshot(); }); diff --git a/frontend/src/pages/EntryCopyPage.test.tsx b/frontend/src/pages/EntryCopyPage.test.tsx index 5fa2effc0..631f815fb 100644 --- a/frontend/src/pages/EntryCopyPage.test.tsx +++ b/frontend/src/pages/EntryCopyPage.test.tsx @@ -3,40 +3,48 @@ */ import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; import { createMemoryRouter, RouterProvider } from "react-router-dom"; import { EntryCopyPage } from "./EntryCopyPage"; import { TestWrapperWithoutRoutes } from "TestWrapper"; +import { copyEntryPath } from "routes/Routes"; + +const server = setupServer( + // getEntry + http.get("http://localhost/entry/api/v2/1/", () => { + return HttpResponse.json({ + id: 1, + name: "test entry", + is_active: true, + schema: { + id: 2, + name: "test entity", + }, + attrs: [], + }); + }) +); -afterEach(() => { - jest.clearAllMocks(); -}); +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); test("should match snapshot", async () => { - const entry = { - id: 1, - name: "aaa", - schema: { - id: 2, - name: "bbb", - }, - attrs: [], - }; - - /* eslint-disable */ - jest - .spyOn(require("repository/AironeApiClient").aironeApiClient, "getEntry") - .mockResolvedValue(Promise.resolve(entry)); - /* eslint-enable */ - - const router = createMemoryRouter([ + const router = createMemoryRouter( + [ + { + path: copyEntryPath(":entityId", ":entryId"), + element: , + }, + ], { - path: "/", - element: , - }, - ]); + initialEntries: [copyEntryPath(2, 1)], + } + ); const result = await act(async () => { return render(, { wrapper: TestWrapperWithoutRoutes, diff --git a/frontend/src/pages/EntryDetailsPage.test.tsx b/frontend/src/pages/EntryDetailsPage.test.tsx index c208ecc0f..f04178d6d 100644 --- a/frontend/src/pages/EntryDetailsPage.test.tsx +++ b/frontend/src/pages/EntryDetailsPage.test.tsx @@ -3,6 +3,8 @@ */ import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; import { createMemoryRouter, RouterProvider } from "react-router-dom"; @@ -10,51 +12,45 @@ import { TestWrapperWithoutRoutes } from "TestWrapper"; import { EntryDetailsPage } from "pages/EntryDetailsPage"; import { entryDetailsPath } from "routes/Routes"; -afterEach(() => { - jest.clearAllMocks(); -}); - -test("should match snapshot", async () => { - const entry = { - id: 1, - name: "aaa", - isActive: true, - schema: { - id: 2, - name: "bbb", - }, - attrs: [], - }; - - const referredEntries = [ - { +const server = setupServer( + // getEntry + http.get("http://localhost/entry/api/v2/1/", () => { + return HttpResponse.json({ id: 1, - name: "aaa", + name: "test entry", + is_active: true, schema: { id: 2, - name: "bbb", + name: "test entity", }, - }, - ]; - - /* eslint-disable */ - jest - .spyOn( - require("repository/AironeApiClient").aironeApiClient, - "getEntryReferral" - ) - .mockResolvedValue( - Promise.resolve({ - results: referredEntries, - count: referredEntries.length, - }) - ); + attrs: [], + }); + }), + // getEntryReferral + http.get("http://localhost/entry/api/v2/1/referral/", () => { + return HttpResponse.json({ + count: 1, + next: null, + previous: null, + results: [ + { + id: 1, + name: "aaa", + schema: { + id: 2, + name: "bbb", + }, + }, + ], + }); + }) +); - jest - .spyOn(require("repository/AironeApiClient").aironeApiClient, "getEntry") - .mockResolvedValue(Promise.resolve(entry)); - /* eslint-enable */ +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); +test("should match snapshot", async () => { const router = createMemoryRouter( [ { @@ -63,7 +59,7 @@ test("should match snapshot", async () => { }, ], { - initialEntries: ["/ui/entities/2/entries/1/details"], + initialEntries: [entryDetailsPath(2, 1)], } ); const result = await act(async () => { diff --git a/frontend/src/pages/EntryHistoryListPage.test.tsx b/frontend/src/pages/EntryHistoryListPage.test.tsx index 458e58f44..f887c49d6 100644 --- a/frontend/src/pages/EntryHistoryListPage.test.tsx +++ b/frontend/src/pages/EntryHistoryListPage.test.tsx @@ -3,6 +3,8 @@ */ import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; import { createMemoryRouter, RouterProvider } from "react-router-dom"; @@ -12,40 +14,34 @@ import { EntryHistoryListPage } from "./EntryHistoryListPage"; import { TestWrapperWithoutRoutes } from "TestWrapper"; -afterEach(() => { - jest.clearAllMocks(); -}); - -test("should match snapshot", async () => { - const entry = { - id: 1, - name: "aaa", - isActive: true, - schema: { - id: 2, - name: "bbb", - }, - attrs: [], - }; - - const histories = { - count: 0, - results: [], - }; - - /* eslint-disable */ - jest - .spyOn(require("repository/AironeApiClient").aironeApiClient, "getEntry") - .mockResolvedValue(Promise.resolve(entry)); +const server = setupServer( + // getEntry + http.get("http://localhost/entry/api/v2/1/", () => { + return HttpResponse.json({ + id: 1, + name: "test entry", + is_active: true, + schema: { + id: 2, + name: "test entity", + }, + attrs: [], + }); + }), + // getEntryHistories + http.get("http://localhost/entry/api/v2/1/histories", () => { + return HttpResponse.json({ + count: 0, + results: [], + }); + }) +); - jest - .spyOn( - require("repository/AironeApiClient").aironeApiClient, - "getEntryHistories" - ) - .mockResolvedValue(Promise.resolve(histories)); - /* eslint-enable */ +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); +test("should match snapshot", async () => { const router = createMemoryRouter( [ { diff --git a/frontend/src/pages/EntryRestorePage.test.tsx b/frontend/src/pages/EntryRestorePage.test.tsx index bb54b2eb8..74fa756b0 100644 --- a/frontend/src/pages/EntryRestorePage.test.tsx +++ b/frontend/src/pages/EntryRestorePage.test.tsx @@ -2,70 +2,83 @@ * @jest-environment jsdom */ -import { - render, - waitForElementToBeRemoved, - screen, -} from "@testing-library/react"; +import { render, screen, act, waitFor } from "@testing-library/react"; +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; import React from "react"; +import { createMemoryRouter, RouterProvider } from "react-router-dom"; import { EntryRestorePage } from "./EntryRestorePage"; -import { TestWrapper } from "TestWrapper"; +import { TestWrapperWithoutRoutes } from "TestWrapper"; +import { restoreEntryPath } from "routes/Routes"; -afterEach(() => { - jest.clearAllMocks(); -}); - -test("should match snapshot", async () => { - const entity = { - id: 1, - name: "aaa", - note: "", - isToplevel: false, - attrs: [], - }; - const entries = [ - { +const server = setupServer( + // getEntity + http.get("http://localhost/entity/api/v2/1", () => { + return HttpResponse.json({ id: 1, name: "aaa", - schema: null, - isActive: true, - }, - { - id: 2, - name: "aaaaa", - schema: null, - isActive: true, - }, - { - id: 3, - name: "bbbbb", - schema: null, - isActive: true, - }, - ]; + note: "", + is_toplevel: false, + attrs: [], + webhooks: [], + }); + }), + // getEntries + http.get("http://localhost/entity/api/v2/1/entries/", () => { + return HttpResponse.json({ + count: 3, + next: null, + previous: null, + results: [ + { + id: 1, + name: "aaa", + schema: null, + is_active: true, + }, + { + id: 2, + name: "aaaaa", + schema: null, + is_active: true, + }, + { + id: 3, + name: "bbbbb", + schema: null, + is_active: true, + }, + ], + }); + }) +); - /* eslint-disable */ - jest - .spyOn( - require("../repository/AironeApiClient").aironeApiClient, - "getEntity" - ) - .mockResolvedValue(Promise.resolve(entity)); - jest - .spyOn( - require("../repository/AironeApiClient").aironeApiClient, - "getEntries" - ) - .mockResolvedValue(Promise.resolve({ results: entries })); - /* eslint-enable */ +beforeAll(() => server.listen()); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); - // wait async calls and get rendered fragment - const result = render(, { - wrapper: TestWrapper, +test("should match snapshot", async () => { + const router = createMemoryRouter( + [ + { + path: restoreEntryPath(":entityId"), + element: , + }, + ], + { + initialEntries: [restoreEntryPath(1)], + } + ); + const result = await act(async () => { + return render(, { + wrapper: TestWrapperWithoutRoutes, + }); + }); + await waitFor(() => { + expect(screen.queryByTestId("loading")).not.toBeInTheDocument(); }); - await waitForElementToBeRemoved(screen.getByTestId("loading")); expect(result).toMatchSnapshot(); }); diff --git a/frontend/src/pages/UnavailableErrorPage.test.tsx b/frontend/src/pages/UnavailableErrorPage.test.tsx new file mode 100644 index 000000000..bd4b8c029 --- /dev/null +++ b/frontend/src/pages/UnavailableErrorPage.test.tsx @@ -0,0 +1,23 @@ +/** + * @jest-environment jsdom + */ + +import { render } from "@testing-library/react"; +import React from "react"; + +import { UnavailableErrorPage } from "./UnavailableErrorPage"; + +import { TestWrapper } from "TestWrapper"; + +afterEach(() => { + jest.clearAllMocks(); +}); + +test("should match snapshot", async () => { + // wait async calls and get rendered fragment + const result = render(, { + wrapper: TestWrapper, + }); + + expect(result).toMatchSnapshot(); +}); diff --git a/frontend/src/pages/__snapshots__/ACLEditPage.test.tsx.snap b/frontend/src/pages/__snapshots__/ACLEditPage.test.tsx.snap index a779f68f9..8d01ce9d7 100644 --- a/frontend/src/pages/__snapshots__/ACLEditPage.test.tsx.snap +++ b/frontend/src/pages/__snapshots__/ACLEditPage.test.tsx.snap @@ -9,8 +9,98 @@ exports[`should match snapshot 1`] = ` class="container-fluid MuiBox-root css-0" >
+ class="MuiBox-root css-1baykhj" + > +
+
+ +
+
+
@@ -121,7 +211,7 @@ exports[`should match snapshot 1`] = ` role="button" tabindex="0" > - 公開 + 限定公開
@@ -236,14 +326,13 @@ exports[`should match snapshot 1`] = ` aria-hidden="true" aria-invalid="false" class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput" - disabled="" name="defaultPermission" tabindex="-1" value="1" />
@@ -301,14 +390,13 @@ exports[`should match snapshot 1`] = ` aria-hidden="true" aria-invalid="false" class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput" - disabled="" name="roles.0.currentPermission" tabindex="-1" value="1" />
+ class="MuiBox-root css-1baykhj" + > +
+
+ +
+
+
@@ -459,7 +637,7 @@ exports[`should match snapshot 1`] = ` role="button" tabindex="0" > - 公開 + 限定公開
@@ -574,14 +752,13 @@ exports[`should match snapshot 1`] = ` aria-hidden="true" aria-invalid="false" class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput" - disabled="" name="defaultPermission" tabindex="-1" value="1" />
@@ -639,14 +816,13 @@ exports[`should match snapshot 1`] = ` aria-hidden="true" aria-invalid="false" class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput" - disabled="" name="roles.0.currentPermission" tabindex="-1" value="1" />
+ class="MuiBox-root css-1baykhj" + > +
+
+ +
+
+
@@ -143,8 +233,98 @@ exports[`should match snapshot 1`] = ` class="container-fluid MuiBox-root css-0" >
+ class="MuiBox-root css-1baykhj" + > +
+
+ +
+
+
diff --git a/frontend/src/pages/__snapshots__/AdvancedSearchResultsPage.test.tsx.snap b/frontend/src/pages/__snapshots__/AdvancedSearchResultsPage.test.tsx.snap index ca83c317e..72f746a70 100644 --- a/frontend/src/pages/__snapshots__/AdvancedSearchResultsPage.test.tsx.snap +++ b/frontend/src/pages/__snapshots__/AdvancedSearchResultsPage.test.tsx.snap @@ -239,6 +239,9 @@ exports[`should match snapshot 1`] = ` d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" /> +
@@ -272,6 +275,9 @@ exports[`should match snapshot 1`] = ` d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" /> + 1 +
  • @@ -605,6 +614,9 @@ exports[`should match snapshot 1`] = ` d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" /> +
  • @@ -638,6 +650,9 @@ exports[`should match snapshot 1`] = ` d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" /> + 1 +
  • diff --git a/frontend/src/pages/__snapshots__/EntityHistoryPage.test.tsx.snap b/frontend/src/pages/__snapshots__/EntityHistoryPage.test.tsx.snap index f19a2d461..5f812c1d5 100644 --- a/frontend/src/pages/__snapshots__/EntityHistoryPage.test.tsx.snap +++ b/frontend/src/pages/__snapshots__/EntityHistoryPage.test.tsx.snap @@ -346,6 +346,9 @@ exports[`should match snapshot 1`] = ` type="button" > 1 +
  • @@ -720,6 +723,9 @@ exports[`should match snapshot 1`] = ` type="button" > 1 +
  • diff --git a/frontend/src/pages/__snapshots__/EntryCopyPage.test.tsx.snap b/frontend/src/pages/__snapshots__/EntryCopyPage.test.tsx.snap index 450b637ec..df417f6fb 100644 --- a/frontend/src/pages/__snapshots__/EntryCopyPage.test.tsx.snap +++ b/frontend/src/pages/__snapshots__/EntryCopyPage.test.tsx.snap @@ -66,7 +66,7 @@ exports[`should match snapshot 1`] = ` class="MuiTypography-root MuiTypography-body1 css-ahj2mt-MuiTypography-root" href="/ui/entities/2/entries" > - bbb + test entity
    - 入力した各行ごとに aaa と同じ属性を持つ別のアイテムを作成 + 入力した各行ごとに test entry と同じ属性を持つ別のアイテムを作成

    - bbb + test entity
    - 入力した各行ごとに aaa と同じ属性を持つ別のアイテムを作成 + 入力した各行ごとに test entry と同じ属性を持つ別のアイテムを作成

    - bbb + test entity
    - bbb + test entity
    - bbb + test entity
    - bbb + test entity
    +
  • @@ -278,6 +281,9 @@ exports[`should match snapshot 1`] = ` d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" /> +
    @@ -312,6 +318,9 @@ exports[`should match snapshot 1`] = ` +
    @@ -337,6 +346,9 @@ exports[`should match snapshot 1`] = ` d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" /> + @@ -371,6 +383,9 @@ exports[`should match snapshot 1`] = ` + @@ -396,6 +411,9 @@ exports[`should match snapshot 1`] = ` d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" /> + @@ -410,7 +428,7 @@ exports[`should match snapshot 1`] = `

    - 0 - 0 / 0 件 + 1 - 3 / 3 件

    +
  • + +
  • @@ -747,6 +782,9 @@ exports[`should match snapshot 1`] = ` d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" /> + @@ -781,6 +819,9 @@ exports[`should match snapshot 1`] = ` + @@ -806,6 +847,9 @@ exports[`should match snapshot 1`] = ` d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" /> + @@ -840,6 +884,9 @@ exports[`should match snapshot 1`] = ` + @@ -865,6 +912,9 @@ exports[`should match snapshot 1`] = ` d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" /> + @@ -879,7 +929,7 @@ exports[`should match snapshot 1`] = `

    - 0 - 0 / 0 件 + 1 - 3 / 3 件

    +
  • + +
  • +
  • + + + , + "container":
    +
    +
    +

    + 利用できません:;(∩´﹏\`∩);: +

    +
    +
    +

    + このページは現在、利用ができません。 +

    +

    + 管理者からのお知らせをご覧いただくか、お問合せください。 +

    +
    +
    + +
    +
    +
    , + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`;