learn and share notes on atproto (wip) 馃 malfestio.stormlightlabs.org/
readability solid axum atproto srs
at main 56 lines 2.2 kB view raw
1import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; 2import { afterEach, describe, expect, it, vi } from "vitest"; 3import FileDropZone from "../FileDropZone"; 4 5describe("FileDropZone", () => { 6 afterEach(cleanup); 7 8 it("renders correctly", () => { 9 render(() => <FileDropZone onFileSelect={() => {}} />); 10 expect(screen.getByText("Click to upload or drag and drop")).toBeInTheDocument(); 11 expect(screen.getByText("PDF or DOCX (max 10MB)")).toBeInTheDocument(); 12 }); 13 14 it("handles file selection via input change", () => { 15 const onFileSelectRequest = vi.fn(); 16 render(() => <FileDropZone onFileSelect={onFileSelectRequest} />); 17 18 const file = new File(["dummy content"], "test.pdf", { type: "application/pdf" }); 19 const input = screen.getByTestId("file-upload-input"); 20 21 Object.defineProperty(input, "files", { value: [file] }); 22 23 fireEvent.change(input); 24 25 expect(onFileSelectRequest).toHaveBeenCalledWith(file); 26 }); 27 28 it("handles drag and drop", () => { 29 const onFileSelectRequest = vi.fn(); 30 render(() => <FileDropZone onFileSelect={onFileSelectRequest} />); 31 32 const dropZone = screen.getByText("Click to upload or drag and drop").closest("div"); 33 expect(dropZone).not.toBeNull(); 34 35 const file = new File(["dummy content"], "lecture.pdf", { type: "application/pdf" }); 36 37 fireEvent.drop(dropZone!, { dataTransfer: { files: [file] } }); 38 39 expect(onFileSelectRequest).toHaveBeenCalledWith(file); 40 }); 41 42 it("validates file size", () => { 43 const onFileSelectRequest = vi.fn(); 44 const onErrorRequest = vi.fn(); 45 render(() => <FileDropZone onFileSelect={onFileSelectRequest} onError={onErrorRequest} maxSize={10} />); // 10 bytes limit 46 47 const file = new File(["content larger than 10 bytes"], "large.pdf", { type: "application/pdf" }); 48 const input = screen.getByTestId("file-upload-input"); 49 50 Object.defineProperty(input, "files", { value: [file] }); 51 fireEvent.change(input); 52 53 expect(onFileSelectRequest).not.toHaveBeenCalled(); 54 expect(onErrorRequest).toHaveBeenCalledWith(expect.stringContaining("File size exceeds limit")); 55 }); 56});