| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { |
| 3 | MAX_SELECTED_PAGES, |
| 4 | MAX_STYLE_SWITCH_PAGES, |
| 5 | normalizeAnimationPreferences, |
| 6 | normalizeSelectPageIds |
| 7 | } from '../../../src/shared/generation' |
| 8 | |
| 9 | describe('normalizeSelectPageIds', () => { |
| 10 | it('normalizes explicit main-session selected page ids', () => { |
| 11 | expect( |
| 12 | normalizeSelectPageIds([' page-13 ', 'page-14', 'page-13', '../bad', 'page_15']) |
| 13 | ).toEqual(['page-13', 'page-14', 'page_15']) |
| 14 | }) |
| 15 | |
| 16 | it('rejects more than the shared selected-page limit without truncating', () => { |
| 17 | const pageIds = Array.from( |
| 18 | { length: MAX_SELECTED_PAGES + 1 }, |
| 19 | (_, index) => `page-${index + 1}` |
| 20 | ) |
| 21 | |
| 22 | expect(() => normalizeSelectPageIds(pageIds)).toThrow(`一次最多选择 ${MAX_SELECTED_PAGES} 页`) |
| 23 | }) |
| 24 | |
| 25 | it('allows exactly the shared selected-page limit', () => { |
| 26 | const pageIds = Array.from({ length: MAX_SELECTED_PAGES }, (_, index) => `page-${index + 1}`) |
| 27 | |
| 28 | expect(normalizeSelectPageIds(pageIds)).toHaveLength(MAX_SELECTED_PAGES) |
| 29 | }) |
| 30 | |
| 31 | it('supports the larger explicit limit used by style-switch retries', () => { |
| 32 | const pageIds = Array.from( |
| 33 | { length: MAX_STYLE_SWITCH_PAGES }, |
| 34 | (_, index) => `page-${index + 1}` |
| 35 | ) |
| 36 | |
| 37 | expect(normalizeSelectPageIds(pageIds, MAX_STYLE_SWITCH_PAGES)).toHaveLength( |
| 38 | MAX_STYLE_SWITCH_PAGES |
| 39 | ) |
| 40 | }) |
| 41 | }) |
| 42 | |
| 43 | describe('normalizeAnimationPreferences', () => { |
| 44 | it('deduplicates known animation preference ids and limits to three', () => { |
| 45 | expect( |
| 46 | normalizeAnimationPreferences({ |
| 47 | ids: ['fade-up', 'wipe', 'fade-up', 'pulse-soft', 'zoom-in'] |
| 48 | }) |
| 49 | ).toEqual({ ids: ['fade-up', 'wipe', 'pulse-soft'] }) |
| 50 | }) |
| 51 | |
| 52 | it('drops unknown ids and returns null when no known preference remains', () => { |
| 53 | expect( |
| 54 | normalizeAnimationPreferences({ |
| 55 | ids: ['unknown', 'default', 'fade-up'] |
| 56 | }) |
| 57 | ).toEqual({ ids: ['fade-up'] }) |
| 58 | expect(normalizeAnimationPreferences({ ids: ['unknown'] })).toBeNull() |
| 59 | }) |
| 60 | |
| 61 | it('accepts raw id arrays for UI state normalization', () => { |
| 62 | expect(normalizeAnimationPreferences(['slide-right', 'zoom-in', 'pulse'])).toEqual({ |
| 63 | ids: ['slide-right', 'zoom-in', 'pulse'] |
| 64 | }) |
| 65 | }) |
| 66 | }) |
| 67 |