feat(documents): bulk upload — split-panel with file switcher #329

Merged
marcel merged 46 commits from feat/issue-317-bulk-upload into main 2026-04-25 12:24:25 +02:00
2 changed files with 36 additions and 4 deletions
Showing only changes of commit 74b473e3d7 - Show all commits

View File

@@ -109,10 +109,14 @@ async function save() {
if (!res.ok) {
hadErrors = true;
const body = await res.json().catch(() => ({ errors: [] }));
const errorCount = (body.errors ?? []).length;
for (let j = 0; j < errorCount && j < chunk.length; j++) {
const e = files.get(chunk[j].id);
if (e) files.set(chunk[j].id, { ...e, status: 'error' });
const errorFilenames = new Set<string>(
(body.errors ?? []).map((err: { filename: string }) => err.filename)
);
for (const entry of chunk) {
if (errorFilenames.has(entry.file.name)) {
const e = files.get(entry.id);
if (e) files.set(entry.id, { ...e, status: 'error' });
}
}
}
chunkProgress = { done: i + 1, total: chunks.length };

View File

@@ -159,6 +159,34 @@ describe('BulkDocumentEditLayout', () => {
expect(goto).not.toHaveBeenCalled();
});
it('save marks only the file whose filename matches the backend error, not adjacent files', async () => {
// backend returns error keyed to b.pdf — only b.pdf chip should get data-status="error"
const mockFetch = vi.fn().mockResolvedValue({
ok: false,
json: async () => ({ errors: [{ filename: 'b.pdf', code: 'FILE_UPLOAD_FAILED' }] })
});
vi.stubGlobal('fetch', mockFetch);
const { container } = render(BulkDocumentEditLayout, {});
await addFilesViaInput(container, [makeFile('a.pdf'), makeFile('b.pdf'), makeFile('c.pdf')]);
const saveBtn = container.querySelector(
'button[data-testid="bulk-save-btn"]'
) as HTMLButtonElement;
saveBtn.click();
await vi.waitFor(() => expect(mockFetch).toHaveBeenCalledTimes(1), { timeout: 3000 });
await vi.waitFor(
() => {
const errorChips = container.querySelectorAll('[data-chip-id][data-status="error"]');
expect(errorChips.length).toBe(1);
expect(errorChips[0].textContent).toContain('b');
},
{ timeout: 1000 }
);
});
it('discard-all resets to N=0 state and shows drop zone', async () => {
const { container } = render(BulkDocumentEditLayout, {});
await addFilesViaInput(container, [makeFile('a.pdf'), makeFile('b.pdf')]);