mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
test: hold the branch's tests to the type and lint gates
The booking save helper answers a Reservation the way the dialogs' onSave does, and takes the payload the sheets read back. The export tests resolve their routing promise without non-null assertions, the autocomplete test reads its own console spy, and the Photon tally test asks its five dropped questions together instead of awaiting in a loop. The Photon address line falls back to empty when a feature has none. The repair test now expects the dashboard to place the cleared beach in Germany through the borders, as the Atlas map does since #2875. The client lint baseline follows the counts this branch lowered.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"src": {
|
||||
"@typescript-eslint/no-non-null-assertion": 382,
|
||||
"@typescript-eslint/no-misused-promises": 848,
|
||||
"@typescript-eslint/no-misused-promises": 847,
|
||||
"no-console": 88,
|
||||
"complexity": 219,
|
||||
"@typescript-eslint/no-explicit-any": 146,
|
||||
@@ -35,11 +35,11 @@
|
||||
},
|
||||
"tests": {
|
||||
"@typescript-eslint/no-explicit-any": 490,
|
||||
"@typescript-eslint/no-non-null-assertion": 1917,
|
||||
"@typescript-eslint/no-non-null-assertion": 1914,
|
||||
"@typescript-eslint/no-misused-promises": 22,
|
||||
"@typescript-eslint/no-unused-vars": 51,
|
||||
"@typescript-eslint/no-floating-promises": 33,
|
||||
"trek/no-window-globals": 331,
|
||||
"trek/no-window-globals": 325,
|
||||
"trek/no-swallowed-catch": 14,
|
||||
"react-hooks/globals": 5,
|
||||
"react-hooks/refs": 22,
|
||||
|
||||
@@ -111,14 +111,14 @@ describe('TripExportModal', () => {
|
||||
|
||||
it('FE-PLANNER-EXPORTMODAL-016: while one export works, every row waits', async () => {
|
||||
const user = userEvent.setup()
|
||||
let finish: (() => void) | null = null
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
|
||||
let finish = () => {}
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
|
||||
render(<TripExportModal {...makeProps()} />)
|
||||
await user.click(screen.getByText('dayplan.pdf'))
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /dayplan\.gpxAll/ })).toBeDisabled())
|
||||
expect(screen.getByRole('button', { name: /mobileTrip\.icsDownload/ })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: /dayplan\.pdf/ })).toBeDisabled()
|
||||
finish!()
|
||||
finish()
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /dayplan\.gpxAll/ })).toBeEnabled())
|
||||
})
|
||||
|
||||
@@ -203,7 +203,7 @@ describe('TripExportModal', () => {
|
||||
const onClose = vi.fn()
|
||||
render(<TripExportModal {...makeProps({ onClose })} />)
|
||||
await user.click(screen.getByText('mobileTrip.icsSubscribe'))
|
||||
const exportBackdrop = screen.getByRole('dialog', { name: 'dayplan.export' }).parentElement!
|
||||
const exportBackdrop = screen.getByRole('dialog', { name: 'dayplan.export' }).parentElement as HTMLElement
|
||||
const subscribe = screen.getByTestId('ics-subscribe-modal')
|
||||
// Both hang off the body; the later one paints above the earlier.
|
||||
expect(exportBackdrop.compareDocumentPosition(subscribe) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
@@ -294,8 +294,8 @@ describe('TripExportModal', () => {
|
||||
|
||||
it('FE-PLANNER-EXPORTMODAL-019: while the PDF routes the row counts the legs, and the rest can be left out (#2876)', async () => {
|
||||
const user = userEvent.setup()
|
||||
let finish: (() => void) | null = null
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
|
||||
let finish = () => {}
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
|
||||
const roadtripViasByDay = { 10: [] }
|
||||
const tourStageStops = new Map()
|
||||
render(<TripExportModal {...makeProps({ roadtripViasByDay, tourStageStops })} />)
|
||||
@@ -309,13 +309,13 @@ describe('TripExportModal', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'dayplan.pdfSkipRouting' }))
|
||||
expect(route?.signal?.aborted).toBe(true)
|
||||
expect(screen.queryByRole('button', { name: 'dayplan.pdfSkipRouting' })).toBeNull()
|
||||
await act(async () => finish!())
|
||||
await act(async () => finish())
|
||||
})
|
||||
|
||||
it('FE-PLANNER-EXPORTMODAL-020: closing the dialog while the PDF routes gives the export up', async () => {
|
||||
const user = userEvent.setup()
|
||||
let finish: (() => void) | null = null
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
|
||||
let finish = () => {}
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
|
||||
const props = makeProps()
|
||||
const { rerender } = render(<TripExportModal {...props} />)
|
||||
await user.click(screen.getByText('dayplan.pdf'))
|
||||
@@ -325,7 +325,7 @@ describe('TripExportModal', () => {
|
||||
rerender(<TripExportModal {...props} isOpen={false} />)
|
||||
expect(route?.signal?.aborted).toBe(true)
|
||||
expect(signal?.aborted).toBe(true)
|
||||
await act(async () => finish!())
|
||||
await act(async () => finish())
|
||||
expect(props.onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,14 +12,20 @@ import type { Reservation } from '../../src/types';
|
||||
*/
|
||||
export function plannerSave(record: { id: number }) {
|
||||
const failures: Error[] = [];
|
||||
const save = vi.fn(async (_data: unknown, steps?: BookingSaveSteps) => {
|
||||
try {
|
||||
await steps?.afterSave?.(record as Reservation);
|
||||
return record;
|
||||
} catch (err) {
|
||||
failures.push(err as Error);
|
||||
return undefined;
|
||||
const stored = record as Reservation;
|
||||
const save = vi.fn(
|
||||
async (
|
||||
_data: Record<string, unknown> & { title: string },
|
||||
steps?: BookingSaveSteps
|
||||
): Promise<Reservation | undefined> => {
|
||||
try {
|
||||
await steps?.afterSave?.(stored);
|
||||
return stored;
|
||||
} catch (err) {
|
||||
failures.push(err as Error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
return { save, failures };
|
||||
}
|
||||
|
||||
@@ -223,8 +223,8 @@ describe('MExportSheet', () => {
|
||||
})
|
||||
|
||||
it('FE-MOB-EXPSH-014: while the PDF routes the row counts the legs, and the rest can be left out (#2876)', async () => {
|
||||
let finish: (() => void) | null = null
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = res }))
|
||||
let finish = () => {}
|
||||
vi.mocked(downloadTripPDF).mockImplementationOnce(() => new Promise<void>(res => { finish = () => res() }))
|
||||
renderSheet()
|
||||
fireEvent.click(screen.getByText('PDF'))
|
||||
await waitFor(() => expect(downloadTripPDF).toHaveBeenCalledTimes(1))
|
||||
@@ -234,7 +234,7 @@ describe('MExportSheet', () => {
|
||||
expect(screen.getByText('Calculating routes: 3 of 10')).toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Export without the remaining routes' }))
|
||||
expect(route?.signal?.aborted).toBe(true)
|
||||
await act(async () => finish!())
|
||||
await act(async () => finish())
|
||||
})
|
||||
|
||||
it('FE-MOB-EXPSH-015: hiding the sheet while the PDF routes gives the export up', async () => {
|
||||
|
||||
@@ -148,7 +148,7 @@ export function asSuggestion(feature: PhotonFeature): Suggestion | null {
|
||||
// place is. Cut by the name rather than at its first comma, which a name can
|
||||
// hold; a house without a name is titled by its number, as Nominatim does.
|
||||
const name = feature.properties.name?.trim();
|
||||
const line = hit.display_name;
|
||||
const line = hit.display_name ?? '';
|
||||
const [head = '', ...rest] = line.split(', ');
|
||||
const mainText = name || head;
|
||||
if (!mainText) return null;
|
||||
|
||||
@@ -498,11 +498,12 @@ describe('MapsService.autocompletePlaces', () => {
|
||||
|
||||
it('MAPS-AUTO-023: an index failure keeps what Photon found instead of throwing it away', async () => {
|
||||
mockSearch.mockRejectedValue(new Error('places api down'));
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
const { svc } = withPhoton([photonRow()]);
|
||||
|
||||
const result = await svc.autocompletePlaces(1, INPUT);
|
||||
|
||||
expect(console.warn).toHaveBeenCalledWith('TREK Places autocomplete failed, falling back:', 'places api down');
|
||||
expect(warn).toHaveBeenCalledWith('TREK Places autocomplete failed, falling back:', 'places api down');
|
||||
expect(result.suggestions).toEqual([photonRow()]);
|
||||
});
|
||||
|
||||
|
||||
@@ -247,12 +247,13 @@ describe('the suggestions asked per keystroke', () => {
|
||||
init.signal?.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')));
|
||||
}),
|
||||
);
|
||||
for (let i = 0; i < 5; i += 1) {
|
||||
const dropped = new AbortController();
|
||||
const asked = photon.suggest('Rost', { signal: dropped.signal });
|
||||
dropped.abort();
|
||||
expect(await asked).toBeNull();
|
||||
}
|
||||
const dropped = Array.from({ length: 5 }, () => {
|
||||
const controller = new AbortController();
|
||||
const asked = photon.suggest('Rost', { signal: controller.signal });
|
||||
controller.abort();
|
||||
return asked;
|
||||
});
|
||||
expect(await Promise.all(dropped)).toEqual([null, null, null, null, null]);
|
||||
fetchMock.mockImplementation(async () => photonAnswer([gateFeature()]));
|
||||
expect(await photon.suggest('Rostock')).toHaveLength(1);
|
||||
});
|
||||
|
||||
@@ -177,8 +177,8 @@ describe('the one time repair of place_regions rows cached before #2527', () =>
|
||||
expect(await atlas.repairStaleRegionCache()).toEqual({ replaced: 0, dropped: 2 });
|
||||
expect(await cachedRow(beach)).toBeUndefined();
|
||||
expect(await cachedRow(cleared)).toBeUndefined();
|
||||
// The dashboard, which reads only the cache, no longer counts France.
|
||||
expect((await atlas.getTravelStats(userId)).countries).toEqual([]);
|
||||
// The dashboard no longer counts France; the borders place the beach in Germany.
|
||||
expect((await atlas.getTravelStats(userId)).countries).toEqual(['DE']);
|
||||
});
|
||||
|
||||
it('does not write over a place that is edited while the pass runs', async () => {
|
||||
|
||||
Reference in New Issue
Block a user