import { describe, expect, it } from 'vitest'; import { consentHtml, pisBodyHtml } from '../src/pdf/consentHtml.js'; import { CONSENT_STATEMENTS } from '../src/schemas/consent.js'; const allAccepted = Object.fromEntries(CONSENT_STATEMENTS.map((statement) => [statement.id, true])); describe('consent PDF html', () => { it('fills in the participant and ticks every accepted statement', () => { const html = consentHtml({ participantName: 'Dr Rao', consentDate: '2026-10-27', answers: allAccepted, }); expect(html).toContain('PARTICIPANT INFORMATION SHEET (PIS)'); expect(html).toContain('INFORMED CONSENT FORM (ICF)'); expect(html).toContain('Dr <Asha> Rao'); expect(html).toContain('27/10/2026'); expect(html.match(/class="box checked"/g)).toHaveLength(CONSENT_STATEMENTS.length); for (const statement of CONSENT_STATEMENTS) { expect(html).toContain(statement.label); } }); it('leaves out the signature line and the web form button', () => { const html = consentHtml({ participantName: 'A', consentDate: '2026-10-27', answers: {} }); expect(html).not.toMatch(/Electronic Signature/i); expect(html).not.toMatch(/SUBMIT YOUR CONSENT/i); expect(html).not.toContain('class="box checked"'); }); it('uses the PIS document line as the page header and the original footer', () => { const html = consentHtml({ participantName: 'A', consentDate: '2026-10-27', answers: {} }); expect(html).toContain('@top-left { content: "PIS and ICF V01" "\\A" "Date: 14/10/2026"'); expect(html).toContain('size: letter;'); expect(html).toContain('Page of '); expect(html).toContain('.footer .page::after { content: counter(page); font-weight: 700; }'); expect(html).not.toContain('**Document:**'); }); it('embeds the bundled Carlito font', () => { const html = consentHtml({ participantName: 'A', consentDate: '2026-10-27', answers: {} }); expect(html).toMatch(/src: url\("file:\/\/[^"]+\/fonts\/Carlito-Regular\.ttf"\)/); expect(html).toMatch(/src: url\("file:\/\/[^"]+\/fonts\/Carlito-Bold\.ttf"\)/); }); it('lays out page one like the original', () => { const html = consentHtml({ participantName: 'A', consentDate: '2026-10-27', answers: {} }); const body = pisBodyHtml(); expect(html).toContain( '

ONLINE

\n

PARTICIPANT INFORMATION SHEET (PIS)

', ); expect(body).toContain('

Survey Title: Physicians’ Perceptions'); expect(body).toContain('maintenance therapy.
Therefore, we are conducting'); expect(body).not.toContain('Background'); }); it('starts page two at the same section and puts the investigators side by side', () => { const body = pisBodyHtml(); expect(body).toContain('

What will you be expected to do?

'); expect(body).toContain('

Contact Details:

'); expect(body).toMatch( /
Principal Investigator<\/strong>
Name: Dr\. Sundeep Salvi.*<\/td>
Co-investigator<\/strong>/, ); }); });