electron/spec/api-global-shortcut-spec.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-09-13 16:10:51 +00:00
const { globalShortcut } = require('electron').remote
2016-08-09 22:10:51 +00:00
const chai = require('chai')
const dirtyChai = require('dirty-chai')
2017-10-27 01:41:06 +00:00
const isCI = require('electron').remote.getGlobal('isCi')
2018-09-13 16:10:51 +00:00
const { expect } = chai
chai.use(dirtyChai)
2017-10-27 01:41:29 +00:00
describe('globalShortcut module', () => {
before(function () {
if (isCI && process.platform === 'win32') {
this.skip()
}
})
2016-08-09 22:10:51 +00:00
beforeEach(() => {
globalShortcut.unregisterAll()
})
it('can register and unregister single accelerators', () => {
const accelerator = 'CmdOrCtrl+A+B+C'
2016-08-09 22:10:51 +00:00
expect(globalShortcut.isRegistered(accelerator)).to.be.false()
2016-08-09 22:10:51 +00:00
globalShortcut.register(accelerator, () => {})
expect(globalShortcut.isRegistered(accelerator)).to.be.true()
2016-08-09 22:10:51 +00:00
globalShortcut.unregister(accelerator)
expect(globalShortcut.isRegistered(accelerator)).to.be.false()
2016-08-09 22:10:51 +00:00
expect(globalShortcut.isRegistered(accelerator)).to.be.false()
2016-08-09 22:10:51 +00:00
globalShortcut.register(accelerator, () => {})
expect(globalShortcut.isRegistered(accelerator)).to.be.true()
2016-08-09 22:10:51 +00:00
globalShortcut.unregisterAll()
expect(globalShortcut.isRegistered(accelerator)).to.be.false()
2016-08-09 22:10:51 +00:00
})
it('can register and unregister multiple accelerators', () => {
const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y']
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false()
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false()
globalShortcut.registerAll(accelerators, () => {})
expect(globalShortcut.isRegistered(accelerators[0])).to.be.true()
expect(globalShortcut.isRegistered(accelerators[1])).to.be.true()
globalShortcut.unregisterAll()
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false()
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false()
})
2016-08-09 22:10:51 +00:00
})