'use strict'; const { parseRenderOptions, pruneOldImageSubtitleCaches } = require('../server/image-subtitles'); describe('image subtitle option parsing', () => { test('accepts streamIndex 0 as a valid value', () => { const parsed = parseRenderOptions({ filePath: '/tmp/example.mkv', streamIndex: 0, timeSeconds: 24.5, canvasWidth: 1920, canvasHeight: 1080, }); expect(parsed.streamIndex).toBe(0); expect(parsed.timeSeconds).toBeCloseTo(24.5, 3); expect(parsed.isValid).toBe(true); }); test('rejects non-numeric streamIndex values', () => { const parsed = parseRenderOptions({ filePath: '/tmp/example.mkv', streamIndex: '', timeSeconds: 24.5, }); expect(parsed.isValid).toBe(false); }); test('prune calculates drop threshold as double event duration past event end', () => { // When a subtitle event is 20-30s (10s duration), it should be dropped after 40s // This tests the logic: dropThreshold = endTime + (endTime - startTime) const startTime = 20; const endTime = 30; const duration = endTime - startTime; const dropThreshold = endTime + duration; expect(dropThreshold).toBe(40); // Before threshold: subtitle should be kept const beforeThreshold = 39.999; expect(beforeThreshold < dropThreshold).toBe(true); // At or after threshold: subtitle should be dropped const atThreshold = 40; expect(atThreshold >= dropThreshold).toBe(true); // Later: definitely should be dropped const afterThreshold = 50; expect(afterThreshold >= dropThreshold).toBe(true); }); });