Files
SubMiner/src/window-trackers/hyprland-tracker.test.ts
sudacode e0f82d28f0 Improve startup dictionary sync UX and default playback keybindings
- Add default `f` fullscreen overlay binding and switch default AniSkip skip key to `Tab`
- Make character-dictionary auto-sync non-blocking at startup with tokenization gating for Yomitan mutations
- Add ordered startup OSD progress (checking/generating/updating/importing), refresh current subtitle on sync completion, and extend regression tests
2026-03-09 00:50:32 -07:00

109 lines
2.5 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
parseHyprctlClients,
selectHyprlandMpvWindow,
type HyprlandClient,
} from './hyprland-tracker';
function makeClient(overrides: Partial<HyprlandClient> = {}): HyprlandClient {
return {
address: '0x1',
class: 'mpv',
initialClass: 'mpv',
at: [0, 0],
size: [1280, 720],
mapped: true,
hidden: false,
...overrides,
};
}
test('selectHyprlandMpvWindow ignores hidden and unmapped mpv clients', () => {
const selected = selectHyprlandMpvWindow(
[
makeClient({
address: '0xhidden',
hidden: true,
}),
makeClient({
address: '0xunmapped',
mapped: false,
}),
makeClient({
address: '0xvisible',
at: [100, 200],
size: [1920, 1080],
}),
],
{
targetMpvSocketPath: null,
activeWindowAddress: null,
getWindowCommandLine: () => null,
},
);
assert.equal(selected?.address, '0xvisible');
});
test('selectHyprlandMpvWindow prefers active visible window among socket matches', () => {
const commandLines = new Map<string, string>([
['10', 'mpv --input-ipc-server=/tmp/subminer.sock first.mkv'],
['20', 'mpv --input-ipc-server=/tmp/subminer.sock second.mkv'],
]);
const selected = selectHyprlandMpvWindow(
[
makeClient({
address: '0xfirst',
pid: 10,
}),
makeClient({
address: '0xsecond',
pid: 20,
}),
],
{
targetMpvSocketPath: '/tmp/subminer.sock',
activeWindowAddress: '0xsecond',
getWindowCommandLine: (pid) => commandLines.get(String(pid)) ?? null,
},
);
assert.equal(selected?.address, '0xsecond');
});
test('selectHyprlandMpvWindow matches mpv by initialClass when class is blank', () => {
const selected = selectHyprlandMpvWindow(
[
makeClient({
address: '0xinitial',
class: '',
initialClass: 'mpv',
}),
],
{
targetMpvSocketPath: null,
activeWindowAddress: null,
getWindowCommandLine: () => null,
},
);
assert.equal(selected?.address, '0xinitial');
});
test('parseHyprctlClients tolerates non-json prefix output', () => {
const clients = parseHyprctlClients(`ok
[{"address":"0x1","class":"mpv","initialClass":"mpv","at":[1,2],"size":[3,4]}]`);
assert.deepEqual(clients, [
{
address: '0x1',
class: 'mpv',
initialClass: 'mpv',
at: [1, 2],
size: [3, 4],
},
]);
});