Skip to content

Commit

Permalink
Tests Dropzone component
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 15, 2024
1 parent 1d3c390 commit aba9fa3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib/components/inputs/tests/Dropzone.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit aba9fa3

Please sign in to comment.