test: close the remaining gaps and raise the thresholds

Pushes lines from 95.2% to 98.1% and branches from 85.2% to 89.9%, mostly
in the release-notes modal, the reservation overlay, the journey entry sheet
and the trip dialogs.
This commit is contained in:
Maurice
2026-07-29 10:24:39 +02:00
committed by Maurice
parent b80bd3992b
commit 02ad6c3d16
27 changed files with 3332 additions and 77 deletions
@@ -1,4 +1,4 @@
// FE-W5CCM-001 to FE-W5CCM-022
// FE-W5CCM-001 to FE-W5CCM-024
// ChatMessages is a pure presentational component — every piece of state arrives
// as a prop from useCollabChat, so the tests drive it directly instead of going
// through CollabChat (that path is covered in CollabChat.test.tsx).
@@ -1270,7 +1270,7 @@ describe('CollabNotes', () => {
});
});
// FE-W5CNT-001 to FE-W5CNT-026
// FE-W5CNT-001 to FE-W5CNT-028
// Fills in the load/error/attachment/category branches of useCollabNotes and the
// view modal that the smoke tests above do not reach.
@@ -1602,7 +1602,10 @@ describe('CollabNotes details', () => {
it('FE-W5CNT-020: a failing upload during an edit reports an error', async () => {
const user = userEvent.setup();
serveNotes({ notes: [buildNote({ id: 3, title: 'Edit me' })] });
serveNotesSequence([
{ notes: [buildNote({ id: 3, title: 'Edit me' })] },
[buildNote({ id: 3, title: 'Ignored reload' })],
]);
server.use(
http.put('/api/trips/1/collab/notes/3', () =>
HttpResponse.json({ note: buildNote({ id: 3, title: 'Edit me' }) }),
@@ -1616,6 +1619,7 @@ describe('CollabNotes details', () => {
pasteFile('nope.png');
await user.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Error', 'error', undefined));
expect(screen.queryByText('Ignored reload')).not.toBeInTheDocument();
});
it('FE-W5CNT-021: a failing attachment removal reports an error', async () => {
@@ -1645,15 +1649,17 @@ describe('CollabNotes details', () => {
buildNote({ id: 1, title: 'No timestamps', updated_at: null, created_at: null }),
buildNote({ id: 2, title: 'Pinned one', pinned: true }),
buildNote({ id: 3, title: 'Created only', updated_at: null, created_at: '2025-06-02T10:00:00.000Z' }),
buildNote({ id: 4, title: 'Also undated', updated_at: null, created_at: null }),
],
});
const known = ['No timestamps', 'Pinned one', 'Created only', 'Also undated'];
render(<CollabNotes {...defaultProps} />);
await screen.findByText('Pinned one');
const titles = Array.from(document.querySelectorAll('span'))
.filter(el => el.childElementCount === 0)
.map(el => el.textContent)
.filter(text => ['No timestamps', 'Pinned one', 'Created only'].includes(text ?? ''));
expect(titles).toEqual(['Pinned one', 'Created only', 'No timestamps']);
.filter(text => known.includes(text ?? ''));
expect(titles).toEqual(['Pinned one', 'Created only', 'No timestamps', 'Also undated']);
});
it('FE-W5CNT-023: clicking the active category pill clears the filter again', async () => {
@@ -1723,7 +1729,7 @@ describe('CollabNotes details', () => {
content: 'See attachments',
attachments: [
{ id: 1, filename: 'a.png', original_name: 'map.png', mime_type: 'image/png', url: '/uploads/map.png' },
{ id: 2, filename: 'b.txt', original_name: 'itinerary.txt', mime_type: 'text/plain', url: '/uploads/itinerary.txt' },
{ id: 2, filename: 'b.zip', original_name: 'itinerary.zip', mime_type: 'application/zip', url: '/uploads/itinerary.zip' },
{ id: 3, filename: 'c', url: '/uploads/c' },
],
})],
@@ -1740,15 +1746,16 @@ describe('CollabNotes details', () => {
// Unknown mime type and missing name fall back to a "?" tile
expect(within(modal).getByText('?')).toBeInTheDocument();
const txtTile = within(modal).getByTitle('itinerary.txt');
expect(txtTile.style.background).toBe('var(--bg-secondary)');
fireEvent.mouseEnter(txtTile);
expect(txtTile.style.transform).toBe('scale(1.06)');
fireEvent.mouseLeave(txtTile);
expect(txtTile.style.transform).toBe('scale(1)');
fireEvent.click(txtTile);
const zipTile = within(modal).getByTitle('itinerary.zip');
expect(zipTile.style.background).toBe('var(--bg-secondary)');
expect(within(modal).getByText('ZIP')).toBeInTheDocument();
fireEvent.mouseEnter(zipTile);
expect(zipTile.style.transform).toBe('scale(1.06)');
fireEvent.mouseLeave(zipTile);
expect(zipTile.style.transform).toBe('scale(1)');
fireEvent.click(zipTile);
// FilePreviewPortal shows a download action for non-image files
expect(await screen.findByText('Download itinerary.txt')).toBeInTheDocument();
expect(await screen.findByText('Download itinerary.zip')).toBeInTheDocument();
const image = await waitFor(() => {
const img = modal.querySelector('img[alt="map.png"]') as HTMLImageElement | null;
@@ -1760,6 +1767,39 @@ describe('CollabNotes details', () => {
fireEvent.mouseLeave(image);
expect(image.style.transform).toBe('scale(1)');
fireEvent.click(image);
await waitFor(() => expect(screen.queryByText('Download itinerary.txt')).not.toBeInTheDocument());
await waitFor(() => expect(screen.queryByText('Download itinerary.zip')).not.toBeInTheDocument());
});
it('FE-W5CNT-027: a create response for a note already in the list is not added twice', async () => {
const user = userEvent.setup();
serveNotes({ notes: [buildNote({ id: 20, title: 'Fresh note' })] });
server.use(
http.post('/api/trips/1/collab/notes', () =>
HttpResponse.json({ note: buildNote({ id: 20, title: 'Fresh note' }) }),
),
);
render(<CollabNotes {...defaultProps} />);
await screen.findByText('Fresh note');
await user.click(screen.getByText('New Note'));
await user.type(await screen.findByPlaceholderText('Note title'), 'Fresh note');
await user.click(screen.getByRole('button', { name: 'Create' }));
await waitFor(() => expect(screen.queryByPlaceholderText('Note title')).not.toBeInTheDocument());
expect(screen.getAllByText('Fresh note')).toHaveLength(1);
});
it('FE-W5CNT-028: a second note created elsewhere is prepended to the existing list', async () => {
const user = userEvent.setup();
serveNotes({ notes: [buildNote({ id: 20, title: 'Older note' })] });
server.use(
http.post('/api/trips/1/collab/notes', () =>
HttpResponse.json({ note: buildNote({ id: 21, title: 'Newer note' }) }),
),
);
render(<CollabNotes {...defaultProps} />);
await screen.findByText('Older note');
await user.click(screen.getByText('New Note'));
await user.type(await screen.findByPlaceholderText('Note title'), 'Newer note');
await user.click(screen.getByRole('button', { name: 'Create' }));
await screen.findByText('Newer note');
expect(screen.getByText('Older note')).toBeInTheDocument();
});
});
@@ -1,4 +1,4 @@
// FE-W5CNF-001 to FE-W5CNF-018
// FE-W5CNF-001 to FE-W5CNF-021
// NoteFormModal takes everything it needs as props, so the tests drive it
// directly rather than through CollabNotes.
@@ -274,7 +274,7 @@ describe('CollabPolls', () => {
});
});
// FE-W5CPL-001 to FE-W5CPL-026
// FE-W5CPL-001 to FE-W5CPL-028
// Covers the deadline maths, the voter chips, the error paths of every mutation
// and the WebSocket handler branches that the smoke tests above skip.
@@ -410,7 +410,7 @@ describe('CollabPolls details', () => {
polls: [buildPoll({
is_closed: true,
options: [
{ id: 1, text: 'Paris', voters: [{ user_id: 4, username: '', avatar_url: null }] },
{ id: 1, text: 'Paris', voters: [{ user_id: null, username: '', avatar_url: null }] },
{ id: 2, text: 'Rome', voters: [] },
],
})],
@@ -448,9 +448,9 @@ describe('CollabPolls details', () => {
expect(screen.getAllByText('Closed')).toHaveLength(2);
});
it('FE-W5CPL-014: closing a poll marks it closed and moves it out of the active list', async () => {
it('FE-W5CPL-014: closing a poll marks it closed and leaves the other one open', async () => {
let closeCalled = false;
servePolls({ polls: [buildPoll({ id: 5 })] });
servePolls({ polls: [buildPoll({ id: 5 }), buildPoll({ id: 6, question: 'Stays open?' })] });
server.use(
http.put('/api/trips/1/collab/polls/5/close', () => {
closeCalled = true;
@@ -459,11 +459,38 @@ describe('CollabPolls details', () => {
);
const user = userEvent.setup();
render(<CollabPolls {...defaultProps} />);
await screen.findByText('Best destination?');
await user.click(screen.getByTitle(/close/i));
await screen.findByText('Stays open?');
// Both action buttons highlight on hover
const closeBtn = screen.getAllByTitle('Close')[0];
fireEvent.mouseEnter(closeBtn);
expect(closeBtn.style.color).toBe('var(--text-primary)');
fireEvent.mouseLeave(closeBtn);
expect(closeBtn.style.color).toBe('var(--text-faint)');
const deleteBtn = screen.getAllByTitle('Delete')[0];
fireEvent.mouseEnter(deleteBtn);
expect(deleteBtn.style.color).toBe('rgb(239, 68, 68)');
fireEvent.mouseLeave(deleteBtn);
expect(deleteBtn.style.color).toBe('var(--text-faint)');
await user.click(closeBtn);
await waitFor(() => expect(closeCalled).toBe(true));
expect(await screen.findByText(/closed/i)).toBeInTheDocument();
expect(screen.queryByTitle(/close/i)).not.toBeInTheDocument();
await waitFor(() => expect(screen.getAllByText('Closed')).toHaveLength(2));
expect(screen.getAllByTitle('Close')).toHaveLength(1);
});
it('FE-W5CPL-027: a failing poll request falls back to the empty state', async () => {
server.use(
http.get('/api/trips/1/collab/polls', () => new HttpResponse(null, { status: 500 })),
);
render(<CollabPolls {...defaultProps} />);
await screen.findByText(/no polls yet|collab\.polls\.empty/i);
});
it('FE-W5CPL-028: a payload without a polls key yields an empty list', async () => {
servePolls({});
render(<CollabPolls {...defaultProps} />);
await screen.findByText(/no polls yet|collab\.polls\.empty/i);
});
it('FE-W5CPL-015: a failing close shows an error and leaves the poll open', async () => {