shoc-frontend-new/src/test/app/(protected)/workorders/uplift-attachment-picker.test.tsx
Arthur Bassi 64686a59eb feat(work-orders): accept more than one uplift evidence file
Stage every selected file, wait for each scan, and download by document id.
Refresh the work-order detail snapshot for the current tab strip.
2026-09-28 16:25:45 -03:00

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]);
});
});