mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-13 15:13:32 -07:00
feat(subtitle-sidebar): add sidebar config surface (#28)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
buildSubtitleSidebarSourceKey,
|
||||
getActiveExternalSubtitleSource,
|
||||
resolveSubtitleSourcePath,
|
||||
} from './subtitle-prefetch-source';
|
||||
@@ -17,6 +18,15 @@ test('getActiveExternalSubtitleSource returns the active external subtitle path'
|
||||
assert.equal(source, 'https://host/subs.ass');
|
||||
});
|
||||
|
||||
test('getActiveExternalSubtitleSource normalizes integer-like string track ids', () => {
|
||||
const source = getActiveExternalSubtitleSource(
|
||||
[{ type: 'sub', id: '2', external: true, 'external-filename': ' /tmp/subs.ass ' }],
|
||||
'2',
|
||||
);
|
||||
|
||||
assert.equal(source, '/tmp/subs.ass');
|
||||
});
|
||||
|
||||
test('getActiveExternalSubtitleSource returns null when the selected track is not external', () => {
|
||||
const source = getActiveExternalSubtitleSource(
|
||||
[{ type: 'sub', id: 2, external: false, 'external-filename': '/tmp/subs.ass' }],
|
||||
@@ -48,3 +58,38 @@ test('resolveSubtitleSourcePath returns the original source for malformed file U
|
||||
|
||||
assert.equal(resolveSubtitleSourcePath(source), source);
|
||||
});
|
||||
|
||||
test('buildSubtitleSidebarSourceKey uses a stable identifier for internal subtitle tracks', () => {
|
||||
const firstKey = buildSubtitleSidebarSourceKey('/media/episode01.mkv', {
|
||||
id: 3,
|
||||
'ff-index': 7,
|
||||
title: 'English',
|
||||
lang: 'eng',
|
||||
codec: 'ass',
|
||||
});
|
||||
const secondKey = buildSubtitleSidebarSourceKey('/media/episode01.mkv', {
|
||||
id: 3,
|
||||
'ff-index': 7,
|
||||
title: 'English',
|
||||
lang: 'eng',
|
||||
codec: 'ass',
|
||||
});
|
||||
|
||||
assert.equal(firstKey, secondKey);
|
||||
assert.equal(firstKey, 'internal:/media/episode01.mkv:track:3:ff:7');
|
||||
});
|
||||
|
||||
test('buildSubtitleSidebarSourceKey normalizes integer-like string track metadata', () => {
|
||||
const key = buildSubtitleSidebarSourceKey('/media/episode01.mkv', {
|
||||
id: '3',
|
||||
'ff-index': '7',
|
||||
});
|
||||
|
||||
assert.equal(key, 'internal:/media/episode01.mkv:track:3:ff:7');
|
||||
});
|
||||
|
||||
test('buildSubtitleSidebarSourceKey falls back to source path when no track metadata is available', () => {
|
||||
const key = buildSubtitleSidebarSourceKey('/media/episode01.mkv', null, '/tmp/subtitle.ass');
|
||||
|
||||
assert.equal(key, '/tmp/subtitle.ass');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user