Files
SubMiner/src/core/services/app-lifecycle.test.ts
sudacode ffe5c6e1c6 feat(stats): add stats server, API endpoints, config, and Anki integration
- Hono HTTP server with 20+ REST endpoints for stats data
- Stats overlay BrowserWindow with toggle keybinding
- IPC channel definitions and preload bridge
- Stats config section (toggleKey, serverPort, autoStartServer, autoOpenBrowser)
- Config resolver for stats section
- AnkiConnect proxy endpoints (guiBrowse, notesInfo)
- Note ID passthrough in card mining callback chain
- Stats CLI command with autoOpenBrowser respect
2026-03-17 20:04:40 -07:00

117 lines
3.0 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { CliArgs } from '../../cli/args';
import { AppLifecycleServiceDeps, startAppLifecycle } from './app-lifecycle';
function makeArgs(overrides: Partial<CliArgs> = {}): CliArgs {
return {
background: false,
start: false,
launchMpv: false,
launchMpvTargets: [],
stop: false,
toggle: false,
toggleVisibleOverlay: false,
settings: false,
setup: false,
show: false,
hide: false,
showVisibleOverlay: false,
hideVisibleOverlay: false,
copySubtitle: false,
copySubtitleMultiple: false,
mineSentence: false,
mineSentenceMultiple: false,
updateLastCardFromClipboard: false,
refreshKnownWords: false,
toggleSecondarySub: false,
triggerFieldGrouping: false,
triggerSubsync: false,
markAudioCard: false,
openRuntimeOptions: false,
anilistStatus: false,
anilistLogout: false,
anilistSetup: false,
anilistRetryQueue: false,
dictionary: false,
stats: false,
jellyfin: false,
jellyfinLogin: false,
jellyfinLogout: false,
jellyfinLibraries: false,
jellyfinItems: false,
jellyfinSubtitles: false,
jellyfinSubtitleUrlsOnly: false,
jellyfinPlay: false,
jellyfinRemoteAnnounce: false,
jellyfinPreviewAuth: false,
texthooker: false,
help: false,
autoStartOverlay: false,
generateConfig: false,
backupOverwrite: false,
debug: false,
...overrides,
};
}
function createDeps(overrides: Partial<AppLifecycleServiceDeps> = {}) {
const calls: string[] = [];
let lockCalls = 0;
const deps: AppLifecycleServiceDeps = {
shouldStartApp: () => false,
parseArgs: () => makeArgs(),
requestSingleInstanceLock: () => {
lockCalls += 1;
return true;
},
quitApp: () => {
calls.push('quitApp');
},
onSecondInstance: () => {},
handleCliCommand: () => {},
printHelp: () => {
calls.push('printHelp');
},
logNoRunningInstance: () => {
calls.push('logNoRunningInstance');
},
whenReady: () => {},
onWindowAllClosed: () => {},
onWillQuit: () => {},
onActivate: () => {},
isDarwinPlatform: () => false,
onReady: async () => {},
onWillQuitCleanup: () => {},
shouldRestoreWindowsOnActivate: () => false,
restoreWindowsOnActivate: () => {},
shouldQuitOnWindowAllClosed: () => true,
...overrides,
};
return { deps, calls, getLockCalls: () => lockCalls };
}
test('startAppLifecycle handles --help without acquiring single-instance lock', () => {
const { deps, calls, getLockCalls } = createDeps({
shouldStartApp: () => false,
});
startAppLifecycle(makeArgs({ help: true }), deps);
assert.equal(getLockCalls(), 0);
assert.deepEqual(calls, ['printHelp', 'quitApp']);
});
test('startAppLifecycle still acquires lock for startup commands', () => {
const { deps, getLockCalls } = createDeps({
shouldStartApp: () => true,
whenReady: () => {},
});
startAppLifecycle(makeArgs({ start: true }), deps);
assert.equal(getLockCalls(), 1);
});