Files
final-wishes/test/print.test.js
Eric Bell 70c384cdcb Add configurable running print header
The line printed on every page is now a header stored in the document as
header.fields: any number of Text / Last updated fields, each optionally
aligned left or right (at most one of each). Printed order is left,
unaligned, right. Edited from a Print header panel with live preview;
documents without a header use the previous title/last-update default.
The header is a repeating table header so it sits in flow and cannot
overlap body text, replacing the fixed-position footer.

Also add "Open your existing Final Wishes file" to the start screen so
data in an older encrypted file can be carried into a newer build.

Closes #9

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:23:31 -05:00

47 lines
2.4 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { displayValue, headerLayout, countSecrets } from '../src/print.js';
test('displayValue shows or withholds secrets, never confuses empty with hidden', () => {
assert.equal(displayValue({ label: 'a', value: 'x' }, false), 'x');
assert.equal(displayValue({ label: 'a', value: '' }, false), '(blank)');
assert.equal(displayValue({ label: 'p', value: 'pw', secret: true }, true), 'pw');
assert.equal(displayValue({ label: 'p', value: 'pw', secret: true }, false), '[withheld]');
assert.equal(displayValue({ label: 'p', value: '', secret: true }, true), '(not set)');
assert.equal(displayValue({ label: 'p', value: '', secret: true }, false), '(not set)');
});
test('masked output never contains the secret text', () => {
const out = displayValue({ label: 'p', value: 'hunter2', secret: true }, false);
assert.ok(!out.includes('hunter2'));
});
test('countSecrets counts only filled secret fields', () => {
const doc = { meta: { title: 'T', lastUpdated: '2022-04-14' }, sections: [
{ records: [{ fields: [{ label: 'a', value: 'x', secret: true }, { label: 'b', value: '', secret: true }, { label: 'c', value: 'y' }] }] },
{ items: [] } ] };
assert.equal(countSecrets(doc), 1);
});
const D = (header) => ({ meta: { title: 'My Title', lastUpdated: '2026-11-09' }, header, sections: [] });
test('header defaults: title left, last update right', () => {
assert.deepEqual(headerLayout(D(undefined)), { left: 'My Title', middle: [], right: 'Last update: 2026-11-09' });
});
test('header layout order is left, unaligned in list order, right, regardless of field order', () => {
const doc = D({ fields: [
{ kind: 'lastUpdated', text: 'Updated ', align: 'right' },
{ kind: 'text', text: 'Middle A' },
{ kind: 'text', text: 'Left one', align: 'left' },
{ kind: 'text', text: 'Middle B' },
] });
assert.deepEqual(headerLayout(doc), { left: 'Left one', middle: ['Middle A', 'Middle B'], right: 'Updated 2026-11-09' });
});
test('header with only unaligned fields, and empty text dropped', () => {
const doc = D({ fields: [{ kind: 'text', text: 'A' }, { kind: 'text', text: '' }, { kind: 'lastUpdated', text: '' }] });
assert.deepEqual(headerLayout(doc), { left: '', middle: ['A', '2026-11-09'], right: '' });
assert.deepEqual(headerLayout(D({ fields: [] })), { left: '', middle: [], right: '' });
});