diff --git a/frontend/package.json b/frontend/package.json index 807b769..c201ae0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -32,7 +32,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", - "test": "react-scripts test", + "test": "react-scripts test --testPathPattern='(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$'", "eject": "react-scripts eject" }, "eslintConfig": { diff --git a/frontend/src/pages/Main/utils/__tests__/tryDeutscheNationalBibliothekApi.test.ts b/frontend/src/pages/Main/utils/__tests__/tryDeutscheNationalBibliothekApi.test.ts new file mode 100644 index 0000000..808657e --- /dev/null +++ b/frontend/src/pages/Main/utils/__tests__/tryDeutscheNationalBibliothekApi.test.ts @@ -0,0 +1,72 @@ +import { cleanup } from "@testing-library/react"; +import { tryDeutscheNationalBibliothekApi } from "../tryDeutscheNationalBibliothekApi"; + +const dnbBookMock = { + text: () => + ` + 1.11RDFxmlxml + + + + + + + (DE-101)962361321 + 9783898641227 + Pp. : DM 79.00, EUR 41.00 (ab 1.1.2002), sfr 70.00, S 577.00 + 3898641228 + Pp. : DM 79.00, EUR 41.00 (ab 1.1.2002), sfr 70.00, S 577.00 + (OCoLC)76300394 + + Gunter Saake ; Kai-Uwe Sattler + + mockedbook + + + + + 1. Aufl. + dpunkt-Verl. + Heidelberg + Heidelberg : dpunkt-Verl. + 25 cm + Ill. + Literaturverz. S. 483 - 486 + + + + + + + + + 2024-10-13T04:31:46.000 + + + + 2024 + + eine Einführung mit Java + XVI, 494 S. + + + 11.19783898641227`, +}; + +describe("tryDeutscheNationalBibliothekApi", () => { + it("should parse dnb response to book", async () => { + global.fetch = jest.fn(() => Promise.resolve(dnbBookMock)) as jest.Mock; + + const book = await tryDeutscheNationalBibliothekApi("mocked-isbn"); + + expect(book).toStrictEqual({ + published: 2024, + title: "mockedbook", + }); + }); + + afterAll(() => { + jest.clearAllMocks(); + cleanup(); + }); +}); diff --git a/frontend/src/pages/Main/utils/__tests__/tryGoogleBooksApi.test.ts b/frontend/src/pages/Main/utils/__tests__/tryGoogleBooksApi.test.ts new file mode 100644 index 0000000..5e93a95 --- /dev/null +++ b/frontend/src/pages/Main/utils/__tests__/tryGoogleBooksApi.test.ts @@ -0,0 +1,33 @@ +import { cleanup } from "@testing-library/react"; +import { tryGoogleBooksApi } from "../tryGoogleBooksApi"; + +const goolgeBooksMock = { + json: () => ({ + items: [ + { + volumeInfo: { + publishedDate: "2024-10-31", + title: "mockedbook", + }, + }, + ], + }), +}; + +describe("tryGoogleBooksApi", () => { + it("should parse google response to book", async () => { + global.fetch = jest.fn(() => Promise.resolve(goolgeBooksMock)) as jest.Mock; + + const book = await tryGoogleBooksApi("mocked-isbn"); + + expect(book).toStrictEqual({ + published: "2024", + title: "mockedbook", + }); + }); + + afterAll(() => { + jest.clearAllMocks(); + cleanup(); + }); +}); diff --git a/frontend/src/shared/components/modals/__tests__/AuthenticationModal.test.tsx b/frontend/src/shared/components/modals/__tests__/AuthenticationModal.test.tsx new file mode 100644 index 0000000..ad856f6 --- /dev/null +++ b/frontend/src/shared/components/modals/__tests__/AuthenticationModal.test.tsx @@ -0,0 +1,26 @@ +import { render } from "@testing-library/react"; +import { AuthenticationModal } from "../AuthenticationModal"; + +describe("AuthenticationModal", () => { + it("renders as admin verification correctly", () => { + const view = render( + undefined} + isUpdate={false} + /> + ); + expect(view.baseElement).toMatchSnapshot(); + }); + + it("renders as admin pw change correctly", () => { + const view = render( + undefined} + isUpdate={true} + /> + ); + expect(view.baseElement).toMatchSnapshot(); + }); +}); diff --git a/frontend/src/shared/components/modals/__tests__/BookModal.test.tsx b/frontend/src/shared/components/modals/__tests__/BookModal.test.tsx new file mode 100644 index 0000000..84b271d --- /dev/null +++ b/frontend/src/shared/components/modals/__tests__/BookModal.test.tsx @@ -0,0 +1,30 @@ +import { render } from "@testing-library/react"; +import { BookModal } from "../BookModal"; + +describe("BookModal", () => { + it("renders without a book", () => { + const view = render( undefined} />); + expect(view.baseElement).toMatchSnapshot(); + }); + + it("sets book as default value", () => { + const view = render( + undefined} + book={{ + id: 1, + uuid: "mockedbook", + isbn: "123", + title: "mockedbook", + published: 2024, + lastCheckoutDate: null, + checkoutBy: null, + shelf: "AVAILABLE", + contact: null, + }} + /> + ); + expect(view.baseElement).toMatchSnapshot(); + }); +}); diff --git a/frontend/src/shared/components/modals/__tests__/__snapshots__/AuthenticationModal.test.tsx.snap b/frontend/src/shared/components/modals/__tests__/__snapshots__/AuthenticationModal.test.tsx.snap new file mode 100644 index 0000000..cb78b1d --- /dev/null +++ b/frontend/src/shared/components/modals/__tests__/__snapshots__/AuthenticationModal.test.tsx.snap @@ -0,0 +1,271 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AuthenticationModal renders as admin pw change correctly 1`] = ` + + + + + + + + + + + + + + Set new Admin key + + + + + + + + + + + + + + Current Password + + + + + + Old password is required + + + + + + + New Password + + + + + + New password is required + + + + + + + Send + + + + + + + + +`; + +exports[`AuthenticationModal renders as admin verification correctly 1`] = ` + + + + + + + + + + + + + + Admin Login + + + + + + + + + + + + + + + Password is required + + + + + + Send + + + + + + + + +`; diff --git a/frontend/src/shared/components/modals/__tests__/__snapshots__/BookModal.test.tsx.snap b/frontend/src/shared/components/modals/__tests__/__snapshots__/BookModal.test.tsx.snap new file mode 100644 index 0000000..8049ff5 --- /dev/null +++ b/frontend/src/shared/components/modals/__tests__/__snapshots__/BookModal.test.tsx.snap @@ -0,0 +1,495 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BookModal renders without a book 1`] = ` + + + + + + + + + + + + + + Add new Book + + + + + + + + + + + + + + ISBN + + + + + + + + + + + + + ISBN is required + + + + + + + Title + + + + + + Title is required + + + + + + + Year published + + + + + + Year published is required + + + + + + + Shelf + + + + + + available + + + fnord1 + + + fnord2 + + + sharing + + + + Shelf is required + + + + + + Add Book + + + + + + + + +`; + +exports[`BookModal sets book as default value 1`] = ` + + + + + + + + + + + + + + Edit Book + + + + + + + + + + + + + + ISBN + + + + + + + + + + + + + ISBN is required + + + + + + + Title + + + + + + + + + + + Year published + + + + + + + + + + + Shelf + + + + + + available + + + fnord1 + + + fnord2 + + + sharing + + + + + + + + Submit + + + + + + + + +`;