mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
ajout test ImageGalleryModal
This commit is contained in:
parent
755d14a5b7
commit
78e398ecd8
2 changed files with 46 additions and 1 deletions
|
|
@ -0,0 +1,44 @@
|
|||
import React from "react";
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import ImageGalleryModal from "../../../components/ImageGallery/ImageGalleryModal/ImageGalleryModal";
|
||||
import "@testing-library/jest-dom";
|
||||
|
||||
jest.mock("../../../components/ImageGallery/ImageGallery", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => <div data-testid="image-gallery" />),
|
||||
}));
|
||||
|
||||
describe("ImageGalleryModal", () => {
|
||||
|
||||
it("renders button correctly", () => {
|
||||
render(<ImageGalleryModal />);
|
||||
|
||||
const button = screen.getByLabelText(/images-open/i);
|
||||
expect(button).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens the modal when button is clicked", () => {
|
||||
render(<ImageGalleryModal />);
|
||||
|
||||
const button = screen.getByRole("button", { name: /images/i });
|
||||
fireEvent.click(button);
|
||||
|
||||
const dialog = screen.getByRole("dialog");
|
||||
expect(dialog).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
it("closes the modal when close button is clicked", async () => {
|
||||
render(<ImageGalleryModal />);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /images/i }));
|
||||
|
||||
const closeButton = screen.getByRole("button", { name: /close/i });
|
||||
fireEvent.click(closeButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -25,7 +25,7 @@ const ImageGalleryModal: React.FC<ImageGalleryModalProps> = ({ handleCopy }) =>
|
|||
<>
|
||||
<Button
|
||||
variant="outlined"
|
||||
aria-label='Téléverser'
|
||||
aria-label='images-open'
|
||||
onClick={() => handleOpen()}>
|
||||
Images <ImageSearch />
|
||||
</Button>
|
||||
|
|
@ -34,6 +34,7 @@ const ImageGalleryModal: React.FC<ImageGalleryModalProps> = ({ handleCopy }) =>
|
|||
<IconButton
|
||||
onClick={handleClose}
|
||||
color="primary"
|
||||
aria-label="close"
|
||||
sx={{
|
||||
position: "absolute",
|
||||
right: 8,
|
||||
|
|
|
|||
Loading…
Reference in a new issue