Files
Clipboard/test/tray-menu.test.js
2026-09-12 13:59:12 +08:00

52 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const assert = require('node:assert');
const { buildTrayMenuTemplate } = require('../tray-menu.js');
let passed = 0;
function check(name, fn) {
try { fn(); console.log(' ok -', name); passed++; }
catch (e) { console.error(' FAIL -', name, '\n', e.message); process.exitCode = 1; }
}
const noop = () => {};
const actions = { onShow: noop, onSettings: noop, onQuit: noop };
check('菜单只有 3 个可点项', () => {
const items = buildTrayMenuTemplate(actions).filter((i) => i.type !== 'separator');
assert.strictEqual(items.length, 3,
`期望 3 项,实际 ${items.length}${items.map((i) => i.label).join(' / ')}`);
});
check('菜单项顺序与文案固定', () => {
const t = buildTrayMenuTemplate(actions);
assert.deepStrictEqual(
t.map((i) => (i.type === 'separator' ? '---' : i.label)),
['显示历史', '设置...', '---', '退出']
);
});
check('不再包含主题 / 强调色 / 快捷键 / 关于', () => {
const labels = buildTrayMenuTemplate(actions).map((i) => i.label || '').join('|');
for (const gone of ['主题', '强调色', '快捷键', '关于']) {
assert.ok(!labels.includes(gone), `${gone}」应已迁移到设置窗口`);
}
});
check('没有任何子菜单', () => {
const t = buildTrayMenuTemplate(actions);
assert.ok(t.every((i) => !i.submenu), '托盘不应再有子菜单');
});
check('click 回调按顺序接线到传入的动作', () => {
const calls = [];
const t = buildTrayMenuTemplate({
onShow: () => calls.push('show'),
onSettings: () => calls.push('settings'),
onQuit: () => calls.push('quit'),
});
for (const i of t) if (typeof i.click === 'function') i.click();
assert.deepStrictEqual(calls, ['show', 'settings', 'quit']);
});
console.log(`\n${passed} checks passed`);