diff --git a/tests/spec/010-focus.js b/tests/spec/010-focus.js index 51e674b..4b4e185 100644 --- a/tests/spec/010-focus.js +++ b/tests/spec/010-focus.js @@ -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() diff --git a/tests/utils.js b/tests/utils.js index 94d1479..4c427eb 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -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) {