mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-01 06:22:44 -08:00
refactor: extract main runtime dependency builders
This commit is contained in:
64
src/main/runtime/startup-config-main-deps.test.ts
Normal file
64
src/main/runtime/startup-config-main-deps.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createBuildCriticalConfigErrorMainDepsHandler,
|
||||
createBuildReloadConfigMainDepsHandler,
|
||||
} from './startup-config-main-deps';
|
||||
|
||||
test('reload config main deps builder maps callbacks and fail handlers', async () => {
|
||||
const calls: string[] = [];
|
||||
const deps = createBuildReloadConfigMainDepsHandler({
|
||||
reloadConfigStrict: () => ({ ok: true }),
|
||||
logInfo: (message) => calls.push(`info:${message}`),
|
||||
logWarning: (message) => calls.push(`warn:${message}`),
|
||||
showDesktopNotification: (title, options) => calls.push(`notify:${title}:${options.body}`),
|
||||
startConfigHotReload: () => calls.push('start-hot-reload'),
|
||||
refreshAnilistClientSecretState: async (options) => {
|
||||
calls.push(`refresh:${options.force}`);
|
||||
return true;
|
||||
},
|
||||
failHandlers: {
|
||||
logError: (details) => calls.push(`error:${details}`),
|
||||
showErrorBox: (title, details) => calls.push(`error-box:${title}:${details}`),
|
||||
quit: () => calls.push('quit'),
|
||||
},
|
||||
})();
|
||||
|
||||
assert.deepEqual(deps.reloadConfigStrict(), { ok: true });
|
||||
deps.logInfo('x');
|
||||
deps.logWarning('y');
|
||||
deps.showDesktopNotification('SubMiner', { body: 'warn' });
|
||||
deps.startConfigHotReload();
|
||||
await deps.refreshAnilistClientSecretState({ force: true });
|
||||
deps.failHandlers.logError('bad');
|
||||
deps.failHandlers.showErrorBox('Oops', 'Details');
|
||||
deps.failHandlers.quit();
|
||||
assert.deepEqual(calls, [
|
||||
'info:x',
|
||||
'warn:y',
|
||||
'notify:SubMiner:warn',
|
||||
'start-hot-reload',
|
||||
'refresh:true',
|
||||
'error:bad',
|
||||
'error-box:Oops:Details',
|
||||
'quit',
|
||||
]);
|
||||
});
|
||||
|
||||
test('critical config main deps builder maps config path and fail handlers', () => {
|
||||
const calls: string[] = [];
|
||||
const deps = createBuildCriticalConfigErrorMainDepsHandler({
|
||||
getConfigPath: () => '/tmp/config.jsonc',
|
||||
failHandlers: {
|
||||
logError: (details) => calls.push(`error:${details}`),
|
||||
showErrorBox: (title, details) => calls.push(`error-box:${title}:${details}`),
|
||||
quit: () => calls.push('quit'),
|
||||
},
|
||||
})();
|
||||
|
||||
assert.equal(deps.getConfigPath(), '/tmp/config.jsonc');
|
||||
deps.failHandlers.logError('bad');
|
||||
deps.failHandlers.showErrorBox('Oops', 'Details');
|
||||
deps.failHandlers.quit();
|
||||
assert.deepEqual(calls, ['error:bad', 'error-box:Oops:Details', 'quit']);
|
||||
});
|
||||
Reference in New Issue
Block a user