fix(client): work through the findings from the coverage pass

214 items came out of writing the tests. Real defects are corrected, dead code
is removed rather than covered, and the tests that pinned the old behaviour
move with them.

Also drops two agent coverage scratch files that slipped into the coverage PR
and adds the ignore rule that keeps them out.
This commit is contained in:
Maurice
2026-07-29 11:57:24 +02:00
committed by Maurice
parent a4bf815d24
commit 72a82b3c44
425 changed files with 3155 additions and 1968 deletions
@@ -261,6 +261,14 @@ describe('AddPlaceToCollectionModal', () => {
expect(screen.getByPlaceholderText('Longitude (e.g. 2.3522)')).toHaveValue('2.3522')
})
it('FE-COMP-ADDPLACECOL-015b: the pair is split the same way when pasted into longitude', () => {
setup()
const lng = screen.getByPlaceholderText('Longitude (e.g. 2.3522)')
fireEvent.paste(lng, { clipboardData: { getData: () => '48.8566, 2.3522' } })
expect(screen.getByPlaceholderText('Latitude (e.g. 48.8566)')).toHaveValue('48.8566')
expect(lng).toHaveValue('2.3522')
})
it('FE-COMP-ADDPLACECOL-016: a paste that is not a coordinate pair is left to the input', () => {
setup()
const lat = screen.getByPlaceholderText('Latitude (e.g. 48.8566)')
@@ -192,7 +192,7 @@ export default function AddPlaceToCollectionModal({ isOpen, collectionId, collec
<input value={address} onChange={e => setAddress(e.target.value)} placeholder={t('places.formAddressPlaceholder')} className={coordInputClass} />
<div className="grid grid-cols-2 gap-2 mt-2">
<NumericInput mode="signed" value={lat} onValueChange={setLat} onPaste={coordPaste} placeholder={t('places.formLat')} className={coordInputClass} />
<NumericInput mode="signed" value={lng} onValueChange={setLng} placeholder={t('places.formLng')} className={coordInputClass} />
<NumericInput mode="signed" value={lng} onValueChange={setLng} onPaste={coordPaste} placeholder={t('places.formLng')} className={coordInputClass} />
</div>
</div>
@@ -31,6 +31,28 @@ function distanceTo(p: CollectionPlace, center: { lat: number; lng: number }): n
interface Opt { key: string | number; label: string; icon?: React.ReactNode; count?: number }
/** Detail requests fired at once while building the union — keeps a user with
* many lists from opening the modal with a burst of parallel requests. */
const DETAIL_BATCH = 4
/** Union of every list's places, in list order, without duplicates. */
async function loadSavedPlaces(ids: number[]): Promise<CollectionPlace[]> {
const merged: CollectionPlace[] = []
const seen = new Set<number>()
for (let i = 0; i < ids.length; i += DETAIL_BATCH) {
const batch = await Promise.all(ids.slice(i, i + DETAIL_BATCH).map(id => collectionsApi.get(id).catch(() => null)))
for (const d of batch) {
if (!d) continue
for (const p of d.places) {
if (seen.has(p.id)) continue
seen.add(p.id)
merged.push(p)
}
}
}
return merged
}
/** Compact click-away dropdown (Tailwind — this panel lives outside .trek-dash). */
function FilterDropdown({ current, options, onSelect, lead }: {
current: string | number
@@ -93,13 +115,8 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker
setLoading(true)
collectionsApi.list()
.then(async (res) => {
const detail = await Promise.all(res.collections.map(c => collectionsApi.get(c.id).catch(() => null)))
const merged = await loadSavedPlaces(res.collections.map(c => c.id))
if (cancelled) return
const merged: CollectionPlace[] = []
for (const d of detail) {
if (!d) continue
for (const p of d.places) merged.push(p)
}
setLists(res.collections.map(c => ({ id: c.id, name: c.name, color: c.color ?? null })))
setPlaces(merged)
})
@@ -233,7 +233,8 @@ describe('CollectionPlaceDetail', () => {
const input = document.querySelector('input[type="file"]') as HTMLInputElement;
fireEvent.change(input, { target: { files: [new File(['x'], 'cover.png', { type: 'image/png' })] } });
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Upload rejected', 'error', undefined));
// A rejection without a server payload falls back to the localized message.
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Could not upload image', 'error', undefined));
// The spinner is gone again, so the control accepts a retry.
await waitFor(() => expect(document.querySelector('.animate-spin')).toBeNull());
});
@@ -15,7 +15,7 @@ import { useToast } from '../shared/Toast'
import { Tooltip } from '../shared/Tooltip'
import PlaceRating from '../shared/StarRating'
import { normalizeImageFile } from '../../utils/convertHeic'
import { getApiErrorMessage } from '../../types'
import { getApiErrorMessage } from '../../utils/apiError'
function linkHost(url: string): string {
try { return new URL(url).hostname.replace(/^www\./, '') } catch { return url }
@@ -322,7 +322,8 @@ describe('ListEditorModal', () => {
const { props } = setup()
fireEvent.change(screen.getByPlaceholderText('e.g. Tokyo 2025'), { target: { value: 'Oslo' } })
fireEvent.click(screen.getByRole('button', { name: 'Create' }))
await waitFor(() => expect(addToast).toHaveBeenCalledWith('boom', 'error', undefined))
// A plain failure has no server-provided message, so the translated fallback shows.
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Error', 'error', undefined))
expect(props.onClose).not.toHaveBeenCalled()
// The save button releases again so the user can retry.
await waitFor(() => expect(screen.getByRole('button', { name: 'Create' })).not.toBeDisabled())
@@ -4,7 +4,7 @@ import Modal from '../shared/Modal'
import { useCollectionStore } from '../../store/collectionStore'
import { useToast } from '../shared/Toast'
import { tripsApi } from '../../api/client'
import { getApiErrorMessage } from '../../types'
import { getApiErrorMessage } from '../../utils/apiError'
import { normalizeLinkUrl } from '../../pages/collections/collectionsModel'
import type { TranslationFn } from '../../types'
import type { Collection, CollectionLink } from '@trek/shared'
@@ -219,7 +219,7 @@ describe('SaveToCollectionModal', () => {
expect(useSaveToCollectionStore.getState().version).toBe(0);
});
it('FE-COMP-SAVETOCOL-013: a second click on the busy row is ignored while the save runs', async () => {
it('FE-COMP-SAVETOCOL-013: every row locks while a save runs', async () => {
let resolve!: (v: CollectionSaveResult) => void;
const save = vi.spyOn(collectionsApi, 'savePlace').mockReturnValue(new Promise(r => { resolve = r; }));
openFor();
@@ -228,7 +228,9 @@ describe('SaveToCollectionModal', () => {
const wishlist = await screen.findByRole('button', { name: /Wishlist/ });
fireEvent.click(wishlist);
expect(wishlist).toBeDisabled();
fireEvent.click(screen.getByRole('button', { name: /Favorites/ }));
const favorites = screen.getByRole('button', { name: /Favorites/ });
expect(favorites).toBeDisabled();
fireEvent.click(favorites);
expect(save).toHaveBeenCalledTimes(1);
resolve({});
@@ -169,7 +169,7 @@ export default function SaveToCollectionModal(): React.ReactElement | null {
key={list.id}
type="button"
onClick={() => handleToggle(list)}
disabled={busy}
disabled={busyId != null}
className={`flex items-center gap-3 px-3 py-2.5 rounded-xl border text-left transition-colors disabled:opacity-60 ${saved ? 'border-accent bg-accent-subtle' : 'border-edge bg-surface-card hover:bg-surface-hover'}`}
>
<span className="w-2.5 h-2.5 rounded-full shrink-0" style={{ background: list.color || 'var(--accent)' }} />
@@ -98,7 +98,7 @@ describe('SaveTripPlacesToListModal', () => {
vi.spyOn(collectionsApi, 'list').mockResolvedValue(listResponse(many));
renderModal();
const search = await screen.findByPlaceholderText('Search trips');
const search = await screen.findByPlaceholderText('Search lists');
fireEvent.change(search, { target: { value: 'list 4' } });
expect(screen.getByText('List 4')).toBeInTheDocument();
expect(screen.queryByText('List 5')).not.toBeInTheDocument();
@@ -110,7 +110,7 @@ describe('SaveTripPlacesToListModal', () => {
it('FE-COMP-SAVETRIPPL-007: five lists or fewer need no search box', async () => {
renderModal();
await screen.findByText('Favorites');
expect(screen.queryByPlaceholderText('Search trips')).not.toBeInTheDocument();
expect(screen.queryByPlaceholderText('Search lists')).not.toBeInTheDocument();
});
it('FE-COMP-SAVETRIPPL-008: picking a list copies every selected place, reports it and closes', async () => {
@@ -77,7 +77,7 @@ export default function SaveTripPlacesToListModal({ isOpen, tripId, placeIds, on
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.copyToTripSearch')}
placeholder={t('collections.searchLists')}
className="w-full pl-8 pr-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
/>
</div>
@@ -114,6 +114,7 @@ export default function ShareCollectionModal({
}
const handleSetRole = async (userId: number, role: CollectionRole) => {
if (settingRoleId != null) return
setSettingRoleId(userId)
try {
await setMemberRole(collectionId, userId, role)