import { describe, it, expect } from 'vitest'; /** * Tests for the Diff Panel pure helpers. * * The `createDiffPanel` factory is DOM-heavy and exercised via e2e tests. * Here we only cover the stringly helpers that decide how each version * option is rendered — particularly the Forge-aware branch. */ import { formatDiffOption, isForgeAuthored } from '../src/docs/diff-panel.js'; describe('formatDiffOption', () => { const recent = new Date(Date.now() - 5 * 60 * 1000).toISOString(); it('tags forge-authored versions with [forge] prefix', () => { const out = formatDiffOption({ author: 'forge', label: 'Initial plan' }, recent); expect(out.startsWith('[forge]')).toBe(true); expect(out).toContain('Initial plan'); expect(out).toContain('5 min ago'); }); it('prefers name over label when both present', () => { const out = formatDiffOption({ author: 'forge', name: 'Milestone 1', label: 'raw' }, recent); expect(out).toContain('Milestone 1'); expect(out).not.toContain('raw'); }); it('falls back to "revision" when forge metadata has no label', () => { const out = formatDiffOption({ author: 'forge' }, recent); expect(out).toContain('[forge] revision'); }); it('uses legacy "time — author" format for human versions', () => { const out = formatDiffOption({ author: 'scott' }, recent); expect(out).toBe('5 min ago — scott'); expect(out.startsWith('[forge]')).toBe(false); }); it('uses "name (time)" when a human version has a name', () => { const out = formatDiffOption({ author: 'scott', name: 'Before rewrite' }, recent); expect(out).toBe('Before rewrite (5 min ago)'); }); it('defaults author to Unknown when missing', () => { const out = formatDiffOption({}, recent); expect(out).toContain('Unknown'); }); }); describe('isForgeAuthored', () => { it('returns true for forge author', () => { expect(isForgeAuthored({ author: 'forge' })).toBe(true); }); it('returns false for human authors', () => { expect(isForgeAuthored({ author: 'scott' })).toBe(false); }); it('returns false when author is missing', () => { expect(isForgeAuthored({})).toBe(false); }); it('returns false for non-string author values', () => { expect(isForgeAuthored({ author: 42 as unknown })).toBe(false); }); });