`npm run format:check` (a CI gate) had drifted red across 44 files — pre-existing files plus recently-added ones committed without formatting. Ran `prettier --write .`; no logic changes. Also regenerates documentation.json (compodoc reflects the reformatted component sources). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { Brief, LetterBlock } from './brief';
|
|
import { diffBlocks, changedBlocks } from './brief-diff';
|
|
|
|
function block(id: string, text: string): LetterBlock {
|
|
return {
|
|
type: 'freeText',
|
|
blockId: id,
|
|
content: { paragraphs: [{ nodes: [{ type: 'text', text }] }] },
|
|
};
|
|
}
|
|
|
|
function brief(blocks: LetterBlock[]): Brief {
|
|
return {
|
|
briefId: 'b1',
|
|
beroep: 'arts',
|
|
templateId: 't1',
|
|
placeholders: [],
|
|
sections: [{ sectionKey: 'kern', title: 'Kern', required: true, locked: false, blocks }],
|
|
status: { tag: 'draft' },
|
|
drafterId: 'u1',
|
|
};
|
|
}
|
|
|
|
describe('diffBlocks', () => {
|
|
it('marks added, removed, changed and unchanged by blockId', () => {
|
|
const before = brief([block('local-1', 'a'), block('local-2', 'b'), block('local-3', 'c')]);
|
|
const after = brief([block('local-1', 'a'), block('local-2', 'B!'), block('local-4', 'd')]);
|
|
const diffs = diffBlocks(before, after);
|
|
const byId = new Map(diffs.map((d) => [d.blockId, d.kind]));
|
|
expect(byId.get('local-1')).toBe('unchanged');
|
|
expect(byId.get('local-2')).toBe('changed');
|
|
expect(byId.get('local-3')).toBe('removed'); // gone from after
|
|
expect(byId.get('local-4')).toBe('added'); // new in after
|
|
});
|
|
|
|
it('changedBlocks drops unchanged and keeps added/removed/changed', () => {
|
|
const before = brief([block('local-1', 'a'), block('local-2', 'b')]);
|
|
const after = brief([block('local-1', 'a'), block('local-2', 'B'), block('local-3', 'c')]);
|
|
const map = changedBlocks(diffBlocks(before, after));
|
|
expect(map.has('local-1')).toBe(false);
|
|
expect(map.get('local-2')).toBe('changed');
|
|
expect(map.get('local-3')).toBe('added');
|
|
});
|
|
});
|