Add lawyer's summary print: records with lawyer-level fields only (Fixes #30)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -109,3 +109,52 @@ test('countByLevel splits lawyer-level from plain secrets, and countSecrets tota
|
||||
assert.deepEqual(countByLevel(doc), { lawyer: 2, secret: 2 });
|
||||
assert.equal(countSecrets(doc), 4);
|
||||
});
|
||||
|
||||
import { summaryGroups, summaryCounts } from '../src/print.js';
|
||||
|
||||
const rec = (title, fields) => ({ id: title, title, status: 'ok', updated: '2022-04-14', fields });
|
||||
const lw = (label, value) => ({ label, value, secret: true, lawyer: true });
|
||||
const summaryDoc = () => ({ sections: [
|
||||
{ id: 'a', title: 'Intro', kind: 'text', body: 'hello' },
|
||||
{ id: 'b', title: 'Bank', kind: 'records', records: [
|
||||
rec('Chase', [{ label: 'Name', value: 'Chase' }, lw('Account', '123'), { label: 'Balance', value: '$9', secret: true }]),
|
||||
rec('Only secret', [{ label: 'PIN', value: '1', secret: true }]),
|
||||
rec('Only normal', [{ label: 'Phone', value: '555' }]),
|
||||
rec('Empty acct', [lw('Account', '')]),
|
||||
rec('Card scan', [{ label: 'Card', kind: 'image', value: '', secret: true, lawyer: true }]),
|
||||
{ id: 'q', kind: 'sequence', title: 'Walk', updated: '2022-04-14', frames: [{ image: '', text: 'x', layout: 'none', secret: true, lawyer: true }] },
|
||||
] },
|
||||
{ id: 'c', title: 'Nothing here', kind: 'records', records: [rec('Plain', [{ label: 'x', value: 'y' }])] },
|
||||
{ id: 'd', title: 'Steps', kind: 'steps', items: [] },
|
||||
] });
|
||||
|
||||
test('summaryGroups keeps only records with lawyer-level text fields, and only those fields', () => {
|
||||
const out = summaryGroups(summaryDoc());
|
||||
assert.equal(out.length, 1);
|
||||
assert.equal(out[0].section, 'Bank');
|
||||
assert.deepEqual(out[0].groups[0].records.map((r) => r.title), ['Chase', 'Empty acct']);
|
||||
assert.deepEqual(out[0].groups[0].records[0].fields.map((f) => f.label), ['Account']); // no Name, no Balance
|
||||
assert.equal(out[0].groups[0].title, null);
|
||||
});
|
||||
|
||||
test('summaryGroups follows sub-tabs and drops tabs with no match', () => {
|
||||
const doc = summaryDoc();
|
||||
const s = doc.sections[1];
|
||||
s.subsections = [{ id: 't1', title: 'Savings' }, { id: 't2', title: 'Unused' }];
|
||||
s.records[0].subsection = 't1';
|
||||
const out = summaryGroups(doc);
|
||||
assert.deepEqual(out[0].groups.map((g) => g.title), ['General', 'Savings']);
|
||||
assert.deepEqual(out[0].groups[1].records.map((r) => r.title), ['Chase']);
|
||||
});
|
||||
|
||||
test('summaryCounts counts records and values; an empty document lists nothing', () => {
|
||||
assert.deepEqual(summaryCounts(summaryDoc()), { records: 2, values: 2 });
|
||||
assert.deepEqual(summaryGroups({ sections: [] }), []);
|
||||
assert.deepEqual(summaryCounts({ sections: [] }), { records: 0, values: 0 });
|
||||
});
|
||||
|
||||
test("the summary mode shows lawyer values like the lawyer's view and keeps plain secrets hidden", () => {
|
||||
assert.equal(normalizeMode('summary'), 'summary');
|
||||
assert.equal(isHidden(acct.num, 'summary'), false);
|
||||
assert.equal(isHidden(acct.amt, 'summary'), true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user