electron/spec-main/api-global-shortcut-spec.ts

42 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
import { expect } from 'chai';
import { globalShortcut } from 'electron';
import { ifdescribe } from './spec-helpers';
2019-10-30 23:38:21 +00:00
ifdescribe(process.platform !== 'win32')('globalShortcut module', () => {
2016-08-09 22:10:51 +00:00
beforeEach(() => {
2020-03-20 20:28:31 +00:00
globalShortcut.unregisterAll();
});
2016-08-09 22:10:51 +00:00
it('can register and unregister single accelerators', () => {
2020-03-20 20:28:31 +00:00
const accelerator = 'CmdOrCtrl+A+B+C';
2016-08-09 22:10:51 +00:00
2020-03-20 20:28:31 +00:00
expect(globalShortcut.isRegistered(accelerator)).to.be.false('initially registered');
globalShortcut.register(accelerator, () => {});
expect(globalShortcut.isRegistered(accelerator)).to.be.true('registration worked');
globalShortcut.unregister(accelerator);
expect(globalShortcut.isRegistered(accelerator)).to.be.false('unregistration worked');
2016-08-09 22:10:51 +00:00
2020-03-20 20:28:31 +00:00
globalShortcut.register(accelerator, () => {});
expect(globalShortcut.isRegistered(accelerator)).to.be.true('reregistration worked');
globalShortcut.unregisterAll();
expect(globalShortcut.isRegistered(accelerator)).to.be.false('re-unregistration worked');
});
it('can register and unregister multiple accelerators', () => {
2020-03-20 20:28:31 +00:00
const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y'];
2020-03-20 20:28:31 +00:00
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first initially unregistered');
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second initially unregistered');
2020-03-20 20:28:31 +00:00
globalShortcut.registerAll(accelerators, () => {});
2020-03-20 20:28:31 +00:00
expect(globalShortcut.isRegistered(accelerators[0])).to.be.true('first registration worked');
expect(globalShortcut.isRegistered(accelerators[1])).to.be.true('second registration worked');
2020-03-20 20:28:31 +00:00
globalShortcut.unregisterAll();
2020-03-20 20:28:31 +00:00
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first unregistered');
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second unregistered');
});
});