mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 10:12:05 +00:00
Stage every selected file, wait for each scan, and download by document id. Refresh the work-order detail snapshot for the current tab strip.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { useState } from "react";
|
|
import { fireEvent, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { UpliftAttachmentPicker } from "@/app/(protected)/workorders/_components/uplifts/uplift-attachment-picker";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
function PickerHarness({ onChange }: { onChange: (files: File[]) => void }) {
|
|
const [files, setFiles] = useState<File[]>([]);
|
|
return (
|
|
<UpliftAttachmentPicker
|
|
files={files}
|
|
onChange={(next) => {
|
|
setFiles(next);
|
|
onChange(next);
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function selectFiles(files: File[]) {
|
|
const input = document.querySelector('input[type="file"]');
|
|
fireEvent.change(input as HTMLInputElement, { target: { files } });
|
|
}
|
|
|
|
describe("UpliftAttachmentPicker", () => {
|
|
it("keeps every allowed file from one multi-select", () => {
|
|
const onChange = vi.fn();
|
|
renderWithProviders(<PickerHarness onChange={onChange} />);
|
|
const quote = new File(["%PDF"], "quote.pdf", { type: "application/pdf" });
|
|
const notes = new File(["text"], "notes.txt", { type: "text/plain" });
|
|
const photo = new File(["jpeg"], "photo.jpg", { type: "image/jpeg" });
|
|
|
|
selectFiles([quote, notes, photo]);
|
|
|
|
expect(screen.getByText("quote.pdf")).toBeInTheDocument();
|
|
expect(screen.getByText("photo.jpg")).toBeInTheDocument();
|
|
expect(screen.queryByText("notes.txt")).not.toBeInTheDocument();
|
|
expect(onChange).toHaveBeenCalledWith([quote, photo]);
|
|
expect(document.querySelector('input[type="file"]')?.hasAttribute("multiple")).toBe(true);
|
|
});
|
|
|
|
it("appends a later selection instead of replacing the staged files", () => {
|
|
const onChange = vi.fn();
|
|
renderWithProviders(<PickerHarness onChange={onChange} />);
|
|
const quote = new File(["%PDF"], "quote.pdf", { type: "application/pdf" });
|
|
const photo = new File(["jpeg"], "photo.jpg", { type: "image/jpeg" });
|
|
|
|
selectFiles([quote]);
|
|
selectFiles([photo]);
|
|
|
|
expect(screen.getByText("quote.pdf")).toBeInTheDocument();
|
|
expect(screen.getByText("photo.jpg")).toBeInTheDocument();
|
|
expect(onChange).toHaveBeenLastCalledWith([quote, photo]);
|
|
});
|
|
});
|