Add print layout
Print dialog with withhold/include secrets modes, cover page with contents, one section per page, non-splitting record blocks, TBD highlighting that survives black and white, tick boxes on steps and checklist items, and a per-page footer. Print content is built on demand and cleared after printing. Pure display helpers live in print.js with tests. Closes #5 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
25
test/print.test.js
Normal file
25
test/print.test.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { displayValue, footerText, 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('footerText and countSecrets', () => {
|
||||
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(footerText(doc), 'T — Last update: 2022-04-14');
|
||||
assert.equal(countSecrets(doc), 1);
|
||||
});
|
||||
Reference in New Issue
Block a user