2019-07-15 08:29:29 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { globalShortcut } from 'electron'
|
2018-06-18 16:50:37 +00:00
|
|
|
|
2017-10-27 01:41:29 +00:00
|
|
|
describe('globalShortcut module', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (isCI && process.platform === 'win32') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2016-08-10 15:51:29 +00:00
|
|
|
|
2016-08-09 22:10:51 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
globalShortcut.unregisterAll()
|
|
|
|
})
|
|
|
|
|
2018-11-07 17:40:38 +00:00
|
|
|
it('can register and unregister single accelerators', () => {
|
|
|
|
const accelerator = 'CmdOrCtrl+A+B+C'
|
2016-08-09 22:10:51 +00:00
|
|
|
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerator)).to.be.false('initially registered')
|
2016-08-09 22:10:51 +00:00
|
|
|
globalShortcut.register(accelerator, () => {})
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerator)).to.be.true('registration worked')
|
2016-08-09 22:10:51 +00:00
|
|
|
globalShortcut.unregister(accelerator)
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerator)).to.be.false('unregistration worked')
|
2016-08-09 22:10:51 +00:00
|
|
|
|
|
|
|
globalShortcut.register(accelerator, () => {})
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerator)).to.be.true('reregistration worked')
|
2016-08-09 22:10:51 +00:00
|
|
|
globalShortcut.unregisterAll()
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerator)).to.be.false('re-unregistration worked')
|
2016-08-09 22:10:51 +00:00
|
|
|
})
|
2018-11-07 17:40:38 +00:00
|
|
|
|
|
|
|
it('can register and unregister multiple accelerators', () => {
|
|
|
|
const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y']
|
|
|
|
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first initially unregistered')
|
|
|
|
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second initially unregistered')
|
2018-11-07 17:40:38 +00:00
|
|
|
|
|
|
|
globalShortcut.registerAll(accelerators, () => {})
|
|
|
|
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerators[0])).to.be.true('first registration worked')
|
|
|
|
expect(globalShortcut.isRegistered(accelerators[1])).to.be.true('second registration worked')
|
2018-11-07 17:40:38 +00:00
|
|
|
|
|
|
|
globalShortcut.unregisterAll()
|
|
|
|
|
2019-07-15 08:29:29 +00:00
|
|
|
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first unregistered')
|
|
|
|
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second unregistered')
|
2018-11-07 17:40:38 +00:00
|
|
|
})
|
2016-08-09 22:10:51 +00:00
|
|
|
})
|