diff --git a/src/lib/components/inputs/tests/Dropzone.test.ts b/src/lib/components/inputs/tests/Dropzone.test.ts new file mode 100644 index 000000000..92ea273db --- /dev/null +++ b/src/lib/components/inputs/tests/Dropzone.test.ts @@ -0,0 +1,45 @@ +import { vi, describe, it, expect } from "vitest"; +import { + render, + screen, + fireEvent, + createEvent, +} from "@testing-library/svelte"; + +import Dropzone from "../Dropzone.svelte"; + +describe("Dropzone", () => { + it("fires a handler upon a drop event", () => { + const onDrop = vi.fn(); + render(Dropzone, { + onDrop, + }); + const dropElement = screen.getByRole("button"); + const dropEvent = createEvent.drop(dropElement); + const fileList = [new File([], "file.pdf")]; + Object.defineProperty(dropEvent, "dataTransfer", { + value: { + files: fileList, + }, + }); + fireEvent(dropElement, dropEvent); + expect(onDrop).toHaveBeenCalledWith(fileList); + }); + it("does not fire if disabled", () => { + const onDrop = vi.fn(); + render(Dropzone, { + onDrop, + disabled: true, + }); + const dropElement = screen.getByRole("button"); + const dropEvent = createEvent.drop(dropElement); + const fileList = [new File([], "file.pdf")]; + Object.defineProperty(dropEvent, "dataTransfer", { + value: { + files: fileList, + }, + }); + fireEvent(dropElement, dropEvent); + expect(onDrop).not.toHaveBeenCalledWith(fileList); + }); +});