Files
TREK/client/src/hooks/useExportDeepLink.test.tsx
T
Maurice f8e51cb83d fix(pdf): hand the trip PDF to Safari from the iOS Home Screen app
An iPhone or iPad running TREK from the Home Screen ignores print(), in
the page and in an iframe alike, so "Save as PDF" in the preview did
nothing there. Mobile Safari prints the same preview fine.

In the installed iOS app the preview now shows "Open in Safari" in
place of the dead button, with a line saying why. The link opens the
trip with ?export=pdf, and both shells open their export dialog or
sheet for it, so the PDF is one tap away once Safari is up. The
parameter is dropped once read and survives the login redirect.
Everywhere else the preview prints as before.

The preview overlay moves out of TripPDF.tsx into pdfPreview.ts, which
TripPDF had no room left for under lint:size, and its backdrop and
stacking now use the --overlay and --z-modal tokens.
2026-11-03 09:14:55 +01:00

50 lines
1.7 KiB
TypeScript

/**
* FE-EXPORTLINK-001 to FE-EXPORTLINK-003: `?export=pdf` opens the trip's export
* once, the way Safari lands after the iOS Home Screen app handed the PDF over.
*/
import { renderHook } from '@testing-library/react';
import type { ReactNode } from 'react';
import { MemoryRouter, useLocation } from 'react-router';
import { describe, expect, it, vi } from 'vitest';
import { useExportDeepLink } from './useExportDeepLink';
function setup(entry: string) {
const openExport = vi.fn();
const wrapper = ({ children }: { children: ReactNode }) => (
<MemoryRouter initialEntries={[entry]}>{children}</MemoryRouter>
);
const { result, rerender } = renderHook(
() => {
useExportDeepLink(openExport);
return useLocation();
},
{ wrapper }
);
return { openExport, result, rerender };
}
describe('useExportDeepLink', () => {
it('FE-EXPORTLINK-001: opens the export and drops the parameter, keeping the others', () => {
const { openExport, result, rerender } = setup('/trips/7?tab=plan&export=pdf');
expect(openExport).toHaveBeenCalledTimes(1);
expect(result.current.pathname).toBe('/trips/7');
expect(result.current.search).toBe('?tab=plan');
rerender();
expect(openExport).toHaveBeenCalledTimes(1);
});
it('FE-EXPORTLINK-002: leaves the trip alone without the parameter', () => {
const { openExport, result } = setup('/trips/7?tab=plan');
expect(openExport).not.toHaveBeenCalled();
expect(result.current.search).toBe('?tab=plan');
});
it('FE-EXPORTLINK-003: ignores an export it does not know', () => {
const { openExport, result } = setup('/trips/7?export=gpx');
expect(openExport).not.toHaveBeenCalled();
expect(result.current.search).toBe('?export=gpx');
});
});