72 lines
3.2 KiB
JavaScript
72 lines
3.2 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 <Asha> 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 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 <span class="page"></span> of <span class="pages"></span>');
|
||
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(
|
||
'<p class="doc-title">ONLINE</p>\n<p class="doc-title">PARTICIPANT INFORMATION SHEET (PIS)</p>',
|
||
);
|
||
expect(body).toContain('<p class="survey-title">Survey Title: Physicians’ Perceptions');
|
||
expect(body).toContain('maintenance therapy.<br />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('<h3 class="page-break">What will you be expected to do?</h3>');
|
||
expect(body).toContain('<h3 class="contact-heading">Contact Details:</h3>');
|
||
expect(body).toMatch(
|
||
/<table class="contacts"><tr><td><strong>Principal Investigator<\/strong><br \/>Name: Dr\. Sundeep Salvi.*<\/td><td><strong>Co-investigator<\/strong>/,
|
||
);
|
||
});
|
||
});
|