2026-12-03 11:19:22 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
import { createTranscriptTimeline } from './transcript-timeline'
|
|
|
|
|
|
|
|
|
|
describe('createTranscriptTimeline', () => {
|
|
|
|
|
it('uses inclusive starts and exclusive ends for adjacent segments and gaps', () => {
|
|
|
|
|
const at = createTranscriptTimeline([
|
|
|
|
|
{ id: 'later', startMs: 2000, endMs: 2500, text: '' },
|
|
|
|
|
{ id: 'first', startMs: 300, endMs: 1000, text: '' },
|
|
|
|
|
{ id: 'second', startMs: 1000, endMs: 1700, text: '' },
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(at(0)).toBeUndefined()
|
|
|
|
|
expect(at(300)).toBe('first')
|
|
|
|
|
expect(at(1000)).toBe('second')
|
|
|
|
|
expect(at(1700)).toBeUndefined()
|
|
|
|
|
expect(at(2000)).toBe('later')
|
|
|
|
|
expect(at(2500)).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('finds the latest active start when a shorter segment overlaps a longer one', () => {
|
|
|
|
|
const at = createTranscriptTimeline([
|
|
|
|
|
{ id: 'long', startMs: 0, endMs: 4000, text: '' },
|
|
|
|
|
{ id: 'short', startMs: 1050, endMs: 1120, text: '' },
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(at(1049.5)).toBe('long')
|
|
|
|
|
expect(at(1050)).toBe('short')
|
|
|
|
|
expect(at(1120)).toBe('long')
|
|
|
|
|
expect(at(4000)).toBeUndefined()
|
|
|
|
|
expect(createTranscriptTimeline([])(0)).toBeUndefined()
|
|
|
|
|
})
|
2026-12-03 15:25:28 +08:00
|
|
|
|
|
|
|
|
it('uses the new segment at an exact millisecond after converting the seek through seconds', () => {
|
|
|
|
|
const at = createTranscriptTimeline([
|
|
|
|
|
{ id: 'before', startMs: 1800, endMs: 2010, text: '' },
|
|
|
|
|
{ id: 'after', startMs: 2010, endMs: 2200, text: '' },
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(at(2009.999)).toBe('before')
|
|
|
|
|
expect(at((2010 / 1000) * 1000)).toBe('after')
|
|
|
|
|
})
|
2026-12-03 11:19:22 +08:00
|
|
|
})
|