fedilove-ui/tests/spec/010-focus.js

116 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-02-21 17:26:22 +00:00
import {
getNthStatus, scrollToStatus, closeDialogButton, modalDialogContents, goBack, getUrl,
goBackButton, getActiveElementInnerText, getNthReplyButton, getActiveElementInsideNthStatus, focus,
getNthStatusSelector, getActiveElementTagName, getActiveElementClassList
2018-02-21 17:26:22 +00:00
} from '../utils'
import { loginAsFoobar } from '../roles'
import { Selector as $ } from 'testcafe'
import { indexWhere } from '../../src/routes/_utils/arrays'
import { homeTimeline } from '../fixtures'
2018-02-21 17:26:22 +00:00
2018-03-07 05:32:51 +00:00
fixture`010-focus.js`
2018-02-21 17:26:22 +00:00
.page`http://localhost:4002`
test('modal preserves focus', async t => {
await loginAsFoobar(t)
let idx = indexWhere(homeTimeline, _ => _.content === "here's a video")
await scrollToStatus(t, idx)
// explicitly hover-focus-click
await t.hover($(`${getNthStatusSelector(idx)} .play-video-button`))
await focus(`${getNthStatusSelector(idx)} .play-video-button`)()
await t.click($(`${getNthStatusSelector(idx)} .play-video-button`))
2018-02-21 17:26:22 +00:00
.click(closeDialogButton)
.expect(modalDialogContents.exists).notOk()
.expect(getActiveElementClassList()).contains('play-video-button')
.expect(getActiveElementInsideNthStatus()).eql(idx.toString())
2018-02-21 17:26:22 +00:00
})
test('timeline preserves focus', async t => {
await loginAsFoobar(t)
// explicitly hover-focus-click
await t.hover(getNthStatus(0))
await focus(getNthStatusSelector(0))()
await t.click(getNthStatus(0))
2018-03-06 06:36:54 +00:00
.expect(getUrl()).contains('/statuses/')
2018-02-21 17:26:22 +00:00
await goBack()
2018-03-16 03:31:58 +00:00
await t.expect(getUrl()).eql('http://localhost:4002/')
.expect(getActiveElementClassList()).contains('status-article')
.expect(getActiveElementClassList()).contains('status-in-timeline')
2018-03-17 02:04:48 +00:00
.expect(getActiveElementInsideNthStatus()).eql('0')
2018-03-16 03:31:58 +00:00
})
test('timeline link preserves focus', async t => {
await loginAsFoobar(t)
await t
.expect(getNthStatus(0).exists).ok({ timeout: 20000 })
.click($(`${getNthStatusSelector(0)} .status-header a`))
2018-03-16 03:31:58 +00:00
.expect(getUrl()).contains('/accounts/')
.click(goBackButton)
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getNthStatus(0).exists).ok()
2018-03-16 03:31:58 +00:00
.expect(getActiveElementInnerText()).eql('admin')
.click($(`${getNthStatusSelector(0)} .status-sidebar`))
.expect(getUrl()).contains('/accounts/')
.click(goBackButton)
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getActiveElementClassList()).contains('status-sidebar')
2018-03-17 02:04:48 +00:00
.expect(getActiveElementInsideNthStatus()).eql('0')
2018-03-16 03:31:58 +00:00
})
test('notification timeline preserves focus', async t => {
await loginAsFoobar(t)
await t
2018-03-16 03:31:58 +00:00
.navigateTo('/notifications')
await scrollToStatus(t, 5)
await t.click($(`${getNthStatusSelector(5)} .status-header a`))
2018-03-16 03:31:58 +00:00
.expect(getUrl()).contains('/accounts/')
.click(goBackButton)
.expect(getUrl()).contains('/notifications')
.expect(getNthStatus(0).exists).ok()
2018-03-16 03:31:58 +00:00
.expect(getActiveElementInnerText()).eql('quux')
2018-03-17 02:04:48 +00:00
.expect(getActiveElementInsideNthStatus()).eql('5')
})
test('thread preserves focus', async t => {
2019-02-23 20:32:10 +00:00
const timeout = 30000
await loginAsFoobar(t)
await t
.navigateTo('/accounts/3')
2019-02-23 20:32:10 +00:00
.expect(getNthStatus(0).exists).ok({ timeout })
.hover(getNthStatus(0))
await scrollToStatus(t, 2)
await t.click(getNthStatus(2))
.expect(getUrl()).contains('/statuses/')
.click($(`${getNthStatusSelector(24)} .status-sidebar`))
.expect(getUrl()).contains('/accounts/')
.click(goBackButton)
.expect(getUrl()).contains('/statuses/')
.expect(getNthStatus(24).exists).ok()
.expect(getActiveElementClassList()).contains('status-sidebar')
.expect(getActiveElementInsideNthStatus()).eql('24')
.hover(getNthStatus(23))
.click(getNthStatus(23))
2019-02-23 20:32:10 +00:00
.expect($(`${getNthStatusSelector(23)} .status-absolute-date`).exists).ok({ timeout })
await goBack()
2019-02-23 20:32:10 +00:00
await t.expect($(`${getNthStatusSelector(24)} .status-absolute-date`).exists).ok({ timeout })
.expect(getActiveElementClassList()).contains('status-article', { timeout })
.expect(getActiveElementClassList()).contains('status-in-timeline', { timeout })
.expect(getActiveElementInsideNthStatus()).eql('23', { timeout })
})
2018-03-17 02:04:48 +00:00
test('reply preserves focus and moves focus to the text input', async t => {
await loginAsFoobar(t)
await t
.expect(getNthStatus(1).exists).ok({ timeout: 20000 })
2018-03-17 02:04:48 +00:00
.click(getNthReplyButton(1))
.expect(getActiveElementClassList()).contains('compose-box-input')
2018-02-21 17:26:22 +00:00
})
test('focus main content element on index page load', async t => {
await t.expect(getActiveElementTagName()).match(/body/i)
})