Full document, spreadsheet, slideshow, and diagram tooling
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 67 lines 2.3 kB view raw
1import { describe, it, expect } from 'vitest'; 2 3/** 4 * Tests for the Diff Panel pure helpers. 5 * 6 * The `createDiffPanel` factory is DOM-heavy and exercised via e2e tests. 7 * Here we only cover the stringly helpers that decide how each version 8 * option is rendered — particularly the Forge-aware branch. 9 */ 10 11import { formatDiffOption, isForgeAuthored } from '../src/docs/diff-panel.js'; 12 13describe('formatDiffOption', () => { 14 const recent = new Date(Date.now() - 5 * 60 * 1000).toISOString(); 15 16 it('tags forge-authored versions with [forge] prefix', () => { 17 const out = formatDiffOption({ author: 'forge', label: 'Initial plan' }, recent); 18 expect(out.startsWith('[forge]')).toBe(true); 19 expect(out).toContain('Initial plan'); 20 expect(out).toContain('5 min ago'); 21 }); 22 23 it('prefers name over label when both present', () => { 24 const out = formatDiffOption({ author: 'forge', name: 'Milestone 1', label: 'raw' }, recent); 25 expect(out).toContain('Milestone 1'); 26 expect(out).not.toContain('raw'); 27 }); 28 29 it('falls back to "revision" when forge metadata has no label', () => { 30 const out = formatDiffOption({ author: 'forge' }, recent); 31 expect(out).toContain('[forge] revision'); 32 }); 33 34 it('uses legacy "time — author" format for human versions', () => { 35 const out = formatDiffOption({ author: 'scott' }, recent); 36 expect(out).toBe('5 min ago — scott'); 37 expect(out.startsWith('[forge]')).toBe(false); 38 }); 39 40 it('uses "name (time)" when a human version has a name', () => { 41 const out = formatDiffOption({ author: 'scott', name: 'Before rewrite' }, recent); 42 expect(out).toBe('Before rewrite (5 min ago)'); 43 }); 44 45 it('defaults author to Unknown when missing', () => { 46 const out = formatDiffOption({}, recent); 47 expect(out).toContain('Unknown'); 48 }); 49}); 50 51describe('isForgeAuthored', () => { 52 it('returns true for forge author', () => { 53 expect(isForgeAuthored({ author: 'forge' })).toBe(true); 54 }); 55 56 it('returns false for human authors', () => { 57 expect(isForgeAuthored({ author: 'scott' })).toBe(false); 58 }); 59 60 it('returns false when author is missing', () => { 61 expect(isForgeAuthored({})).toBe(false); 62 }); 63 64 it('returns false for non-string author values', () => { 65 expect(isForgeAuthored({ author: 42 as unknown })).toBe(false); 66 }); 67});