BlueGit

timfa filemanager

Files

filemanager / tests / image-subtitles.test.js

image-subtitles.test.js

image-subtitles.test.js 1.6 KiB Download Raw
1'use strict';
2
3const { parseRenderOptions, pruneOldImageSubtitleCaches } = require('../server/image-subtitles');
4
5describe('image subtitle option parsing', () =>
6{
7 test('accepts streamIndex 0 as a valid value', () =>
8 {
9 const parsed = parseRenderOptions({
10 filePath: '/tmp/example.mkv',
11 streamIndex: 0,
12 timeSeconds: 24.5,
13 canvasWidth: 1920,
14 canvasHeight: 1080,
15 });
16
17 expect(parsed.streamIndex).toBe(0);
18 expect(parsed.timeSeconds).toBeCloseTo(24.5, 3);
19 expect(parsed.isValid).toBe(true);
20 });
21
22 test('rejects non-numeric streamIndex values', () =>
23 {
24 const parsed = parseRenderOptions({
25 filePath: '/tmp/example.mkv',
26 streamIndex: '',
27 timeSeconds: 24.5,
28 });
29
30 expect(parsed.isValid).toBe(false);
31 });
32
33 test('prune calculates drop threshold as double event duration past event end', () =>
34 {
35 // When a subtitle event is 20-30s (10s duration), it should be dropped after 40s
36 // This tests the logic: dropThreshold = endTime + (endTime - startTime)
37 const startTime = 20;
38 const endTime = 30;
39 const duration = endTime - startTime;
40 const dropThreshold = endTime + duration;
41
42 expect(dropThreshold).toBe(40);
43
44 // Before threshold: subtitle should be kept
45 const beforeThreshold = 39.999;
46 expect(beforeThreshold < dropThreshold).toBe(true);
47
48 // At or after threshold: subtitle should be dropped
49 const atThreshold = 40;
50 expect(atThreshold >= dropThreshold).toBe(true);
51
52 // Later: definitely should be dropped
53 const afterThreshold = 50;
54 expect(afterThreshold >= dropThreshold).toBe(true);
55 });
56});