|
| 1 | +import { describe, expect, it, vi, beforeEach, type Mock } from "vitest"; |
| 2 | +import { type RenderResult, render } from "@testing-library/react"; |
| 3 | +import MyDropzone from "./Dropzone"; |
| 4 | + |
| 5 | +interface Props { |
| 6 | + openDialog?: { mode: string }; |
| 7 | + loading?: boolean; |
| 8 | + files?: File[]; |
| 9 | + clickToOpen?: boolean; |
| 10 | + showDropZone?: boolean; |
| 11 | +} |
| 12 | + |
| 13 | +describe("~/components/Dropzone.tsx", () => { |
| 14 | + let wrapper: RenderResult; |
| 15 | + let onDrop: Mock; |
| 16 | + |
| 17 | + const createWrapper = ({ |
| 18 | + showDropZone, |
| 19 | + clickToOpen, |
| 20 | + openDialog, |
| 21 | + files = [], |
| 22 | + }: Props) => { |
| 23 | + onDrop = vi.fn(); |
| 24 | + wrapper = render( |
| 25 | + <MyDropzone |
| 26 | + openDialog={openDialog} |
| 27 | + onDrop={onDrop} |
| 28 | + files={files} |
| 29 | + showDropZone={showDropZone} |
| 30 | + clickToOpen={clickToOpen} |
| 31 | + /> |
| 32 | + ); |
| 33 | + }; |
| 34 | + |
| 35 | + describe("with no files and showDropZone = true ", () => { |
| 36 | + beforeEach(() => { |
| 37 | + createWrapper({ showDropZone: true, clickToOpen: true }); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should mount dropzone", () => { |
| 41 | + expect(wrapper.getByTestId("my-dropzone")).toBeTruthy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should display an empty message", () => { |
| 45 | + expect(wrapper.getByText("No files uploaded yet")).toBeTruthy(); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should display a click here message", () => { |
| 49 | + expect(wrapper.getByText("Click or drop here")).toBeTruthy(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe("with no files and showDropZone = false ", () => { |
| 54 | + beforeEach(() => { |
| 55 | + createWrapper({ showDropZone: false }); |
| 56 | + }); |
| 57 | + |
| 58 | + it("should mount dropzone", () => { |
| 59 | + expect(wrapper.getByTestId("my-dropzone")).toBeTruthy(); |
| 60 | + }); |
| 61 | + |
| 62 | + it("should not display an empty message", () => { |
| 63 | + expect(() => wrapper.getByText("No files uploaded yet")).toThrow(); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should not display a drop here message", () => { |
| 67 | + expect(() => wrapper.getByText("Drop here")).toThrow(); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments