-
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.
Initial tests for the DocumentUpload component
Refactors `$page.data` state into props passed from `+page.svelte` for greater isolation and data decoupling.
- Loading branch information
1 parent
aba9fa3
commit b42ea58
Showing
4 changed files
with
55 additions
and
11 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
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
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,44 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { | ||
act, | ||
render, | ||
screen, | ||
fireEvent, | ||
createEvent, | ||
} from "@testing-library/svelte"; | ||
|
||
import DocumentUploadForm from "../DocumentUpload.svelte"; | ||
import { PDF_SIZE_LIMIT } from "@/config/config"; | ||
|
||
describe("DocumentUpload form", () => { | ||
it("lists files selected for upload", async () => { | ||
render(DocumentUploadForm); | ||
const dropElement = screen.getByText("Drag and drop files here"); | ||
const dropEvent = createEvent.drop(dropElement); | ||
const fileList = [new File([new ArrayBuffer(128000)], "file.pdf")]; | ||
Object.defineProperty(dropEvent, "dataTransfer", { | ||
value: { | ||
files: fileList, | ||
}, | ||
}); | ||
await act(() => fireEvent(dropElement, dropEvent)); | ||
const fileListItem = screen.getByRole("listitem"); | ||
expect(fileListItem).toContainHTML("128 kB"); | ||
}); | ||
it("provides feedback when a file is too large", async () => { | ||
render(DocumentUploadForm); | ||
const dropElement = screen.getByText("Drag and drop files here"); | ||
const dropEvent = createEvent.drop(dropElement); | ||
const fileList = [ | ||
new File([new ArrayBuffer(PDF_SIZE_LIMIT + 1)], "file.pdf"), | ||
]; | ||
Object.defineProperty(dropEvent, "dataTransfer", { | ||
value: { | ||
files: fileList, | ||
}, | ||
}); | ||
await act(() => fireEvent(dropElement, dropEvent)); | ||
const fileListItem = screen.getByRole("listitem"); | ||
expect(fileListItem).toContainHTML("The maximum size for a PDF is 500MB"); | ||
}); | ||
}); |
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