-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d3c390
commit aba9fa3
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |