fedilove-ui/tests/utils.js

61 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-02-20 01:04:37 +00:00
import { ClientFunction as exec, Selector as $ } from 'testcafe'
export const settingsButton = $('nav a[aria-label=Settings]')
export const instanceInput = $('#instanceInput')
export const addInstanceButton = $('.add-new-instance button')
export const getUrl = exec(() => window.location.href)
2018-02-21 05:08:26 +00:00
export function getNthStatus (n) {
return $(`[aria-hidden="false"] > article[aria-posinset="${n}"]`)
}
export function getLastVisibleStatus () {
return $(`[aria-hidden="false"] > article[aria-posinset]`).nth(-1)
2018-02-20 01:04:37 +00:00
}
2018-02-20 02:25:59 +00:00
export async function validateTimeline (t, timeline) {
2018-02-20 01:04:37 +00:00
for (let i = 0; i < timeline.length; i++) {
let status = timeline[i]
if (status.content) {
2018-02-21 05:08:26 +00:00
await t.expect(getNthStatus(i).find('.status-content p').innerText)
2018-02-20 01:04:37 +00:00
.contains(status.content)
}
if (status.spoiler) {
2018-02-21 05:08:26 +00:00
await t.expect(getNthStatus(i).find('.status-spoiler p').innerText)
2018-02-20 01:04:37 +00:00
.contains(status.spoiler)
}
if (status.followedBy) {
2018-02-21 05:08:26 +00:00
await t.expect(getNthStatus(i).find('.status-header span').innerText)
2018-02-20 01:04:37 +00:00
.contains(status.followedBy + ' followed you')
}
if (status.rebloggedBy) {
2018-02-21 05:08:26 +00:00
await t.expect(getNthStatus(i).find('.status-header span').innerText)
2018-02-20 01:04:37 +00:00
.contains(status.rebloggedBy + ' boosted your status')
}
if (status.favoritedBy) {
2018-02-21 05:08:26 +00:00
await t.expect(getNthStatus(i).find('.status-header span').innerText)
2018-02-20 01:04:37 +00:00
.contains(status.favoritedBy + ' favorited your status')
}
// hovering forces TestCafé to scroll to that element: https://git.io/vABV2
if (i % 3 === 2) { // only scroll every nth element
2018-02-21 05:08:26 +00:00
await t.hover(getNthStatus(i))
.expect($('.loading-footer').exist).notOk()
2018-02-20 01:04:37 +00:00
}
}
2018-02-20 02:25:59 +00:00
}
2018-02-21 05:08:26 +00:00
export async function scrollToBottomOfTimeline (t) {
let lastSize = null
while (true) {
await t.hover(getLastVisibleStatus())
.expect($('.loading-footer').exist).notOk()
let newSize = await getLastVisibleStatus().getAttribute('aria-setsize')
if (newSize === lastSize) {
break
}
lastSize = newSize
}
2018-02-21 05:30:16 +00:00
}