Skip to content

Commit

Permalink
test: Add Trigger Keyboard Focus test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 23, 2019
1 parent 9a2c1d6 commit 4f77051
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ function __triggerKeyboardUp(el, keyCode, opt) {
}
el.dispatchEvent ? el.dispatchEvent(eventObj) : el.fireEvent('onkeyup', eventObj);
}
function __triggerKeyboardFocus(el, keyCode, opt) {
const eventObj = document.createEventObject ?
document.createEventObject() : document.createEvent('Events');
if (eventObj.initEvent) {
eventObj.initEvent('focus', true, true);
}
if (keyCode) {
eventObj.keyCode = keyCode;
eventObj.which = keyCode;
}
if (opt) {
for (const a in opt) {
if (Object.prototype.hasOwnProperty.call(opt, a)) {
eventObj[a] = opt[a];
}
}
}
el.dispatchEvent ? el.dispatchEvent(eventObj) : el.fireEvent('onfocus', eventObj);
}

beforeAll(async () => {
browser = await puppeteer.launch({ args: ['--no-sandbox'] });
Expand Down Expand Up @@ -90,6 +109,7 @@ describe('\n Hotkeys.js Test Case222.\n', () => {

test('HotKeys modifier scope,setScope,getScope,deleteScope Test Case', () => {
let isExecuteFunction = false;
__triggerKeyboardFocus(window);
hotkeys('⌘+d', 'files', (e) => {
isExecuteFunction = true;
expect(e.keyCode).toBe(68);
Expand Down

0 comments on commit 4f77051

Please sign in to comment.