PPPAIMT-Crest/backend/test/consentHtml.test.js

49 lines
2.0 KiB
JavaScript

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 <Asha> Rao',
consentDate: '2026-10-27',
answers: allAccepted,
});
expect(html).toContain('PARTICIPANT INFORMATION SHEET (PIS)');
expect(html).toContain('INFORMED CONSENT FORM (ICF)');
expect(html).toContain('<span class="filled">Dr &lt;Asha&gt; Rao</span>');
expect(html).toContain('<span class="filled">27/10/2026</span>');
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', () => {
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('counter(page) " of " counter(pages)');
expect(html).not.toContain('**Document:**');
});
it('starts page two at the same section as the original document', () => {
const body = pisBodyHtml();
expect(body).toContain('<h3 class="page-break">What will you be expected to do?</h3>');
expect(body).toContain('<strong>Survey Title:</strong>');
expect(body).not.toContain('Background');
});
});