mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-26 04:19:27 -07:00
feat(core): add Electron runtime, services, and app composition
This commit is contained in:
57
src/main/runtime/global-shortcuts-runtime-handlers.test.ts
Normal file
57
src/main/runtime/global-shortcuts-runtime-handlers.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import type { ConfiguredShortcuts } from '../../core/utils/shortcut-config';
|
||||
import { createGlobalShortcutsRuntimeHandlers } from './global-shortcuts-runtime-handlers';
|
||||
|
||||
function createShortcuts(): ConfiguredShortcuts {
|
||||
return {
|
||||
toggleVisibleOverlayGlobal: 'CommandOrControl+Shift+O',
|
||||
toggleInvisibleOverlayGlobal: 'CommandOrControl+Shift+I',
|
||||
copySubtitle: 's',
|
||||
copySubtitleMultiple: 'CommandOrControl+s',
|
||||
updateLastCardFromClipboard: 'c',
|
||||
triggerFieldGrouping: null,
|
||||
triggerSubsync: null,
|
||||
mineSentence: 'q',
|
||||
mineSentenceMultiple: 'w',
|
||||
multiCopyTimeoutMs: 5000,
|
||||
toggleSecondarySub: null,
|
||||
markAudioCard: null,
|
||||
openRuntimeOptions: null,
|
||||
openJimaku: null,
|
||||
};
|
||||
}
|
||||
|
||||
test('global shortcuts runtime handlers compose get/register/refresh flow', () => {
|
||||
const calls: string[] = [];
|
||||
const shortcuts = createShortcuts();
|
||||
const runtime = createGlobalShortcutsRuntimeHandlers({
|
||||
getConfiguredShortcutsMainDeps: {
|
||||
getResolvedConfig: () => ({}) as never,
|
||||
defaultConfig: {} as never,
|
||||
resolveConfiguredShortcuts: () => shortcuts,
|
||||
},
|
||||
buildRegisterGlobalShortcutsMainDeps: (getConfiguredShortcuts) => ({
|
||||
getConfiguredShortcuts,
|
||||
registerGlobalShortcutsCore: (options) => {
|
||||
calls.push('register');
|
||||
assert.equal(options.shortcuts, shortcuts);
|
||||
},
|
||||
toggleVisibleOverlay: () => calls.push('toggle-visible'),
|
||||
toggleInvisibleOverlay: () => calls.push('toggle-invisible'),
|
||||
openYomitanSettings: () => calls.push('open-yomitan'),
|
||||
isDev: false,
|
||||
getMainWindow: () => null,
|
||||
}),
|
||||
buildRefreshGlobalAndOverlayShortcutsMainDeps: (registerGlobalShortcuts) => ({
|
||||
unregisterAllGlobalShortcuts: () => calls.push('unregister'),
|
||||
registerGlobalShortcuts: () => registerGlobalShortcuts(),
|
||||
syncOverlayShortcuts: () => calls.push('sync-overlay'),
|
||||
}),
|
||||
});
|
||||
|
||||
assert.equal(runtime.getConfiguredShortcuts(), shortcuts);
|
||||
runtime.registerGlobalShortcuts();
|
||||
runtime.refreshGlobalAndOverlayShortcuts();
|
||||
assert.deepEqual(calls, ['register', 'unregister', 'register', 'sync-overlay']);
|
||||
});
|
||||
Reference in New Issue
Block a user