|
@@ -1,7 +1,11 @@
|
|
|
import { BrowserWindow, app, Menu, MenuItem, MenuItemConstructorOptions } from 'electron/main';
|
|
|
import { expect } from 'chai';
|
|
|
import { closeAllWindows } from './lib/window-helpers';
|
|
|
-const { roleList, execute } = require('../lib/browser/api/menu-item-roles');
|
|
|
+import { roleList, execute } from '../lib/browser/api/menu-item-roles';
|
|
|
+
|
|
|
+function keys<Key extends string, Value> (record: Record<Key, Value>) {
|
|
|
+ return Object.keys(record) as Key[];
|
|
|
+}
|
|
|
|
|
|
describe('MenuItems', () => {
|
|
|
describe('MenuItem instance properties', () => {
|
|
@@ -179,7 +183,7 @@ describe('MenuItems', () => {
|
|
|
const win = new BrowserWindow({ show: false, width: 200, height: 200 });
|
|
|
const item = new MenuItem({ role: 'asdfghjkl' as any });
|
|
|
|
|
|
- const canExecute = execute(item.role, win, win.webContents);
|
|
|
+ const canExecute = execute(item.role as any, win, win.webContents);
|
|
|
expect(canExecute).to.be.false('can execute');
|
|
|
});
|
|
|
|
|
@@ -187,7 +191,7 @@ describe('MenuItems', () => {
|
|
|
const win = new BrowserWindow({ show: false, width: 200, height: 200 });
|
|
|
const item = new MenuItem({ role: 'reload' });
|
|
|
|
|
|
- const canExecute = execute(item.role, win, win.webContents);
|
|
|
+ const canExecute = execute(item.role as any, win, win.webContents);
|
|
|
expect(canExecute).to.be.true('can execute');
|
|
|
});
|
|
|
|
|
@@ -195,7 +199,7 @@ describe('MenuItems', () => {
|
|
|
const win = new BrowserWindow({ show: false, width: 200, height: 200 });
|
|
|
const item = new MenuItem({ role: 'resetZoom' });
|
|
|
|
|
|
- const canExecute = execute(item.role, win, win.webContents);
|
|
|
+ const canExecute = execute(item.role as any, win, win.webContents);
|
|
|
expect(canExecute).to.be.true('can execute');
|
|
|
});
|
|
|
});
|
|
@@ -237,7 +241,7 @@ describe('MenuItems', () => {
|
|
|
|
|
|
describe('MenuItem role', () => {
|
|
|
it('returns undefined for items without default accelerator', () => {
|
|
|
- const list = Object.keys(roleList).filter(key => !roleList[key].accelerator);
|
|
|
+ const list = keys(roleList).filter(key => !roleList[key].accelerator);
|
|
|
|
|
|
for (const role of list) {
|
|
|
const item = new MenuItem({ role: role as any });
|
|
@@ -246,7 +250,7 @@ describe('MenuItems', () => {
|
|
|
});
|
|
|
|
|
|
it('returns the correct default label', () => {
|
|
|
- for (const role of Object.keys(roleList)) {
|
|
|
+ for (const role of keys(roleList)) {
|
|
|
const item = new MenuItem({ role: role as any });
|
|
|
const label: string = roleList[role].label;
|
|
|
expect(item.label).to.equal(label);
|
|
@@ -254,11 +258,11 @@ describe('MenuItems', () => {
|
|
|
});
|
|
|
|
|
|
it('returns the correct default accelerator', () => {
|
|
|
- const list = Object.keys(roleList).filter(key => roleList[key].accelerator);
|
|
|
+ const list = keys(roleList).filter(key => roleList[key].accelerator);
|
|
|
|
|
|
for (const role of list) {
|
|
|
const item = new MenuItem({ role: role as any });
|
|
|
- const accelerator: string = roleList[role].accelerator;
|
|
|
+ const accelerator = roleList[role].accelerator;
|
|
|
expect(item.getDefaultRoleAccelerator()).to.equal(accelerator);
|
|
|
}
|
|
|
});
|