feat(BookModal): update tests

This commit is contained in:
0ry5 2025-01-17 15:14:56 +01:00
parent b25c54915f
commit 6548250178
2 changed files with 32 additions and 67 deletions

View file

@ -1,29 +1,44 @@
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import { BookModal } from "../BookModal"; import { BookModal } from "../BookModal";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
describe("BookModal", () => { describe("BookModal", () => {
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({ test: 100 }),
})
) as jest.Mock;
const queryClient = new QueryClient();
it("renders without a book", () => { it("renders without a book", () => {
const view = render(<BookModal open={true} onClose={() => undefined} />); const view = render(
<QueryClientProvider client={queryClient}>
<BookModal open={true} onClose={() => undefined} />
</QueryClientProvider>
);
expect(view.baseElement).toMatchSnapshot(); expect(view.baseElement).toMatchSnapshot();
}); });
it("sets book as default value", () => { it("sets book as default value", () => {
const view = render( const view = render(
<BookModal <QueryClientProvider client={queryClient}>
open={true} <BookModal
onClose={() => undefined} open={true}
book={{ onClose={() => undefined}
id: 1, book={{
uuid: "mockedbook", id: 1,
isbn: "123", uuid: "mockedbook",
title: "mockedbook", isbn: "123",
published: 2024, title: "mockedbook",
lastCheckoutDate: null, published: 2024,
checkoutBy: null, lastCheckoutDate: null,
shelf: "AVAILABLE", checkoutBy: null,
contact: null, shelf: "AVAILABLE",
}} contact: null,
/> }}
/>
</QueryClientProvider>
); );
expect(view.baseElement).toMatchSnapshot(); expect(view.baseElement).toMatchSnapshot();
}); });

View file

@ -199,35 +199,10 @@ exports[`BookModal renders without a book 1`] = `
<div <div
class="col" 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 <div
class="invalid-feedback" class="invalid-feedback"
> >
Shelf is required Target shelf is required
</div> </div>
</div> </div>
</div> </div>
@ -445,31 +420,6 @@ exports[`BookModal sets book as default value 1`] = `
<div <div
class="col" 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 <div
class="invalid-feedback" class="invalid-feedback"
/> />