From e8a527989a18db0b7b2674647a62ce50f477079a Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 17 Apr 2018 09:44:28 -0700 Subject: [PATCH] explicitly focus elements in tests (#147) --- tests/spec/010-focus.js | 11 +++++++++-- tests/utils.js | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/spec/010-focus.js b/tests/spec/010-focus.js index 51e674b1..4b4e1856 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 94d1479b..4c427eb6 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) {