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,14 +1,28 @@
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(
<QueryClientProvider client={queryClient}>
<BookModal <BookModal
open={true} open={true}
onClose={() => undefined} onClose={() => undefined}
@ -24,6 +38,7 @@ describe("BookModal", () => {
contact: null, 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"
/> />