mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +00:00
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:
@@ -899,4 +899,16 @@ describe('downloadTripPDF defaults', () => {
|
||||
expect(endSection).toContain('reservations.span.end: Overnight Bus')
|
||||
expect(endSection).not.toContain('22:00')
|
||||
})
|
||||
|
||||
it('FE-W5PDF-027: an export without a locale still renders, with lang="en"', async () => {
|
||||
await downloadTripPDF({ ...minimalArgs, locale: '' })
|
||||
|
||||
expect(srcdoc()).toContain('<html lang="en">')
|
||||
})
|
||||
|
||||
it('FE-W5PDF-028: an export without assignments renders the days as empty', async () => {
|
||||
await downloadTripPDF({ ...minimalArgs, assignments: undefined as any })
|
||||
|
||||
expect(srcdoc()).toContain('Day 1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -146,7 +146,9 @@ interface downloadTripPDFProps {
|
||||
locale: string
|
||||
}
|
||||
|
||||
export async function downloadTripPDF({ trip, days, places, assignments, categories, dayNotes, reservations = [], t: _t, locale: _locale }: downloadTripPDFProps) {
|
||||
// `assignments` is normalised here once — every read below (and fetchPlacePhotos)
|
||||
// relies on it being an object.
|
||||
export async function downloadTripPDF({ trip, days, places, assignments = {}, categories, dayNotes, reservations = [], t: _t, locale: _locale }: downloadTripPDFProps) {
|
||||
await ensureRenderer()
|
||||
const loc = _locale || undefined
|
||||
const tr = _t || (k => k)
|
||||
@@ -165,7 +167,7 @@ export async function downloadTripPDF({ trip, days, places, assignments, categor
|
||||
const photoMap = await fetchPlacePhotos(assignments, places)
|
||||
|
||||
const totalAssigned = new Set(
|
||||
Object.values(assignments || {}).flatMap(a => a.map(x => x.place?.id)).filter(Boolean)
|
||||
Object.values(assignments).flatMap(a => a.map(x => x.place?.id)).filter(Boolean)
|
||||
).size
|
||||
// The PDF is a trip-scoped, shareable document, so totals stay in the trip's
|
||||
// own currency. Rates are resolved ONCE before any HTML is built so the cover
|
||||
@@ -173,7 +175,7 @@ export async function downloadTripPDF({ trip, days, places, assignments, categor
|
||||
// entirely (offline export keeps working), and a failed fetch degrades to
|
||||
// per-currency breakdowns instead of mislabeled sums (#1561).
|
||||
const tripCur = (trip?.currency || 'EUR').toUpperCase()
|
||||
const allCostEntries: MoneyEntry[] = Object.values(assignments || {})
|
||||
const allCostEntries: MoneyEntry[] = Object.values(assignments)
|
||||
.flatMap(a => a)
|
||||
.map(a => ({ amount: Number(a.place?.price) || 0, currency: a.place?.currency || tripCur }))
|
||||
const needsFx = allCostEntries.some(e => e.amount > 0 && e.currency.toUpperCase() !== tripCur)
|
||||
@@ -433,7 +435,7 @@ export async function downloadTripPDF({ trip, days, places, assignments, categor
|
||||
</div>`
|
||||
|
||||
const html = `<!DOCTYPE html>
|
||||
<html lang="${loc.split('-')[0]}">
|
||||
<html lang="${(loc || 'en').split('-')[0]}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<base href="${window.location.origin}/">
|
||||
|
||||
Reference in New Issue
Block a user