| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { |
| 3 | createDefaultDesignContract, |
| 4 | normalizeDesignContract, |
| 5 | resolveDesignContract |
| 6 | } from '../../../src/main/presentation/design-contract' |
| 7 | |
| 8 | describe('presentation design contract', () => { |
| 9 | it('uses presentation defaults for invalid persisted values', () => { |
| 10 | expect(normalizeDesignContract('not-json')).toEqual(createDefaultDesignContract()) |
| 11 | }) |
| 12 | |
| 13 | it('normalizes persisted text and uses defaults for an incomplete palette', () => { |
| 14 | const fallback = createDefaultDesignContract() |
| 15 | |
| 16 | expect( |
| 17 | normalizeDesignContract({ |
| 18 | theme: ' editorial\n deck ', |
| 19 | palette: [' #111 ', '', ' #222 '], |
| 20 | titleFont: ' Source Han Sans ' |
| 21 | }) |
| 22 | ).toEqual({ |
| 23 | ...fallback, |
| 24 | theme: 'editorial deck', |
| 25 | titleFont: 'Source Han Sans' |
| 26 | }) |
| 27 | }) |
| 28 | |
| 29 | it('marks missing or non-canonical persisted contracts for persistence', () => { |
| 30 | const defaultContract = createDefaultDesignContract() |
| 31 | |
| 32 | expect(resolveDesignContract(null)).toEqual({ |
| 33 | contract: defaultContract, |
| 34 | shouldPersist: true |
| 35 | }) |
| 36 | expect(resolveDesignContract(JSON.stringify(defaultContract))).toEqual({ |
| 37 | contract: defaultContract, |
| 38 | shouldPersist: false |
| 39 | }) |
| 40 | expect(resolveDesignContract({ ...defaultContract, titleFont: ' Inter ' })).toEqual({ |
| 41 | contract: defaultContract, |
| 42 | shouldPersist: true |
| 43 | }) |
| 44 | }) |
| 45 | }) |
| 46 |