Files
SubMiner/src/settings/key-input.test.ts
T
sudacode 6ba91780c1 feat(config): unify mpv plugin options under main config and add CSS/Ani
- Replace subminer.conf plugin config with mpv.* fields in config.jsonc
- Add socketPath, backend, autoStartSubMiner, pauseUntilOverlayReady, aniskipEnabled/buttonKey, subminerBinaryPath to mpv config
- Add subtitleSidebar.css field; migrate legacy sidebar appearance fields
- Add paintOrder and WebkitTextStroke to subtitle style options
- Update default subtitle/sidebar fontFamily to CJK-first stack
- Fix overlay visible state surviving mpv y-r restart
- Fix live config saves applying subtitle CSS immediately to open overlays
- Migrate legacy primary/secondary subtitle appearance into subtitleStyle.css on load
- Switch AniSkip button key setting to click-to-learn key capture
2026-05-18 03:07:39 -07:00

120 lines
3.2 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import type { Keybinding } from '../types/runtime';
import {
buildMpvKeybindingConfigValue,
createMpvKeybindingRows,
keyboardEventToConfigKey,
} from './key-input';
test('keyboardEventToConfigKey formats Electron accelerators from learned input', () => {
assert.equal(
keyboardEventToConfigKey(
{ code: 'KeyS', key: 's', ctrlKey: true, altKey: false, shiftKey: true, metaKey: false },
'accelerator',
),
'CommandOrControl+Shift+S',
);
assert.equal(
keyboardEventToConfigKey(
{ code: 'Slash', key: '/', ctrlKey: false, altKey: true, shiftKey: false, metaKey: false },
'accelerator',
),
'Alt+Slash',
);
});
test('keyboardEventToConfigKey formats DOM code bindings from learned input', () => {
assert.equal(
keyboardEventToConfigKey(
{ code: 'KeyJ', key: 'j', ctrlKey: true, altKey: false, shiftKey: true, metaKey: false },
'dom-code',
),
'Ctrl+Shift+KeyJ',
);
assert.equal(
keyboardEventToConfigKey(
{
code: 'Backquote',
key: '`',
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
},
'dom-code',
),
'Backquote',
);
});
test('keyboardEventToConfigKey formats bare key-code fields without modifiers', () => {
assert.equal(
keyboardEventToConfigKey(
{ code: 'KeyW', key: 'w', ctrlKey: true, altKey: true, shiftKey: false, metaKey: false },
'code',
),
'KeyW',
);
});
test('keyboardEventToConfigKey formats mpv key bindings from learned input', () => {
assert.equal(
keyboardEventToConfigKey(
{ code: 'Tab', key: 'Tab', ctrlKey: false, altKey: false, shiftKey: false, metaKey: false },
'mpv-key',
),
'TAB',
);
assert.equal(
keyboardEventToConfigKey(
{ code: 'KeyK', key: 'K', ctrlKey: true, altKey: false, shiftKey: true, metaKey: false },
'mpv-key',
),
'Ctrl+Shift+K',
);
});
test('MPV keybinding rows save default key moves as a disable plus replacement', () => {
const defaults: Keybinding[] = [{ key: 'Space', command: ['cycle', 'pause'] }];
const rows = createMpvKeybindingRows(defaults, []);
rows[0]!.key = 'KeyP';
assert.deepEqual(buildMpvKeybindingConfigValue(defaults, rows), [
{ key: 'Space', command: null },
{ key: 'KeyP', command: ['cycle', 'pause'] },
]);
});
test('MPV keybinding rows reopen moved default bindings as their default row', () => {
const defaults: Keybinding[] = [{ key: 'Space', command: ['cycle', 'pause'] }];
assert.deepEqual(
createMpvKeybindingRows(defaults, [
{ key: 'Space', command: null },
{ key: 'KeyP', command: ['cycle', 'pause'] },
]),
[
{
defaultKey: 'Space',
key: 'KeyP',
command: ['cycle', 'pause'],
commandText: '["cycle","pause"]',
isDefault: true,
},
],
);
});
test('MPV keybinding rows omit unchanged default bindings from config value', () => {
const defaults: Keybinding[] = [
{ key: 'Space', command: ['cycle', 'pause'] },
{ key: 'KeyF', command: ['cycle', 'fullscreen'] },
];
assert.deepEqual(
buildMpvKeybindingConfigValue(defaults, createMpvKeybindingRows(defaults, [])),
[],
);
});