fix(collab): note attachments added or removed on the phone show in the Files tab at once

On the phone, attaching a file to a note, detaching one or deleting a
note with attachments left the trip's Files tab on the old list until a
reload. The desktop panel fires the local collab-files-changed event
that useTripWebSocket listens for, because the server leaves the
writer's own socket out of its broadcast; the phone notes tab never
fired it.

The event now lives in the shared useCollabNotesData hook:
uploadNoteFiles announces it once after a batch, and
announceNoteFilesChanged is what both shells call after deleting a note
or a note file. The desktop no longer fires it by hand after an upload.

Red before the fix: tests/unit/mobile/trip/MCollabNotes.test.tsx
FE-MOB-CNOTE-034 failed with "expected 0 to be 1" on the event count
after detaching a file. FE-COLLAB-NOTESDATA-009 covers the hook.
No existing assertions changed.
This commit is contained in:
Maurice
2026-10-09 17:26:25 +02:00
parent 0246e5c317
commit f19b52fb20
5 changed files with 69 additions and 8 deletions
@@ -1,4 +1,4 @@
// FE-COLLAB-NOTESDATA-001 to FE-COLLAB-NOTESDATA-008: the note list behind the desktop
// FE-COLLAB-NOTESDATA-001 to FE-COLLAB-NOTESDATA-009: the note list behind the desktop
// Collab panel (empties on a failed load, waits for a trip id) and the phone's notes tab
// (keeps the list, always loads), with
// the live note events and the attachment upload both run after saving a note.
@@ -170,4 +170,23 @@ describe('useCollabNotesData', () => {
act(() => result.current.setNotes([note(9)]));
expect(result.current.notes.map((n) => n.id)).toEqual([9]);
});
it('FE-COLLAB-NOTESDATA-009: an upload batch tells the Files tab to reload once, an empty one does not', async () => {
const onFilesChanged = vi.fn();
window.addEventListener('collab-files-changed', onFilesChanged);
try {
vi.mocked(collabApi.uploadNoteFile).mockRejectedValueOnce(new Error('too big'));
const { result } = await loaded();
await act(async () => {
await result.current.uploadNoteFiles(5, []);
});
expect(onFilesChanged).not.toHaveBeenCalled();
await act(async () => {
await result.current.uploadNoteFiles(5, [new File(['a'], 'a.pdf'), new File(['b'], 'b.pdf')]);
});
expect(onFilesChanged).toHaveBeenCalledTimes(1);
} finally {
window.removeEventListener('collab-files-changed', onFilesChanged);
}
});
});