Created
February 23, 2018 10:11
-
-
Save jgwhite/a36da6217bde4d23a9434bfda3172b8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { focus, triggerKeyEvent } from '@ember/test-helpers'; | |
import findButton from './find-button'; | |
import { calculateTabsTo } from './tabbability'; | |
const KEY_RETURN = 13; | |
export default async function keyboardClick(text) { | |
let element = findButton(text); | |
if (!element) { | |
throw new Error(`Could not find a button containing "${text}"`); | |
} | |
let tabs = calculateTabsTo(element); | |
if (tabs < 0) { | |
throw new Error(`The user would have to tab backwards to reach the button containing "${text}"`); | |
} | |
await focus(element); | |
await triggerKeyEvent(element, 'keydown', KEY_RETURN); | |
await triggerKeyEvent(element, 'keypress', KEY_RETURN); | |
await triggerKeyEvent(element, 'keyup', KEY_RETURN); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment