| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { |
| 4 | extractImpliedPageCount, |
| 5 | normalizeGeneratedPlan |
| 6 | } from '../../../src/main/io/document-plan-normalizer' |
| 7 | |
| 8 | describe('document parse plan page count normalization', () => { |
| 9 | it('uses English per-page entries when the model collapses pageCount to one', () => { |
| 10 | const result = normalizeGeneratedPlan( |
| 11 | JSON.stringify({ |
| 12 | topic: 'Product Launch Readiness Review', |
| 13 | pageCount: 1, |
| 14 | briefText: [ |
| 15 | 'Presentation goal: Review launch readiness.', |
| 16 | 'Recommended outline:', |
| 17 | '1. Context', |
| 18 | '2. Market signal', |
| 19 | '3. Product readiness', |
| 20 | '4. GTM risks', |
| 21 | '5. Timeline', |
| 22 | '6. Decision points', |
| 23 | 'Per-page points:', |
| 24 | 'Page 1: Context', |
| 25 | 'Page 2: Market signal', |
| 26 | 'Page 3: Product readiness', |
| 27 | 'Page 4: GTM risks', |
| 28 | 'Page 5: Timeline', |
| 29 | 'Page 6: Decision points' |
| 30 | ].join('\n') |
| 31 | }), |
| 32 | { topic: '', pageCount: null, briefText: '' } |
| 33 | ) |
| 34 | |
| 35 | expect(result.pageCount).toBe(6) |
| 36 | }) |
| 37 | |
| 38 | it('keeps an explicit user page count even when the outline has more entries', () => { |
| 39 | const result = normalizeGeneratedPlan( |
| 40 | JSON.stringify({ |
| 41 | topic: 'Product Launch Readiness Review', |
| 42 | pageCount: 1, |
| 43 | briefText: ['Recommended outline:', '1. Context', '2. Market signal'].join('\n') |
| 44 | }), |
| 45 | { topic: '', pageCount: 1, briefText: '' } |
| 46 | ) |
| 47 | |
| 48 | expect(result.pageCount).toBe(1) |
| 49 | }) |
| 50 | |
| 51 | it('counts English Page N labels in per-page sections', () => { |
| 52 | expect( |
| 53 | extractImpliedPageCount(['Per-page points:', 'Page 1: A', 'Page 2: B', 'Page 3: C'].join('\n')) |
| 54 | ).toBe(3) |
| 55 | }) |
| 56 | }) |
| 57 |