| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { |
| 3 | buildDefaultSessionLayoutLibrary, |
| 4 | formatLayoutMasterPrompt, |
| 5 | getLayoutMasterTemplates, |
| 6 | isValidSessionLayoutLibrary, |
| 7 | normalizeSessionLayoutLibrary, |
| 8 | resolveLayoutMasterTemplate |
| 9 | } from '../../../src/shared/layout-master' |
| 10 | import { LAYOUT_INTENTS } from '../../../src/shared/layout-intent' |
| 11 | |
| 12 | describe('layout master library', () => { |
| 13 | it('provides at least two compatible visual variants for every layout intent', () => { |
| 14 | const templates = getLayoutMasterTemplates() |
| 15 | |
| 16 | for (const intent of LAYOUT_INTENTS) { |
| 17 | expect( |
| 18 | templates.filter((template) => template.intent === intent).length |
| 19 | ).toBeGreaterThanOrEqual(2) |
| 20 | } |
| 21 | }) |
| 22 | |
| 23 | it('keeps only compatible mappings and falls back safely for unknown values', () => { |
| 24 | const library = normalizeSessionLayoutLibrary({ |
| 25 | version: 1, |
| 26 | mappings: { |
| 27 | cover: 'cover-split', |
| 28 | 'data-focus': 'comparison-versus', |
| 29 | comparison: 'missing-layout' |
| 30 | } |
| 31 | }) |
| 32 | |
| 33 | expect(library.mappings.cover).toBe('cover-split') |
| 34 | expect(library.mappings['data-focus']).toBe('data-metrics') |
| 35 | expect(library.mappings.comparison).toBe('comparison-versus') |
| 36 | expect(resolveLayoutMasterTemplate(library, 'cover')).toMatchObject({ id: 'cover-split' }) |
| 37 | }) |
| 38 | |
| 39 | it('requires a complete, versioned mapping before accepting an IPC save', () => { |
| 40 | const valid = buildDefaultSessionLayoutLibrary() |
| 41 | expect(isValidSessionLayoutLibrary(valid)).toBe(true) |
| 42 | expect( |
| 43 | isValidSessionLayoutLibrary({ |
| 44 | version: 1, |
| 45 | mappings: { ...valid.mappings, cover: 'image-spotlight' } |
| 46 | }) |
| 47 | ).toBe(false) |
| 48 | expect(isValidSessionLayoutLibrary({ version: 2, mappings: valid.mappings })).toBe(false) |
| 49 | }) |
| 50 | |
| 51 | it('states that a selected layout remains a flexible style-aware composition', () => { |
| 52 | const prompt = formatLayoutMasterPrompt(resolveLayoutMasterTemplate({}, 'data-focus')) |
| 53 | |
| 54 | expect(prompt).toContain('Selected layout master: Metric focus') |
| 55 | expect(prompt).toContain('flexible information architecture') |
| 56 | expect(prompt).toContain('current style contract authoritative') |
| 57 | }) |
| 58 | }) |
| 59 |