summary.test.ts
1,311 bytes
| 1 | import { describe, expect, it } from 'vitest' |
|---|---|
| 2 | import type { Segment } from '../../shared/types' |
| 3 | import { RECENT_SEGMENT_WINDOW, splitTranscriptWindow } from './summary' |
| 4 | |
| 5 | function makeSegments(count: number): Segment[] { |
| 6 | return Array.from({ length: count }, (_, i) => ({ |
| 7 | id: `S${i + 1}`, |
| 8 | ts: new Date().toISOString(), |
| 9 | speaker: i % 2 === 0 ? 'user' : 'interviewer', |
| 10 | text: `segment ${i + 1}`, |
| 11 | })) |
| 12 | } |
| 13 | |
| 14 | describe('splitTranscriptWindow', () => { |
| 15 | it('keeps everything in the recent window when at or under the limit', () => { |
| 16 | const segments = makeSegments(RECENT_SEGMENT_WINDOW) |
| 17 | const { recentSegments, olderSegments } = splitTranscriptWindow(segments) |
| 18 | expect(recentSegments).toEqual(segments) |
| 19 | expect(olderSegments).toEqual([]) |
| 20 | }) |
| 21 | |
| 22 | it('keeps only the last 40 segments and puts the rest in olderSegments', () => { |
| 23 | const segments = makeSegments(RECENT_SEGMENT_WINDOW + 5) |
| 24 | const { recentSegments, olderSegments } = splitTranscriptWindow(segments) |
| 25 | expect(recentSegments).toHaveLength(RECENT_SEGMENT_WINDOW) |
| 26 | expect(recentSegments[0].id).toBe('S6') |
| 27 | expect(recentSegments[recentSegments.length - 1].id).toBe(`S${segments.length}`) |
| 28 | expect(olderSegments).toHaveLength(5) |
| 29 | expect(olderSegments.map((s) => s.id)).toEqual(['S1', 'S2', 'S3', 'S4', 'S5']) |
| 30 | }) |
| 31 | }) |
| 32 | |