forked from cybrespace/pinafore
explicitly focus elements in tests (#147)
This commit is contained in:
parent
eef54e992b
commit
e8a527989a
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
getNthStatus, scrollToStatus, closeDialogButton, modalDialogContents, getActiveElementClass, goBack, getUrl,
|
getNthStatus, scrollToStatus, closeDialogButton, modalDialogContents, getActiveElementClass, goBack, getUrl,
|
||||||
goBackButton, getActiveElementInnerText, getNthReplyButton, getActiveElementInsideNthStatus
|
goBackButton, getActiveElementInnerText, getNthReplyButton, getActiveElementInsideNthStatus, focus,
|
||||||
|
getNthStatusSelector
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { foobarRole } from '../roles'
|
import { foobarRole } from '../roles'
|
||||||
|
|
||||||
|
@ -10,6 +11,9 @@ fixture`010-focus.js`
|
||||||
test('modal preserves focus', async t => {
|
test('modal preserves focus', async t => {
|
||||||
await t.useRole(foobarRole)
|
await t.useRole(foobarRole)
|
||||||
await scrollToStatus(t, 9)
|
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'))
|
await t.click(getNthStatus(9).find('.play-video-button'))
|
||||||
.click(closeDialogButton)
|
.click(closeDialogButton)
|
||||||
.expect(modalDialogContents.exists).notOk()
|
.expect(modalDialogContents.exists).notOk()
|
||||||
|
@ -19,7 +23,10 @@ test('modal preserves focus', async t => {
|
||||||
|
|
||||||
test('timeline preserves focus', async t => {
|
test('timeline preserves focus', async t => {
|
||||||
await t.useRole(foobarRole)
|
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/')
|
.expect(getUrl()).contains('/statuses/')
|
||||||
|
|
||||||
await goBack()
|
await goBack()
|
||||||
|
|
|
@ -99,6 +99,14 @@ export const uploadKittenImage = i => (exec(() => {
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
export const focus = (selector) => (exec(() => {
|
||||||
|
document.querySelector(selector).focus()
|
||||||
|
}, {
|
||||||
|
dependencies: {
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
export function getNthMediaAltInput (n) {
|
export function getNthMediaAltInput (n) {
|
||||||
return $(`.compose-box .compose-media:nth-child(${n}) .compose-media-alt input`)
|
return $(`.compose-box .compose-media:nth-child(${n}) .compose-media-alt input`)
|
||||||
}
|
}
|
||||||
|
@ -132,7 +140,11 @@ export function getNthDeleteMediaButton (n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNthStatus (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) {
|
export function getNthStatusAndImage (nStatus, nImage) {
|
||||||
|
|
Loading…
Reference in New Issue