2018-02-20 02:04:37 +01:00
|
|
|
import { ClientFunction as exec, Selector as $ } from 'testcafe'
|
2018-03-03 02:54:38 +01:00
|
|
|
import * as images from './images'
|
|
|
|
import * as blobUtils from './blobUtils'
|
2018-02-20 02:04:37 +01:00
|
|
|
|
|
|
|
export const settingsButton = $('nav a[aria-label=Settings]')
|
|
|
|
export const instanceInput = $('#instanceInput')
|
2018-04-01 07:08:24 +02:00
|
|
|
export const modalDialog = $('.modal-dialog')
|
2018-02-21 18:26:22 +01:00
|
|
|
export const modalDialogContents = $('.modal-dialog-contents')
|
|
|
|
export const closeDialogButton = $('.close-dialog-button')
|
2018-02-24 23:49:28 +01:00
|
|
|
export const notificationsNavButton = $('nav a[href="/notifications"]')
|
|
|
|
export const homeNavButton = $('nav a[href="/"]')
|
2018-03-19 18:09:05 +01:00
|
|
|
export const localTimelineNavButton = $('nav a[href="/local"]')
|
2018-03-09 03:08:14 +01:00
|
|
|
export const searchNavButton = $('nav a[href="/search"]')
|
2018-04-15 03:47:55 +02:00
|
|
|
export const communityNavButton = $('nav a[href="/community"]')
|
2018-04-21 09:33:42 +02:00
|
|
|
export const settingsNavButton = $('nav a[href="/settings"]')
|
2018-02-24 23:49:28 +01:00
|
|
|
export const formError = $('.form-error-user-error')
|
2018-02-28 06:20:48 +01:00
|
|
|
export const composeInput = $('.compose-box-input')
|
2018-03-04 01:12:48 +01:00
|
|
|
export const composeContentWarning = $('.content-warning-input')
|
2018-02-28 06:20:48 +01:00
|
|
|
export const composeButton = $('.compose-box-button')
|
|
|
|
export const composeLengthIndicator = $('.compose-box-length')
|
2018-03-01 03:45:29 +01:00
|
|
|
export const emojiButton = $('.compose-box-toolbar button:first-child')
|
2018-03-03 06:55:04 +01:00
|
|
|
export const mediaButton = $('.compose-box-toolbar button:nth-child(2)')
|
2018-03-03 22:23:26 +01:00
|
|
|
export const postPrivacyButton = $('.compose-box-toolbar button:nth-child(3)')
|
2018-03-04 01:12:48 +01:00
|
|
|
export const contentWarningButton = $('.compose-box-toolbar button:nth-child(4)')
|
2018-03-01 07:45:42 +01:00
|
|
|
export const emailInput = $('input#user_email')
|
|
|
|
export const passwordInput = $('input#user_password')
|
|
|
|
export const authorizeInput = $('button[type=submit]:not(.negative)')
|
2018-03-07 08:57:06 +01:00
|
|
|
export const logInToInstanceLink = $('a[href="/settings/instances/add"]')
|
2018-03-09 03:08:14 +01:00
|
|
|
export const searchInput = $('.search-input')
|
2018-03-10 07:31:26 +01:00
|
|
|
export const postStatusButton = $('.compose-box-button')
|
2018-03-10 19:54:16 +01:00
|
|
|
export const showMoreButton = $('.more-items-header button')
|
2018-03-15 06:14:06 +01:00
|
|
|
export const accountProfileName = $('.account-profile .account-profile-name')
|
|
|
|
export const accountProfileUsername = $('.account-profile .account-profile-username')
|
|
|
|
export const accountProfileFollowedBy = $('.account-profile .account-profile-followed-by')
|
|
|
|
export const accountProfileFollowButton = $('.account-profile .account-profile-follow button')
|
2018-03-16 04:31:58 +01:00
|
|
|
export const goBackButton = $('.dynamic-page-go-back')
|
2018-04-15 03:47:55 +02:00
|
|
|
export const accountProfileMoreOptionsButton = $('.account-profile-more-options button')
|
2018-04-21 22:06:46 +02:00
|
|
|
export const addInstanceButton = $('#submitButton')
|
|
|
|
export const mastodonLogInButton = $('button[type="submit"]')
|
2018-04-27 07:05:55 +02:00
|
|
|
export const followsButton = $('.account-profile-details > *:nth-child(2)')
|
|
|
|
export const followersButton = $('.account-profile-details > *:nth-child(3)')
|
2018-04-29 21:28:44 +02:00
|
|
|
export const avatarInComposeBox = $('.compose-box-avatar')
|
2018-08-20 00:23:40 +02:00
|
|
|
export const displayNameInComposeBox = $('.compose-box-display-name')
|
2018-08-20 03:03:26 +02:00
|
|
|
export const generalSettingsButton = $('a[href="/settings/general"]')
|
2018-12-01 23:09:08 +01:00
|
|
|
export const markMediaSensitiveInput = $('#choice-mark-media-sensitive')
|
|
|
|
export const neverMarkMediaSensitiveInput = $('#choice-never-mark-media-sensitive')
|
2018-08-20 03:03:26 +02:00
|
|
|
export const removeEmojiFromDisplayNamesInput = $('#choice-omit-emoji-in-display-names')
|
2018-02-24 23:49:28 +01:00
|
|
|
|
2018-08-27 00:38:45 +02:00
|
|
|
export const favoritesCountElement = $('.status-favs').addCustomDOMProperties({
|
2018-02-24 23:49:28 +01:00
|
|
|
innerCount: el => parseInt(el.innerText, 10)
|
|
|
|
})
|
|
|
|
|
2018-08-27 00:38:45 +02:00
|
|
|
export const reblogsCountElement = $('.status-reblogs').addCustomDOMProperties({
|
2018-02-24 23:49:28 +01:00
|
|
|
innerCount: el => parseInt(el.innerText, 10)
|
|
|
|
})
|
2018-02-20 02:04:37 +01:00
|
|
|
|
2018-03-10 19:54:16 +01:00
|
|
|
export const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout))
|
|
|
|
|
2018-02-20 02:04:37 +01:00
|
|
|
export const getUrl = exec(() => window.location.href)
|
|
|
|
|
2018-02-21 18:26:22 +01:00
|
|
|
export const getActiveElementClass = exec(() =>
|
2018-04-11 05:56:42 +02:00
|
|
|
(document.activeElement && document.activeElement.getAttribute('class')) || ''
|
2018-02-21 18:26:22 +01:00
|
|
|
)
|
|
|
|
|
2018-11-24 09:41:36 +01:00
|
|
|
export const getActiveElementTagName = exec(() =>
|
|
|
|
(document.activeElement && document.activeElement.tagName) || ''
|
|
|
|
)
|
|
|
|
|
2018-03-16 04:31:58 +01:00
|
|
|
export const getActiveElementInnerText = exec(() =>
|
2018-04-11 05:56:42 +02:00
|
|
|
(document.activeElement && document.activeElement.innerText) || ''
|
2018-03-16 04:31:58 +01:00
|
|
|
)
|
|
|
|
|
2018-03-17 03:04:48 +01:00
|
|
|
export const getActiveElementInsideNthStatus = exec(() => {
|
|
|
|
let element = document.activeElement
|
|
|
|
while (element) {
|
|
|
|
if (element.hasAttribute('aria-posinset')) {
|
|
|
|
return element.getAttribute('aria-posinset')
|
|
|
|
}
|
|
|
|
element = element.parentElement
|
|
|
|
}
|
2018-04-11 05:56:42 +02:00
|
|
|
return ''
|
2018-03-17 03:04:48 +01:00
|
|
|
})
|
|
|
|
|
2018-11-13 03:28:43 +01:00
|
|
|
export const getTitleText = exec(() => document.head.querySelector('title').innerHTML)
|
|
|
|
|
2018-02-21 18:26:22 +01:00
|
|
|
export const goBack = exec(() => window.history.back())
|
|
|
|
|
2018-05-26 22:51:41 +02:00
|
|
|
export const forceOffline = exec(() => window.__forceOnline(false))
|
2018-03-09 03:08:14 +01:00
|
|
|
|
2018-05-26 22:51:41 +02:00
|
|
|
export const forceOnline = exec(() => window.__forceOnline(true))
|
2018-03-09 03:08:14 +01:00
|
|
|
|
2018-03-01 03:45:29 +01:00
|
|
|
export const getComposeSelectionStart = exec(() => composeInput().selectionStart, {
|
|
|
|
dependencies: { composeInput }
|
|
|
|
})
|
|
|
|
|
2018-11-24 09:41:36 +01:00
|
|
|
export const getCurrentTheme = exec(() => {
|
|
|
|
let themeLink = document.head.querySelector('link[rel=stylesheet][href^="/theme-"]')
|
|
|
|
if (themeLink) {
|
|
|
|
return themeLink.getAttribute('href').match(/^\/theme-(.*)\.css$/, '')[1]
|
|
|
|
}
|
|
|
|
return 'default'
|
|
|
|
})
|
2018-06-08 00:26:21 +02:00
|
|
|
|
2018-03-03 06:55:04 +01:00
|
|
|
export const uploadKittenImage = i => (exec(() => {
|
|
|
|
let image = images[`kitten${i}`]
|
|
|
|
let blob = blobUtils.base64StringToBlob(image.data, 'image/png')
|
|
|
|
blob.name = image.name
|
2018-03-03 02:54:38 +01:00
|
|
|
window.__fakeFileInput(blob)
|
|
|
|
}, {
|
|
|
|
dependencies: {
|
|
|
|
images,
|
2018-03-03 06:55:04 +01:00
|
|
|
blobUtils,
|
|
|
|
i
|
2018-03-03 02:54:38 +01:00
|
|
|
}
|
2018-03-03 06:55:04 +01:00
|
|
|
}))
|
|
|
|
|
2018-04-17 18:44:28 +02:00
|
|
|
export const focus = (selector) => (exec(() => {
|
|
|
|
document.querySelector(selector).focus()
|
|
|
|
}, {
|
|
|
|
dependencies: {
|
|
|
|
selector
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
2018-11-22 07:08:37 +01:00
|
|
|
export const scrollToBottom = exec(() => {
|
|
|
|
document.scrollingElement.scrollTop = document.scrollingElement.scrollHeight
|
|
|
|
})
|
|
|
|
|
|
|
|
export const scrollToTop = exec(() => {
|
|
|
|
document.scrollingElement.scrollTop = 0
|
|
|
|
})
|
|
|
|
|
2018-04-10 03:30:15 +02:00
|
|
|
export function getNthMediaAltInput (n) {
|
|
|
|
return $(`.compose-box .compose-media:nth-child(${n}) .compose-media-alt input`)
|
|
|
|
}
|
|
|
|
|
2018-03-30 10:06:17 +02:00
|
|
|
export function getNthComposeReplyInput (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-input`)
|
2018-03-30 10:06:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthComposeReplyButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-button`)
|
2018-03-30 10:06:17 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 19:04:35 +02:00
|
|
|
export function getNthPostPrivacyButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-toolbar button:nth-child(3)`)
|
2018-03-30 19:04:35 +02:00
|
|
|
}
|
|
|
|
|
2018-03-25 21:24:38 +02:00
|
|
|
export function getNthAutosuggestionResult (n) {
|
|
|
|
return $(`.compose-autosuggest-list-item:nth-child(${n}) button`)
|
|
|
|
}
|
|
|
|
|
2018-04-28 23:19:39 +02:00
|
|
|
export function getSearchResultByHref (href) {
|
|
|
|
return $(`.search-result a[href="${href}"]`)
|
|
|
|
}
|
|
|
|
|
2018-03-09 03:08:14 +01:00
|
|
|
export function getNthSearchResult (n) {
|
|
|
|
return $(`.search-result:nth-child(${n}) a`)
|
|
|
|
}
|
|
|
|
|
2018-03-03 06:55:04 +01:00
|
|
|
export function getNthMedia (n) {
|
|
|
|
return $(`.compose-media:nth-child(${n}) img`)
|
|
|
|
}
|
2018-03-03 02:54:38 +01:00
|
|
|
|
2018-03-03 19:27:14 +01:00
|
|
|
export function getNthDeleteMediaButton (n) {
|
|
|
|
return $(`.compose-media:nth-child(${n}) .compose-media-delete-button`)
|
|
|
|
}
|
|
|
|
|
2018-02-21 06:08:26 +01:00
|
|
|
export function getNthStatus (n) {
|
2018-04-17 18:44:28 +02:00
|
|
|
return $(getNthStatusSelector(n))
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusSelector (n) {
|
2018-06-11 04:49:39 +02:00
|
|
|
return `.list-item > article[aria-posinset="${n}"]`
|
2018-02-21 06:08:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-26 22:51:41 +02:00
|
|
|
export function getNthStatusContent (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-content`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusSpoiler (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-spoiler`)
|
|
|
|
}
|
|
|
|
|
2018-12-01 23:09:08 +01:00
|
|
|
export function getNthStatusSensitiveMediaButton (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-sensitive-media-button`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusMedia (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-media`)
|
|
|
|
}
|
|
|
|
|
2018-05-26 22:51:41 +02:00
|
|
|
export function getNthStatusHeader (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-header`)
|
|
|
|
}
|
|
|
|
|
2018-04-10 03:30:15 +02:00
|
|
|
export function getNthStatusAndImage (nStatus, nImage) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(nStatus)} .status-media .show-image-button:nth-child(${nImage + 1}) img`)
|
2018-04-10 03:30:15 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 23:49:28 +01:00
|
|
|
export function getFirstVisibleStatus () {
|
2018-06-11 04:49:39 +02:00
|
|
|
return $(`.list-item > article[aria-posinset]`).nth(0)
|
2018-02-24 23:49:28 +01:00
|
|
|
}
|
|
|
|
|
2018-03-09 17:45:12 +01:00
|
|
|
export function getNthReplyButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(1)`)
|
2018-03-09 17:45:12 +01:00
|
|
|
}
|
|
|
|
|
2018-04-08 22:42:31 +02:00
|
|
|
export function getNthReplyContentWarningInput (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .content-warning-input`)
|
2018-04-08 22:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthReplyContentWarningButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-toolbar button:nth-child(4)`)
|
2018-04-08 22:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthReplyPostPrivacyButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-toolbar button:nth-child(3)`)
|
2018-04-08 22:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthPostPrivacyOptionInDialog (n) {
|
|
|
|
return $(`.generic-dialog-list li:nth-child(${n}) button`)
|
|
|
|
}
|
|
|
|
|
2018-02-24 23:49:28 +01:00
|
|
|
export function getNthFavoriteButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(3)`)
|
2018-02-24 23:49:28 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 03:47:55 +02:00
|
|
|
export function getNthStatusOptionsButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(4)`)
|
2018-04-15 03:47:55 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 23:49:28 +01:00
|
|
|
export function getNthFavorited (n) {
|
|
|
|
return getNthFavoriteButton(n).getAttribute('aria-pressed')
|
|
|
|
}
|
|
|
|
|
2018-04-12 07:55:11 +02:00
|
|
|
export function getNthShowOrHideButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-spoiler-button button`)
|
2018-04-12 07:55:11 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 23:49:28 +01:00
|
|
|
export function getFavoritesCount () {
|
|
|
|
return favoritesCountElement.innerCount
|
|
|
|
}
|
|
|
|
|
2018-02-25 03:20:33 +01:00
|
|
|
export function getNthReblogButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(2)`)
|
2018-02-25 03:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthReblogged (n) {
|
|
|
|
return getNthReblogButton(n).getAttribute('aria-pressed')
|
|
|
|
}
|
|
|
|
|
2018-04-15 03:47:55 +02:00
|
|
|
export function getNthDialogOptionsOption (n) {
|
|
|
|
return $(`.modal-dialog li:nth-child(${n}) button`)
|
|
|
|
}
|
|
|
|
|
2018-02-24 23:49:28 +01:00
|
|
|
export function getReblogsCount () {
|
|
|
|
return reblogsCountElement.innerCount
|
2018-02-20 02:04:37 +01:00
|
|
|
}
|
|
|
|
|
2018-06-09 06:54:11 +02:00
|
|
|
function getNthPinnedStatusSelector (n) {
|
|
|
|
return `.pinned-statuses article[aria-posinset="${n}"]`
|
|
|
|
}
|
|
|
|
|
2018-04-29 21:28:44 +02:00
|
|
|
export function getNthPinnedStatus (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(getNthPinnedStatusSelector(n))
|
2018-04-29 21:28:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthPinnedStatusFavoriteButton (n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
return $(`${getNthPinnedStatusSelector(n)} .status-toolbar button:nth-child(3)`)
|
2018-04-29 21:28:44 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 03:25:59 +01:00
|
|
|
export async function validateTimeline (t, timeline) {
|
2018-05-26 22:51:41 +02:00
|
|
|
const timeout = 30000
|
2018-02-20 02:04:37 +01:00
|
|
|
for (let i = 0; i < timeline.length; i++) {
|
|
|
|
let status = timeline[i]
|
2018-05-26 22:51:41 +02:00
|
|
|
// hovering forces TestCafé to scroll to that element: https://git.io/vABV2
|
|
|
|
await t.hover(getNthStatus(i))
|
2018-02-20 02:04:37 +01:00
|
|
|
if (status.content) {
|
2018-05-26 22:51:41 +02:00
|
|
|
await t.expect(getNthStatusContent(i).innerText)
|
2018-05-25 05:01:34 +02:00
|
|
|
.contains(status.content, { timeout })
|
2018-02-20 02:04:37 +01:00
|
|
|
}
|
|
|
|
if (status.spoiler) {
|
2018-05-26 22:51:41 +02:00
|
|
|
await t.expect(getNthStatusSpoiler(i).innerText)
|
2018-05-25 05:01:34 +02:00
|
|
|
.contains(status.spoiler, { timeout })
|
2018-02-20 02:04:37 +01:00
|
|
|
}
|
|
|
|
if (status.followedBy) {
|
2018-05-26 22:51:41 +02:00
|
|
|
await t.expect(getNthStatusHeader(i).innerText)
|
2018-06-10 00:04:47 +02:00
|
|
|
.match(new RegExp(status.followedBy + '\\s+followed you'), { timeout })
|
2018-02-20 02:04:37 +01:00
|
|
|
}
|
|
|
|
if (status.rebloggedBy) {
|
2018-05-26 22:51:41 +02:00
|
|
|
await t.expect(getNthStatusHeader(i).innerText)
|
2018-06-10 00:04:47 +02:00
|
|
|
.match(new RegExp(status.rebloggedBy + '\\s+boosted your status'), { timeout })
|
2018-02-20 02:04:37 +01:00
|
|
|
}
|
|
|
|
if (status.favoritedBy) {
|
2018-05-26 22:51:41 +02:00
|
|
|
await t.expect(getNthStatusHeader(i).innerText)
|
2018-06-10 00:04:47 +02:00
|
|
|
.match(new RegExp(status.favoritedBy + '\\s+favorited your status'), { timeout })
|
2018-02-20 02:04:37 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-20 03:25:59 +01:00
|
|
|
}
|
2018-02-21 06:08:26 +01:00
|
|
|
|
2018-02-21 18:26:22 +01:00
|
|
|
export async function scrollToStatus (t, n) {
|
2018-05-25 05:01:34 +02:00
|
|
|
let timeout = 20000
|
2018-05-26 22:51:41 +02:00
|
|
|
for (let i = 0; i <= n; i++) {
|
2018-08-30 06:42:57 +02:00
|
|
|
await t.expect(getNthStatus(i).exists).ok({ timeout })
|
2018-05-25 05:01:34 +02:00
|
|
|
.hover(getNthStatus(i))
|
2018-03-16 01:33:52 +01:00
|
|
|
.expect($('.loading-footer').exist).notOk()
|
|
|
|
if (i < n) {
|
2018-06-09 06:54:11 +02:00
|
|
|
await t.hover($(`${getNthStatusSelector(i)} .status-toolbar`))
|
2018-03-16 01:33:52 +01:00
|
|
|
.expect($('.loading-footer').exist).notOk()
|
|
|
|
}
|
2018-02-21 18:26:22 +01:00
|
|
|
}
|
|
|
|
await t.hover(getNthStatus(n))
|
|
|
|
}
|
2018-03-11 05:24:07 +01:00
|
|
|
|
|
|
|
export async function clickToNotificationsAndBackHome (t) {
|
|
|
|
await t.click(notificationsNavButton)
|
|
|
|
.expect(getUrl()).eql('http://localhost:4002/notifications')
|
|
|
|
.click(homeNavButton)
|
|
|
|
.expect(getUrl()).eql('http://localhost:4002/')
|
|
|
|
}
|
2018-04-19 05:43:13 +02:00
|
|
|
|
|
|
|
// like lodash.times but I don't want to try to figure out esm
|
|
|
|
// just to import lodash-es
|
|
|
|
export function times (n, cb) {
|
|
|
|
let arr = []
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
arr.push(cb(i))
|
|
|
|
}
|
|
|
|
return arr
|
|
|
|
}
|