BlueGit

timfa filemanager

Files

filemanager / tests / image-subtitles.test.js

image-subtitles.test.js

image-subtitles.test.js 2.4 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('caps subtitle render canvas within 1280x720 bounds', () =>
34 {
35 const parsed = parseRenderOptions({
36 filePath: '/tmp/example.mkv',
37 streamIndex: 0,
38 timeSeconds: 5,
39 canvasWidth: 4096,
40 canvasHeight: 2160,
41 });
42
43 expect(parsed.canvasWidth).toBe(1280);
44 expect(parsed.canvasHeight).toBe(675);
45 expect(parsed.canvasWidth).toBeLessThanOrEqual(1280);
46 expect(parsed.canvasHeight).toBeLessThanOrEqual(720);
47 });
48
49 test('preserves requested aspect ratio when canvas is capped', () =>
50 {
51 const parsed = parseRenderOptions({
52 filePath: '/tmp/example.mkv',
53 streamIndex: 0,
54 timeSeconds: 5,
55 canvasWidth: 3840,
56 canvasHeight: 1600,
57 });
58
59 expect(parsed.canvasWidth).toBe(1280);
60 expect(parsed.canvasHeight).toBe(533);
61 });
62
63 test('prune calculates drop threshold as end plus duration plus 5 seconds', () =>
64 {
65 // When a subtitle event is 20-30s (10s duration), it should be dropped after 45s
66 // This tests the logic: dropThreshold = endTime + (endTime - startTime) + 5
67 const startTime = 20;
68 const endTime = 30;
69 const duration = endTime - startTime;
70 const dropThreshold = endTime + duration + 5;
71
72 expect(dropThreshold).toBe(45);
73
74 // Before threshold: subtitle should be kept
75 const beforeThreshold = 44.999;
76 expect(beforeThreshold < dropThreshold).toBe(true);
77
78 // At or after threshold: subtitle should be dropped
79 const atThreshold = 45;
80 expect(atThreshold >= dropThreshold).toBe(true);
81
82 // Later: definitely should be dropped
83 const afterThreshold = 55;
84 expect(afterThreshold >= dropThreshold).toBe(true);
85 });
86});