Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

test(pdf): read the export's note cards without non-null assertions

Mauriceeaef3c014e05
diff --git a/client/src/components/PDF/TripPDF.test.ts b/client/src/components/PDF/TripPDF.test.ts
index c41c910b3..a59079732 100644
--- a/client/src/components/PDF/TripPDF.test.ts
+++ b/client/src/components/PDF/TripPDF.test.ts
@@ -474,15 +474,20 @@ describe('downloadTripPDF', () => {
await downloadTripPDF(md)
const html = getIframe()?.srcdoc ?? ''
const doc = new DOMParser().parseFromString(html, 'text/html')
- const intro = doc.querySelector('.day-intro')!
+ const card = (selector: string) => {
+ const found = doc.querySelector(selector)
+ if (!found) throw new Error(`${selector} is not in the export`)
+ return found
+ }
+ const intro = card('.day-intro')
expect(intro.querySelector('strong')?.textContent).toBe('Intro')
expect([...intro.querySelectorAll('li')].map(li => li.textContent)).toEqual(['museum', 'lunch'])
- const noteLine = doc.querySelector('.tl-note .note-time')!
+ const noteLine = card('.tl-note .note-time')
expect(noteLine.querySelector('em')?.textContent).toBe('Bring')
expect(noteLine.querySelector('hr')).not.toBeNull()
expect(noteLine.querySelector('script')).toBeNull()
expect(noteLine.textContent).toContain('<script>alert(1)</script>')
- const transportNote = doc.querySelector('.transport-note')!
+ const transportNote = card('.transport-note')
expect(transportNote.querySelector('strong')?.textContent).toBe('14A')
expect([...transportNote.querySelectorAll('ol li')].map(li => li.textContent)).toEqual(['check in', 'board'])
expect(html).not.toContain('**')