explicitly focus elements in tests (#147)

This commit is contained in:
Nolan Lawson 2018-04-17 09:44:28 -07:00 committed by GitHub
parent eef54e992b
commit e8a527989a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import {
getNthStatus, scrollToStatus, closeDialogButton, modalDialogContents, getActiveElementClass, goBack, getUrl,
goBackButton, getActiveElementInnerText, getNthReplyButton, getActiveElementInsideNthStatus
goBackButton, getActiveElementInnerText, getNthReplyButton, getActiveElementInsideNthStatus, focus,
getNthStatusSelector
} from '../utils'
import { foobarRole } from '../roles'
@ -10,6 +11,9 @@ fixture`010-focus.js`
test('modal preserves focus', async t => {
await t.useRole(foobarRole)
await scrollToStatus(t, 9)
// explicitly hover-focus-click
await t.hover(getNthStatus(9).find('.play-video-button'))
await focus(`${getNthStatusSelector(9)} .play-video-button`)()
await t.click(getNthStatus(9).find('.play-video-button'))
.click(closeDialogButton)
.expect(modalDialogContents.exists).notOk()
@ -19,7 +23,10 @@ test('modal preserves focus', async t => {
test('timeline preserves focus', async t => {
await t.useRole(foobarRole)
.click(getNthStatus(0))
// explicitly hover-focus-click
await t.hover(getNthStatus(0))
await focus(getNthStatusSelector(0))()
await t.click(getNthStatus(0))
.expect(getUrl()).contains('/statuses/')
await goBack()

View File

@ -99,6 +99,14 @@ export const uploadKittenImage = i => (exec(() => {
}
}))
export const focus = (selector) => (exec(() => {
document.querySelector(selector).focus()
}, {
dependencies: {
selector
}
}))
export function getNthMediaAltInput (n) {
return $(`.compose-box .compose-media:nth-child(${n}) .compose-media-alt input`)
}
@ -132,7 +140,11 @@ export function getNthDeleteMediaButton (n) {
}
export function getNthStatus (n) {
return $(`div[aria-hidden="false"] > article[aria-posinset="${n}"]`)
return $(getNthStatusSelector(n))
}
export function getNthStatusSelector (n) {
return `div[aria-hidden="false"] > article[aria-posinset="${n}"]`
}
export function getNthStatusAndImage (nStatus, nImage) {