feat(ISBN-APIS): add tests

This commit is contained in:
0ry5 2025-01-16 20:13:37 +01:00
parent fac5e7b66c
commit 219b65e95f
7 changed files with 928 additions and 1 deletions

View file

@ -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(
<AuthenticationModal
open={true}
onClose={() => undefined}
isUpdate={false}
/>
);
expect(view.baseElement).toMatchSnapshot();
});
it("renders as admin pw change correctly", () => {
const view = render(
<AuthenticationModal
open={true}
onClose={() => undefined}
isUpdate={true}
/>
);
expect(view.baseElement).toMatchSnapshot();
});
});

View file

@ -0,0 +1,30 @@
import { render } from "@testing-library/react";
import { BookModal } from "../BookModal";
describe("BookModal", () => {
it("renders without a book", () => {
const view = render(<BookModal open={true} onClose={() => undefined} />);
expect(view.baseElement).toMatchSnapshot();
});
it("sets book as default value", () => {
const view = render(
<BookModal
open={true}
onClose={() => undefined}
book={{
id: 1,
uuid: "mockedbook",
isbn: "123",
title: "mockedbook",
published: 2024,
lastCheckoutDate: null,
checkoutBy: null,
shelf: "AVAILABLE",
contact: null,
}}
/>
);
expect(view.baseElement).toMatchSnapshot();
});
});

View file

@ -0,0 +1,271 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AuthenticationModal renders as admin pw change correctly 1`] = `
<body
class="modal-open"
data-rr-ui-modal-open=""
style="padding-right: 2048px;"
>
<div />
<div
class="fade modal-backdrop show"
/>
<div
aria-modal="true"
class="fade modal show"
role="dialog"
style="display: block; padding-right: 0px;"
tabindex="-1"
>
<div
class="modal-dialog modal-dialog-centered"
>
<div
class="modal-content"
>
<div
class="modal-header"
>
<div
class="w-100 d-flex modal-title h4"
>
<svg
class="ml-0 mr-auto"
fill="currentColor"
height="50"
stroke="currentColor"
stroke-width="0"
version="1.1"
viewBox="0 0 17 17"
width="50"
xmlns="http://www.w3.org/2000/svg"
>
<g />
<path
d="M14.811 6.299l0.707-0.707-1.733-1.733 0.757-0.753-0.705-0.709-8.146 8.107c-0.484-0.336-1.070-0.535-1.703-0.535-1.654 0-3 1.346-3 3s1.346 3 3 3 3-1.346 3-3c0-0.661-0.222-1.268-0.585-1.764l5.264-5.238 1.738 1.738 0.707-0.707-1.737-1.736 0.701-0.698 1.735 1.735zM3.987 14.969c-1.103 0-2-0.897-2-2s0.897-2 2-2 2 0.897 2 2-0.897 2-2 2z"
/>
</svg>
<h2
class="m-auto p-2"
style="text-align: center;"
>
Set new Admin key
</h2>
<button
class="ml-auto mr-0 btn btn-primary"
type="button"
>
<svg
fill="currentColor"
fill-rule="evenodd"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 1024 1024"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M799.855 166.312c.023.007.043.018.084.059l57.69 57.69c.041.041.052.06.059.084a.118.118 0 0 1 0 .069c-.007.023-.018.042-.059.083L569.926 512l287.703 287.703c.041.04.052.06.059.083a.118.118 0 0 1 0 .07c-.007.022-.018.042-.059.083l-57.69 57.69c-.041.041-.06.052-.084.059a.118.118 0 0 1-.069 0c-.023-.007-.042-.018-.083-.059L512 569.926 224.297 857.629c-.04.041-.06.052-.083.059a.118.118 0 0 1-.07 0c-.022-.007-.042-.018-.083-.059l-57.69-57.69c-.041-.041-.052-.06-.059-.084a.118.118 0 0 1 0-.069c.007-.023.018-.042.059-.083L454.073 512 166.371 224.297c-.041-.04-.052-.06-.059-.083a.118.118 0 0 1 0-.07c.007-.022.018-.042.059-.083l57.69-57.69c.041-.041.06-.052.084-.059a.118.118 0 0 1 .069 0c.023.007.042.018.083.059L512 454.073l287.703-287.702c.04-.041.06-.052.083-.059a.118.118 0 0 1 .07 0Z"
/>
</svg>
</button>
</div>
</div>
<div
class="modal-body"
>
<form
class="mb-2"
>
<div
class="mb-2 row"
>
<div
class="col-sm-4"
>
<label
class="form-label"
>
Current Password
</label>
</div>
<div
class="col"
>
<input
class="form-control"
name="oldPassword"
placeholder="Enter current admin password ..."
type="password"
/>
<div
class="invalid-feedback"
>
Old password is required
</div>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-4"
>
<label
class="form-label"
>
New Password
</label>
</div>
<div
class="col"
>
<input
class="form-control"
name="newPassword"
placeholder="Enter new admin password ..."
type="password"
/>
<div
class="invalid-feedback"
>
New password is required
</div>
</div>
</div>
<div
class="d-flex mx-auto mb-auto mt-2 w-100"
>
<button
class="btn btn-primary"
style="border-radius: 5px; margin-left: auto; margin-right: 10px;"
type="button"
>
Send
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
`;
exports[`AuthenticationModal renders as admin verification correctly 1`] = `
<body
class="modal-open"
data-rr-ui-modal-open=""
style="padding-right: 1024px;"
>
<div />
<div
class="fade modal-backdrop show"
/>
<div
aria-modal="true"
class="fade modal show"
role="dialog"
style="display: block; padding-right: 0px;"
tabindex="-1"
>
<div
class="modal-dialog modal-dialog-centered"
>
<div
class="modal-content"
>
<div
class="modal-header"
>
<div
class="w-100 d-flex modal-title h4"
>
<svg
class="ml-0 mr-auto"
fill="currentColor"
height="50"
stroke="currentColor"
stroke-width="0"
version="1.1"
viewBox="0 0 17 17"
width="50"
xmlns="http://www.w3.org/2000/svg"
>
<g />
<path
d="M14.811 6.299l0.707-0.707-1.733-1.733 0.757-0.753-0.705-0.709-8.146 8.107c-0.484-0.336-1.070-0.535-1.703-0.535-1.654 0-3 1.346-3 3s1.346 3 3 3 3-1.346 3-3c0-0.661-0.222-1.268-0.585-1.764l5.264-5.238 1.738 1.738 0.707-0.707-1.737-1.736 0.701-0.698 1.735 1.735zM3.987 14.969c-1.103 0-2-0.897-2-2s0.897-2 2-2 2 0.897 2 2-0.897 2-2 2z"
/>
</svg>
<h2
class="m-auto p-2"
style="text-align: center;"
>
Admin Login
</h2>
<button
class="ml-auto mr-0 btn btn-primary"
type="button"
>
<svg
fill="currentColor"
fill-rule="evenodd"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 1024 1024"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M799.855 166.312c.023.007.043.018.084.059l57.69 57.69c.041.041.052.06.059.084a.118.118 0 0 1 0 .069c-.007.023-.018.042-.059.083L569.926 512l287.703 287.703c.041.04.052.06.059.083a.118.118 0 0 1 0 .07c-.007.022-.018.042-.059.083l-57.69 57.69c-.041.041-.06.052-.084.059a.118.118 0 0 1-.069 0c-.023-.007-.042-.018-.083-.059L512 569.926 224.297 857.629c-.04.041-.06.052-.083.059a.118.118 0 0 1-.07 0c-.022-.007-.042-.018-.083-.059l-57.69-57.69c-.041-.041-.052-.06-.059-.084a.118.118 0 0 1 0-.069c.007-.023.018-.042.059-.083L454.073 512 166.371 224.297c-.041-.04-.052-.06-.059-.083a.118.118 0 0 1 0-.07c.007-.022.018-.042.059-.083l57.69-57.69c.041-.041.06-.052.084-.059a.118.118 0 0 1 .069 0c.023.007.042.018.083.059L512 454.073l287.703-287.702c.04-.041.06-.052.083-.059a.118.118 0 0 1 .07 0Z"
/>
</svg>
</button>
</div>
</div>
<div
class="modal-body"
>
<form
class="mb-2"
>
<div
class="mb-2 row"
>
<div
class="col"
>
<input
class="form-control"
name="password"
placeholder="Enter admin password ..."
type="password"
/>
<div
class="invalid-feedback"
>
Password is required
</div>
</div>
</div>
<div
class="d-flex mx-auto mb-auto mt-2 w-100"
>
<button
class="btn btn-primary"
style="border-radius: 5px; margin-left: auto; margin-right: 10px;"
type="button"
>
Send
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
`;

View file

@ -0,0 +1,495 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`BookModal renders without a book 1`] = `
<body
class="modal-open"
data-rr-ui-modal-open=""
style="padding-right: 1024px;"
>
<div />
<div
class="fade modal-backdrop show"
/>
<div
aria-modal="true"
class="fade modal show"
role="dialog"
style="display: block; padding-right: 0px;"
tabindex="-1"
>
<div
class="modal-dialog modal-dialog-centered"
>
<div
class="modal-content"
>
<div
class="modal-header"
>
<div
class="w-100 d-flex modal-title h4"
>
<svg
class="ml-0 mr-auto"
fill="currentColor"
height="50"
stroke="currentColor"
stroke-width="0"
version="1.1"
viewBox="0 0 16 16"
width="50"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M14 2v13h-10.5c-0.829 0-1.5-0.672-1.5-1.5s0.671-1.5 1.5-1.5h9.5v-12h-10c-1.1 0-2 0.9-2 2v12c0 1.1 0.9 2 2 2h12v-14h-1z"
/>
<path
d="M3.501 13v0c-0 0-0.001 0-0.001 0-0.276 0-0.5 0.224-0.5 0.5s0.224 0.5 0.5 0.5c0 0 0.001-0 0.001-0v0h9.498v-1h-9.498z"
/>
</svg>
<h2
class="m-auto p-2"
style="text-align: center;"
>
Add new Book
</h2>
<button
class="ml-auto mr-0 btn btn-primary"
type="button"
>
<svg
fill="currentColor"
fill-rule="evenodd"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 1024 1024"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M799.855 166.312c.023.007.043.018.084.059l57.69 57.69c.041.041.052.06.059.084a.118.118 0 0 1 0 .069c-.007.023-.018.042-.059.083L569.926 512l287.703 287.703c.041.04.052.06.059.083a.118.118 0 0 1 0 .07c-.007.022-.018.042-.059.083l-57.69 57.69c-.041.041-.06.052-.084.059a.118.118 0 0 1-.069 0c-.023-.007-.042-.018-.083-.059L512 569.926 224.297 857.629c-.04.041-.06.052-.083.059a.118.118 0 0 1-.07 0c-.022-.007-.042-.018-.083-.059l-57.69-57.69c-.041-.041-.052-.06-.059-.084a.118.118 0 0 1 0-.069c.007-.023.018-.042.059-.083L454.073 512 166.371 224.297c-.041-.04-.052-.06-.059-.083a.118.118 0 0 1 0-.07c.007-.022.018-.042.059-.083l57.69-57.69c.041-.041.06-.052.084-.059a.118.118 0 0 1 .069 0c.023.007.042.018.083.059L512 454.073l287.703-287.702c.04-.041.06-.052.083-.059a.118.118 0 0 1 .07 0Z"
/>
</svg>
</button>
</div>
</div>
<div
class="modal-body"
>
<form
class="mb-2"
>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
ISBN
</label>
</div>
<div
class="d-flex flex-column col"
>
<div
class="d-flex"
>
<input
class="form-control"
name="isbn"
style="border-radius: 5px 0px 0px 5px;"
/>
<button
class="mr-2 pt-0 btn btn-primary"
style="border-radius: 0px 5px 5px 0px;"
type="button"
>
<svg
fill="currentColor"
height="20"
stroke="currentColor"
stroke-width="0"
version="1.1"
viewBox="0 0 16 16"
width="20"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M4.75 9.5c0 1.795 1.455 3.25 3.25 3.25s3.25-1.455 3.25-3.25-1.455-3.25-3.25-3.25-3.25 1.455-3.25 3.25zM15 4h-3.5c-0.25-1-0.5-2-1.5-2h-4c-1 0-1.25 1-1.5 2h-3.5c-0.55 0-1 0.45-1 1v9c0 0.55 0.45 1 1 1h14c0.55 0 1-0.45 1-1v-9c0-0.55-0.45-1-1-1zM8 13.938c-2.451 0-4.438-1.987-4.438-4.438s1.987-4.438 4.438-4.438c2.451 0 4.438 1.987 4.438 4.438s-1.987 4.438-4.438 4.438zM15 7h-2v-1h2v1z"
/>
</svg>
</button>
</div>
<div
class="invalid-feedback"
style="display: none;"
>
ISBN is required
</div>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
Title
</label>
</div>
<div
class="col"
>
<input
class="form-control"
name="title"
/>
<div
class="invalid-feedback"
>
Title is required
</div>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
Year published
</label>
</div>
<div
class="col"
>
<input
class="form-control"
name="published"
/>
<div
class="invalid-feedback"
>
Year published is required
</div>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
Shelf
</label>
</div>
<div
class="col"
>
<select
class="form-select"
name="shelf"
>
<option
value="AVAILABLE"
>
available
</option>
<option
value="FNORD1"
>
fnord1
</option>
<option
value="FNORD2"
>
fnord2
</option>
<option
value="SHARING"
>
sharing
</option>
</select>
<div
class="invalid-feedback"
>
Shelf is required
</div>
</div>
</div>
<div
class="d-flex mx-auto mb-auto mt-2 w-100"
>
<button
class="btn btn-primary"
style="border-radius: 5px; margin-left: auto; margin-right: 10px;"
type="button"
>
Add Book
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
`;
exports[`BookModal sets book as default value 1`] = `
<body
class="modal-open"
data-rr-ui-modal-open=""
style="padding-right: 2048px;"
>
<div />
<div
class="fade modal-backdrop show"
/>
<div
aria-modal="true"
class="fade modal show"
role="dialog"
style="display: block; padding-right: 0px;"
tabindex="-1"
>
<div
class="modal-dialog modal-dialog-centered"
>
<div
class="modal-content"
>
<div
class="modal-header"
>
<div
class="w-100 d-flex modal-title h4"
>
<svg
class="ml-0 mr-auto"
fill="currentColor"
height="50"
stroke="currentColor"
stroke-width="0"
version="1.1"
viewBox="0 0 16 16"
width="50"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M14 2v13h-10.5c-0.829 0-1.5-0.672-1.5-1.5s0.671-1.5 1.5-1.5h9.5v-12h-10c-1.1 0-2 0.9-2 2v12c0 1.1 0.9 2 2 2h12v-14h-1z"
/>
<path
d="M3.501 13v0c-0 0-0.001 0-0.001 0-0.276 0-0.5 0.224-0.5 0.5s0.224 0.5 0.5 0.5c0 0 0.001-0 0.001-0v0h9.498v-1h-9.498z"
/>
</svg>
<h2
class="m-auto p-2"
style="text-align: center;"
>
Edit Book
</h2>
<button
class="ml-auto mr-0 btn btn-primary"
type="button"
>
<svg
fill="currentColor"
fill-rule="evenodd"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 1024 1024"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M799.855 166.312c.023.007.043.018.084.059l57.69 57.69c.041.041.052.06.059.084a.118.118 0 0 1 0 .069c-.007.023-.018.042-.059.083L569.926 512l287.703 287.703c.041.04.052.06.059.083a.118.118 0 0 1 0 .07c-.007.022-.018.042-.059.083l-57.69 57.69c-.041.041-.06.052-.084.059a.118.118 0 0 1-.069 0c-.023-.007-.042-.018-.083-.059L512 569.926 224.297 857.629c-.04.041-.06.052-.083.059a.118.118 0 0 1-.07 0c-.022-.007-.042-.018-.083-.059l-57.69-57.69c-.041-.041-.052-.06-.059-.084a.118.118 0 0 1 0-.069c.007-.023.018-.042.059-.083L454.073 512 166.371 224.297c-.041-.04-.052-.06-.059-.083a.118.118 0 0 1 0-.07c.007-.022.018-.042.059-.083l57.69-57.69c.041-.041.06-.052.084-.059a.118.118 0 0 1 .069 0c.023.007.042.018.083.059L512 454.073l287.703-287.702c.04-.041.06-.052.083-.059a.118.118 0 0 1 .07 0Z"
/>
</svg>
</button>
</div>
</div>
<div
class="modal-body"
>
<form
class="mb-2"
>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
ISBN
</label>
</div>
<div
class="d-flex flex-column col"
>
<div
class="d-flex"
>
<input
class="form-control"
name="isbn"
style="border-radius: 5px 0px 0px 5px;"
/>
<button
class="mr-2 pt-0 btn btn-primary"
style="border-radius: 0px 5px 5px 0px;"
type="button"
>
<svg
fill="currentColor"
height="20"
stroke="currentColor"
stroke-width="0"
version="1.1"
viewBox="0 0 16 16"
width="20"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M4.75 9.5c0 1.795 1.455 3.25 3.25 3.25s3.25-1.455 3.25-3.25-1.455-3.25-3.25-3.25-3.25 1.455-3.25 3.25zM15 4h-3.5c-0.25-1-0.5-2-1.5-2h-4c-1 0-1.25 1-1.5 2h-3.5c-0.55 0-1 0.45-1 1v9c0 0.55 0.45 1 1 1h14c0.55 0 1-0.45 1-1v-9c0-0.55-0.45-1-1-1zM8 13.938c-2.451 0-4.438-1.987-4.438-4.438s1.987-4.438 4.438-4.438c2.451 0 4.438 1.987 4.438 4.438s-1.987 4.438-4.438 4.438zM15 7h-2v-1h2v1z"
/>
</svg>
</button>
</div>
<div
class="invalid-feedback"
style="display: none;"
>
ISBN is required
</div>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
Title
</label>
</div>
<div
class="col"
>
<input
class="form-control"
name="title"
/>
<div
class="invalid-feedback"
/>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
Year published
</label>
</div>
<div
class="col"
>
<input
class="form-control"
name="published"
/>
<div
class="invalid-feedback"
/>
</div>
</div>
<div
class="mb-2 row"
>
<div
class="col-sm-2"
>
<label
class="form-label"
>
Shelf
</label>
</div>
<div
class="col"
>
<select
class="form-select"
name="shelf"
>
<option
value="AVAILABLE"
>
available
</option>
<option
value="FNORD1"
>
fnord1
</option>
<option
value="FNORD2"
>
fnord2
</option>
<option
value="SHARING"
>
sharing
</option>
</select>
<div
class="invalid-feedback"
/>
</div>
</div>
<div
class="d-flex mx-auto mb-auto mt-2 w-100"
>
<button
class="btn btn-primary"
style="border-radius: 5px; margin-left: auto; margin-right: 10px;"
type="button"
>
Submit
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
`;