2018-02-19 17:04:37 -08:00
|
|
|
import { ClientFunction as exec, Selector as $ } from 'testcafe'
|
2018-03-02 17:54:38 -08:00
|
|
|
import * as images from './images'
|
|
|
|
import * as blobUtils from './blobUtils'
|
2018-02-19 17:04:37 -08:00
|
|
|
|
|
|
|
export const settingsButton = $('nav a[aria-label=Settings]')
|
|
|
|
export const instanceInput = $('#instanceInput')
|
2018-03-31 22:08:24 -07:00
|
|
|
export const modalDialog = $('.modal-dialog')
|
2019-03-23 18:16:06 -07:00
|
|
|
export const visibleModalDialog = $('.modal-dialog:not([aria-hidden="true"])')
|
2018-02-21 09:26:22 -08:00
|
|
|
export const modalDialogContents = $('.modal-dialog-contents')
|
2019-03-24 15:08:34 -07:00
|
|
|
export const modalDialogBackdrop = $('.modal-dialog-backdrop')
|
|
|
|
export const closeDialogButton = $('.modal-dialog:not([aria-hidden="true"]) .close-dialog-button')
|
2018-02-24 14:49:28 -08:00
|
|
|
export const notificationsNavButton = $('nav a[href="/notifications"]')
|
|
|
|
export const homeNavButton = $('nav a[href="/"]')
|
2018-03-19 10:09:05 -07:00
|
|
|
export const localTimelineNavButton = $('nav a[href="/local"]')
|
2018-03-08 18:08:14 -08:00
|
|
|
export const searchNavButton = $('nav a[href="/search"]')
|
2018-04-14 18:47:55 -07:00
|
|
|
export const communityNavButton = $('nav a[href="/community"]')
|
2018-04-21 00:33:42 -07:00
|
|
|
export const settingsNavButton = $('nav a[href="/settings"]')
|
2018-02-24 14:49:28 -08:00
|
|
|
export const formError = $('.form-error-user-error')
|
2018-02-27 21:20:48 -08:00
|
|
|
export const composeInput = $('.compose-box-input')
|
2018-03-03 16:12:48 -08:00
|
|
|
export const composeContentWarning = $('.content-warning-input')
|
2018-02-27 21:20:48 -08:00
|
|
|
export const composeButton = $('.compose-box-button')
|
2019-08-24 21:23:43 -07:00
|
|
|
export const composeLengthIndicator = $('.length-indicator')
|
2018-02-28 18:45:29 -08:00
|
|
|
export const emojiButton = $('.compose-box-toolbar button:first-child')
|
2018-03-02 21:55:04 -08:00
|
|
|
export const mediaButton = $('.compose-box-toolbar button:nth-child(2)')
|
2019-05-27 12:31:35 -07:00
|
|
|
export const pollButton = $('.compose-box-toolbar button:nth-child(3)')
|
2019-05-27 00:24:47 -07:00
|
|
|
export const postPrivacyButton = $('.compose-box-toolbar button:nth-child(4)')
|
|
|
|
export const contentWarningButton = $('.compose-box-toolbar button:nth-child(5)')
|
2018-02-28 22:45:42 -08:00
|
|
|
export const emailInput = $('input#user_email')
|
|
|
|
export const passwordInput = $('input#user_password')
|
|
|
|
export const authorizeInput = $('button[type=submit]:not(.negative)')
|
2018-03-06 23:57:06 -08:00
|
|
|
export const logInToInstanceLink = $('a[href="/settings/instances/add"]')
|
2019-09-26 05:28:52 -07:00
|
|
|
export const copyPasteModeButton = $('.copy-paste-mode-button')
|
|
|
|
export const oauthCodeInput = $('#oauthCodeInput')
|
2018-03-08 18:08:14 -08:00
|
|
|
export const searchInput = $('.search-input')
|
2018-03-09 22:31:26 -08:00
|
|
|
export const postStatusButton = $('.compose-box-button')
|
2018-03-10 10:54:16 -08:00
|
|
|
export const showMoreButton = $('.more-items-header button')
|
2018-03-14 22:14:06 -07: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-15 20:31:58 -07:00
|
|
|
export const goBackButton = $('.dynamic-page-go-back')
|
2018-04-14 18:47:55 -07:00
|
|
|
export const accountProfileMoreOptionsButton = $('.account-profile-more-options button')
|
2018-04-21 13:06:46 -07:00
|
|
|
export const addInstanceButton = $('#submitButton')
|
2019-09-26 05:28:52 -07:00
|
|
|
export const submitOauthButton = $('#submitOauthButton')
|
2018-04-21 13:06:46 -07:00
|
|
|
export const mastodonLogInButton = $('button[type="submit"]')
|
2018-04-26 22:05:55 -07:00
|
|
|
export const followsButton = $('.account-profile-details > *:nth-child(2)')
|
|
|
|
export const followersButton = $('.account-profile-details > *:nth-child(3)')
|
2018-04-29 12:28:44 -07:00
|
|
|
export const avatarInComposeBox = $('.compose-box-avatar')
|
2018-08-19 15:23:40 -07:00
|
|
|
export const displayNameInComposeBox = $('.compose-box-display-name')
|
2018-08-19 18:03:26 -07:00
|
|
|
export const generalSettingsButton = $('a[href="/settings/general"]')
|
2018-12-01 14:09:08 -08:00
|
|
|
export const markMediaSensitiveInput = $('#choice-mark-media-sensitive')
|
|
|
|
export const neverMarkMediaSensitiveInput = $('#choice-never-mark-media-sensitive')
|
2018-08-19 18:03:26 -07:00
|
|
|
export const removeEmojiFromDisplayNamesInput = $('#choice-omit-emoji-in-display-names')
|
2019-05-28 22:46:01 -07:00
|
|
|
export const disableInfiniteScroll = $('#choice-disable-infinite-scroll')
|
2019-06-01 15:51:53 -07:00
|
|
|
export const disableUnreadNotifications = $('#choice-disable-unread-notification-counts')
|
2019-09-22 23:53:29 -07:00
|
|
|
export const leftRightChangesFocus = $('#choice-left-right-focus')
|
|
|
|
export const disableHotkeys = $('#choice-disable-hotkeys')
|
2019-08-19 19:08:59 -07:00
|
|
|
export const dialogOptionsOption = $('.modal-dialog button')
|
2018-12-18 00:43:51 -08:00
|
|
|
export const emojiSearchInput = $('.emoji-mart-search input')
|
2019-02-18 15:43:41 -08:00
|
|
|
export const confirmationDialogOKButton = $('.confirmation-dialog-form-flex button:nth-child(1)')
|
2019-02-18 19:55:44 -08:00
|
|
|
export const confirmationDialogCancelButton = $('.confirmation-dialog-form-flex button:nth-child(2)')
|
2018-12-03 23:23:29 -08:00
|
|
|
|
2019-05-28 22:46:01 -07:00
|
|
|
export const loadMoreButton = $('.loading-footer button')
|
|
|
|
|
2018-12-03 23:23:29 -08:00
|
|
|
export const composeModalInput = $('.modal-dialog .compose-box-input')
|
|
|
|
export const composeModalComposeButton = $('.modal-dialog .compose-box-button')
|
|
|
|
export const composeModalContentWarningInput = $('.modal-dialog .content-warning-input')
|
|
|
|
export const composeModalEmojiButton = $('.modal-dialog .compose-box-toolbar button:nth-child(1)')
|
2019-05-27 00:24:47 -07:00
|
|
|
export const composeModalPostPrivacyButton = $('.modal-dialog .compose-box-toolbar button:nth-child(4)')
|
2019-09-17 00:19:53 -07:00
|
|
|
export const composeModalMediaSensitiveCheckbox = $('.modal-dialog .compose-media-sensitive input')
|
2018-12-03 23:23:29 -08:00
|
|
|
|
2019-05-27 12:31:35 -07:00
|
|
|
export const composePoll = $('.compose-poll')
|
|
|
|
export const composePollMultipleChoice = $('.compose-poll input[type="checkbox"]')
|
2019-07-19 20:08:17 -07:00
|
|
|
export const composePollMultipleChoiceInDialog = $('.modal-dialog .compose-poll input[type="checkbox"]')
|
2019-05-27 12:31:35 -07:00
|
|
|
export const composePollExpiry = $('.compose-poll select')
|
2019-07-19 20:08:17 -07:00
|
|
|
export const composePollExpiryOption = $('.compose-poll select option')
|
|
|
|
export const composePollExpiryInDialog = $('.modal-dialog .compose-poll select')
|
2019-05-27 12:31:35 -07:00
|
|
|
export const composePollAddButton = $('.compose-poll button:last-of-type')
|
|
|
|
|
2019-09-15 10:45:46 -07:00
|
|
|
export const composeMediaSensitiveCheckbox = $('.compose-media-sensitive input')
|
|
|
|
|
2019-03-24 15:08:34 -07:00
|
|
|
export const postPrivacyDialogButtonUnlisted = $('[aria-label="Post privacy dialog"] li:nth-child(2) button')
|
|
|
|
|
2019-03-30 21:48:49 -07:00
|
|
|
export const accountProfileFilterStatuses = $('.account-profile-filters li:nth-child(1)')
|
|
|
|
export const accountProfileFilterStatusesAndReplies = $('.account-profile-filters li:nth-child(2)')
|
|
|
|
export const accountProfileFilterMedia = $('.account-profile-filters li:nth-child(3)')
|
|
|
|
|
2019-05-25 13:21:36 -07:00
|
|
|
export const notificationsTabAll = $('.notification-filters li:nth-child(1)')
|
|
|
|
export const notificationsTabMentions = $('.notification-filters li:nth-child(2)')
|
|
|
|
|
|
|
|
export const instanceSettingHomeReblogs = $('#instance-option-homeReblogs')
|
|
|
|
export const instanceSettingNotificationFollows = $('#instance-option-notificationFollows')
|
|
|
|
export const instanceSettingNotificationFavs = $('#instance-option-notificationFavs')
|
|
|
|
export const instanceSettingNotificationReblogs = $('#instance-option-notificationReblogs')
|
|
|
|
export const instanceSettingNotificationMentions = $('#instance-option-notificationMentions')
|
2019-05-04 17:58:44 -07:00
|
|
|
|
2019-05-26 16:01:06 -07:00
|
|
|
export const notificationBadge = $('#main-nav li:nth-child(2) .nav-link-badge')
|
|
|
|
|
2019-07-07 00:14:19 -07:00
|
|
|
export const focalPointXInput = $('.media-focal-point-inputs *:nth-child(1) input')
|
|
|
|
export const focalPointYInput = $('.media-focal-point-inputs *:nth-child(2) input')
|
|
|
|
|
2018-12-03 23:23:29 -08:00
|
|
|
export function getComposeModalNthMediaAltInput (n) {
|
2019-05-27 12:31:49 -07:00
|
|
|
return $(`.modal-dialog .compose-media:nth-child(${n}) .compose-media-alt textarea`)
|
2018-12-03 23:23:29 -08:00
|
|
|
}
|
|
|
|
|
2019-07-07 00:14:19 -07:00
|
|
|
export function getComposeModalNthMediaListItem (n) {
|
|
|
|
return $(`.modal-dialog .compose-media:nth-child(${n})`)
|
2018-12-03 23:23:29 -08:00
|
|
|
}
|
2018-02-24 14:49:28 -08:00
|
|
|
|
2018-08-26 15:38:45 -07:00
|
|
|
export const favoritesCountElement = $('.status-favs').addCustomDOMProperties({
|
2018-02-24 14:49:28 -08:00
|
|
|
innerCount: el => parseInt(el.innerText, 10)
|
|
|
|
})
|
|
|
|
|
2018-08-26 15:38:45 -07:00
|
|
|
export const reblogsCountElement = $('.status-reblogs').addCustomDOMProperties({
|
2018-02-24 14:49:28 -08:00
|
|
|
innerCount: el => parseInt(el.innerText, 10)
|
|
|
|
})
|
2018-02-19 17:04:37 -08:00
|
|
|
|
2018-03-10 10:54:16 -08:00
|
|
|
export const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout))
|
|
|
|
|
2018-02-19 17:04:37 -08:00
|
|
|
export const getUrl = exec(() => window.location.href)
|
|
|
|
|
2019-11-23 19:11:15 -08:00
|
|
|
export const getNumSyntheticListeners = exec(() => {
|
|
|
|
return Object.keys(window.__eventBus.$e).map(key => window.__eventBus.listenerCount(key))
|
|
|
|
.concat(window.__resizeListeners.size)
|
|
|
|
.concat(Object.keys(window.__delegateCallbacks).length)
|
|
|
|
.reduce((a, b) => a + b, 0)
|
|
|
|
})
|
|
|
|
|
2019-03-23 18:16:06 -07:00
|
|
|
export const getMediaScrollLeft = exec(() => document.querySelector('.media-scroll').scrollLeft || 0)
|
|
|
|
|
2019-02-23 09:47:36 -08:00
|
|
|
export const getActiveElementClassList = exec(() =>
|
|
|
|
(document.activeElement && (document.activeElement.getAttribute('class') || '').split(/\s+/)) || []
|
2018-02-21 09:26:22 -08:00
|
|
|
)
|
|
|
|
|
2019-12-08 18:03:26 -08:00
|
|
|
export const getActiveElementHref = exec(() =>
|
|
|
|
(document.activeElement && (document.activeElement.getAttribute('href') || ''))
|
|
|
|
)
|
|
|
|
|
2018-11-24 00:41:36 -08:00
|
|
|
export const getActiveElementTagName = exec(() =>
|
|
|
|
(document.activeElement && document.activeElement.tagName) || ''
|
|
|
|
)
|
|
|
|
|
2018-03-15 20:31:58 -07:00
|
|
|
export const getActiveElementInnerText = exec(() =>
|
2018-04-10 20:56:42 -07:00
|
|
|
(document.activeElement && document.activeElement.innerText) || ''
|
2018-03-15 20:31:58 -07:00
|
|
|
)
|
|
|
|
|
2019-02-21 23:50:27 -08:00
|
|
|
export const getActiveElementRectTop = exec(() => (
|
|
|
|
(document.activeElement && document.activeElement.getBoundingClientRect().top) || -1
|
|
|
|
))
|
|
|
|
|
2019-05-28 22:46:01 -07:00
|
|
|
export const getActiveElementAriaPosInSet = exec(() => (
|
|
|
|
(document.activeElement && document.activeElement.getAttribute('aria-posinset')) || ''
|
|
|
|
))
|
|
|
|
|
2019-09-22 23:53:29 -07:00
|
|
|
export const getActiveElementAriaLabel = exec(() => (
|
|
|
|
(document.activeElement && document.activeElement.getAttribute('aria-label')) || ''
|
|
|
|
))
|
|
|
|
|
2018-03-16 19:04:48 -07: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-10 20:56:42 -07:00
|
|
|
return ''
|
2018-03-16 19:04:48 -07:00
|
|
|
})
|
|
|
|
|
2019-12-14 12:04:36 -08:00
|
|
|
export const getNthStatusId = n => exec(() => {
|
|
|
|
return document.querySelector(getNthStatusSelector(n))
|
|
|
|
.getAttribute('id')
|
|
|
|
.split('/')
|
|
|
|
.slice(-1)[0]
|
|
|
|
}, {
|
|
|
|
dependencies: {
|
|
|
|
getNthStatusSelector,
|
|
|
|
n
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export const getStatusContents = exec(() => {
|
|
|
|
const res = []
|
|
|
|
const elements = document.querySelectorAll('.list-item > article .status-content')
|
|
|
|
for (let i = 0; i < elements.length; i++) {
|
|
|
|
res.push(elements[i].innerText)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
})
|
|
|
|
|
2018-12-30 14:51:03 -08:00
|
|
|
export const getTitleText = exec(() => document.head.querySelector('title') && document.head.querySelector('title').innerHTML)
|
2018-11-12 18:28:43 -08:00
|
|
|
|
2018-02-21 09:26:22 -08:00
|
|
|
export const goBack = exec(() => window.history.back())
|
|
|
|
|
2018-12-11 22:06:50 -08:00
|
|
|
export const goForward = exec(() => window.history.forward())
|
|
|
|
|
2018-12-14 00:25:12 -08:00
|
|
|
export const reload = exec(() => window.location.reload())
|
|
|
|
|
2018-05-26 13:51:41 -07:00
|
|
|
export const forceOffline = exec(() => window.__forceOnline(false))
|
2018-03-08 18:08:14 -08:00
|
|
|
|
2018-05-26 13:51:41 -07:00
|
|
|
export const forceOnline = exec(() => window.__forceOnline(true))
|
2018-03-08 18:08:14 -08:00
|
|
|
|
2018-02-28 18:45:29 -08:00
|
|
|
export const getComposeSelectionStart = exec(() => composeInput().selectionStart, {
|
|
|
|
dependencies: { composeInput }
|
|
|
|
})
|
|
|
|
|
2018-12-14 00:25:12 -08:00
|
|
|
export const getOpacity = selector => exec(() => window.getComputedStyle(document.querySelector(selector)).opacity, {
|
|
|
|
dependencies: { selector }
|
|
|
|
})
|
|
|
|
|
2018-11-24 00:41:36 -08:00
|
|
|
export const getCurrentTheme = exec(() => {
|
2019-08-03 13:49:37 -07:00
|
|
|
const themeLink = document.head.querySelector('link[rel=stylesheet][href^="/theme-"]')
|
2018-11-24 00:41:36 -08:00
|
|
|
if (themeLink) {
|
|
|
|
return themeLink.getAttribute('href').match(/^\/theme-(.*)\.css$/, '')[1]
|
|
|
|
}
|
|
|
|
return 'default'
|
|
|
|
})
|
2018-06-07 15:26:21 -07:00
|
|
|
|
2018-03-02 21:55:04 -08:00
|
|
|
export const uploadKittenImage = i => (exec(() => {
|
2019-08-03 13:49:37 -07:00
|
|
|
const image = images[`kitten${i}`]
|
|
|
|
const blob = blobUtils.base64StringToBlob(image.data, 'image/png')
|
2018-03-02 21:55:04 -08:00
|
|
|
blob.name = image.name
|
2019-08-03 13:49:37 -07:00
|
|
|
const fileDrop = document.querySelector('file-drop')
|
|
|
|
const event = new Event('filedrop', { bubbles: false })
|
2019-02-19 22:24:03 -08:00
|
|
|
event.files = [blob]
|
|
|
|
fileDrop.dispatchEvent(event)
|
2018-03-02 17:54:38 -08:00
|
|
|
}, {
|
|
|
|
dependencies: {
|
|
|
|
images,
|
2018-03-02 21:55:04 -08:00
|
|
|
blobUtils,
|
|
|
|
i
|
2018-03-02 17:54:38 -08:00
|
|
|
}
|
2018-03-02 21:55:04 -08:00
|
|
|
}))
|
|
|
|
|
2018-04-17 09:44:28 -07:00
|
|
|
export const focus = (selector) => (exec(() => {
|
|
|
|
document.querySelector(selector).focus()
|
|
|
|
}, {
|
|
|
|
dependencies: {
|
|
|
|
selector
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
2019-02-21 23:50:27 -08:00
|
|
|
export const isNthStatusActive = (idx) => (exec(() => {
|
|
|
|
return document.activeElement &&
|
|
|
|
document.activeElement.getAttribute('aria-posinset') === idx.toString()
|
|
|
|
}, {
|
|
|
|
dependencies: { idx }
|
|
|
|
}))
|
|
|
|
|
2019-02-23 09:47:36 -08:00
|
|
|
export const isActiveStatusPinned = exec(() => {
|
2019-08-03 13:49:37 -07:00
|
|
|
const el = document.activeElement
|
2019-02-23 12:32:00 -08:00
|
|
|
return el &&
|
|
|
|
(
|
|
|
|
(el.parentElement.getAttribute('class') || '').includes('pinned') ||
|
|
|
|
(el.parentElement.parentElement.getAttribute('class') || '').includes('pinned')
|
|
|
|
)
|
2019-02-23 09:47:36 -08:00
|
|
|
})
|
|
|
|
|
2018-11-21 22:08:37 -08:00
|
|
|
export const scrollToBottom = exec(() => {
|
|
|
|
document.scrollingElement.scrollTop = document.scrollingElement.scrollHeight
|
|
|
|
})
|
|
|
|
|
|
|
|
export const scrollToTop = exec(() => {
|
|
|
|
document.scrollingElement.scrollTop = 0
|
|
|
|
})
|
|
|
|
|
2019-04-20 09:12:30 -07:00
|
|
|
export const getScrollTop = exec(() => {
|
|
|
|
return document.scrollingElement.scrollTop || 0
|
|
|
|
})
|
|
|
|
|
2018-04-09 18:30:15 -07:00
|
|
|
export function getNthMediaAltInput (n) {
|
2019-05-27 12:31:49 -07:00
|
|
|
return $(`.compose-box .compose-media:nth-child(${n}) .compose-media-alt textarea`)
|
2018-04-09 18:30:15 -07:00
|
|
|
}
|
|
|
|
|
2018-03-30 01:06:17 -07:00
|
|
|
export function getNthComposeReplyInput (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-input`)
|
2018-03-30 01:06:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthComposeReplyButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-button`)
|
2018-03-30 01:06:17 -07:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:04:35 -07:00
|
|
|
export function getNthPostPrivacyButton (n) {
|
2019-05-27 00:24:47 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-toolbar button:nth-child(4)`)
|
2018-03-30 10:04:35 -07:00
|
|
|
}
|
|
|
|
|
2019-05-27 12:31:35 -07:00
|
|
|
export function getNthStatusPollOption (n, i) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .poll li:nth-child(${i}) input`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusPollVoteButton (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .poll button`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusPollForm (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .poll form`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusPollResult (n, i) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .poll li:nth-child(${i})`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusPollRefreshButton (n) {
|
2019-09-15 16:33:44 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .poll-stat button`)
|
2019-05-27 12:31:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusPollVoteCount (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .poll .poll-stat:nth-child(1) .poll-stat-text`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getComposePollNthInput (n) {
|
|
|
|
return $(`.compose-poll input[type="text"]:nth-of-type(${n})`)
|
|
|
|
}
|
|
|
|
|
2019-07-19 20:08:17 -07:00
|
|
|
export function getComposePollNthInputInDialog (n) {
|
|
|
|
return $(`.modal-dialog .compose-poll input[type="text"]:nth-of-type(${n})`)
|
|
|
|
}
|
|
|
|
|
2019-05-27 12:31:35 -07:00
|
|
|
export function getComposePollRemoveNthButton (n) {
|
|
|
|
return $(`.compose-poll button:nth-of-type(${n})`)
|
|
|
|
}
|
|
|
|
|
2018-03-25 12:24:38 -07:00
|
|
|
export function getNthAutosuggestionResult (n) {
|
2019-05-05 22:08:54 -07:00
|
|
|
return $(`.compose-autosuggest-list-item:nth-child(${n})`)
|
2018-03-25 12:24:38 -07:00
|
|
|
}
|
|
|
|
|
2018-04-28 14:19:39 -07:00
|
|
|
export function getSearchResultByHref (href) {
|
|
|
|
return $(`.search-result a[href="${href}"]`)
|
|
|
|
}
|
|
|
|
|
2018-03-08 18:08:14 -08:00
|
|
|
export function getNthSearchResult (n) {
|
|
|
|
return $(`.search-result:nth-child(${n}) a`)
|
|
|
|
}
|
|
|
|
|
2019-07-07 00:14:19 -07:00
|
|
|
export function getNthMediaListItem (n) {
|
|
|
|
return $(`.compose-media:nth-child(${n})`)
|
|
|
|
}
|
|
|
|
|
2018-03-02 21:55:04 -08:00
|
|
|
export function getNthMedia (n) {
|
|
|
|
return $(`.compose-media:nth-child(${n}) img`)
|
|
|
|
}
|
2018-03-02 17:54:38 -08:00
|
|
|
|
2018-03-03 10:27:14 -08:00
|
|
|
export function getNthDeleteMediaButton (n) {
|
|
|
|
return $(`.compose-media:nth-child(${n}) .compose-media-delete-button`)
|
|
|
|
}
|
|
|
|
|
2019-07-07 00:14:19 -07:00
|
|
|
export function getNthMediaFocalPointButton (n) {
|
|
|
|
return $(`.compose-media:nth-child(${n}) .compose-media-focal-button`)
|
|
|
|
}
|
|
|
|
|
2018-12-11 22:06:50 -08:00
|
|
|
export function getAriaSetSize () {
|
2019-02-28 08:56:25 -08:00
|
|
|
return getNthStatus(1 + 0).getAttribute('aria-setsize')
|
2018-12-11 22:06:50 -08:00
|
|
|
}
|
|
|
|
|
2018-02-20 21:08:26 -08:00
|
|
|
export function getNthStatus (n) {
|
2018-04-17 09:44:28 -07:00
|
|
|
return $(getNthStatusSelector(n))
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusSelector (n) {
|
2018-06-10 19:49:39 -07:00
|
|
|
return `.list-item > article[aria-posinset="${n}"]`
|
2018-02-20 21:08:26 -08:00
|
|
|
}
|
|
|
|
|
2018-05-26 13:51:41 -07:00
|
|
|
export function getNthStatusContent (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-content`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusSpoiler (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-spoiler`)
|
|
|
|
}
|
|
|
|
|
2018-12-01 14:09:08 -08:00
|
|
|
export function getNthStatusSensitiveMediaButton (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-sensitive-media-button`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusMedia (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-media`)
|
|
|
|
}
|
|
|
|
|
2019-03-23 18:16:06 -07:00
|
|
|
export function getNthStatusMediaButton (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-media button`)
|
|
|
|
}
|
|
|
|
|
2018-12-12 23:45:42 -08:00
|
|
|
export function getNthStatusRelativeDate (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-relative-date`)
|
|
|
|
}
|
|
|
|
|
2018-12-03 23:23:29 -08:00
|
|
|
export function getNthStatusMediaImg (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-media img`)
|
|
|
|
}
|
|
|
|
|
2018-05-26 13:51:41 -07:00
|
|
|
export function getNthStatusHeader (n) {
|
|
|
|
return $(`${getNthStatusSelector(n)} .status-header`)
|
|
|
|
}
|
|
|
|
|
2018-04-09 18:30:15 -07:00
|
|
|
export function getNthStatusAndImage (nStatus, nImage) {
|
2019-07-07 00:14:19 -07:00
|
|
|
return $(`${getNthStatusSelector(nStatus)} .status-media .show-image-button:nth-child(${nImage}) img`)
|
2018-04-09 18:30:15 -07:00
|
|
|
}
|
|
|
|
|
2019-09-15 10:45:46 -07:00
|
|
|
export function getNthStatusAndSensitiveButton (nStatus, nImage) {
|
|
|
|
return $(`${getNthStatusSelector(nStatus)} .status-sensitive-media-button:nth-child(${nImage})`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthStatusAndSensitiveImage (nStatus, nImage) {
|
|
|
|
return $(`${getNthStatusSelector(nStatus)} .status-media button:nth-child(${nImage}) img`)
|
|
|
|
}
|
|
|
|
|
2018-02-24 14:49:28 -08:00
|
|
|
export function getFirstVisibleStatus () {
|
2019-08-19 19:08:59 -07:00
|
|
|
return $('.list-item > article[aria-posinset]').nth(0)
|
2018-02-24 14:49:28 -08:00
|
|
|
}
|
|
|
|
|
2018-03-09 08:45:12 -08:00
|
|
|
export function getNthReplyButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(1)`)
|
2018-03-09 08:45:12 -08:00
|
|
|
}
|
|
|
|
|
2018-04-08 13:42:31 -07:00
|
|
|
export function getNthReplyContentWarningInput (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .content-warning-input`)
|
2018-04-08 13:42:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthReplyContentWarningButton (n) {
|
2019-05-27 00:24:47 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-toolbar button:nth-child(5)`)
|
2018-04-08 13:42:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthReplyPostPrivacyButton (n) {
|
2019-05-27 00:24:47 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .compose-box-toolbar button:nth-child(4)`)
|
2018-04-08 13:42:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthPostPrivacyOptionInDialog (n) {
|
|
|
|
return $(`.generic-dialog-list li:nth-child(${n}) button`)
|
|
|
|
}
|
|
|
|
|
2018-02-24 14:49:28 -08:00
|
|
|
export function getNthFavoriteButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(3)`)
|
2018-02-24 14:49:28 -08:00
|
|
|
}
|
|
|
|
|
2018-04-14 18:47:55 -07:00
|
|
|
export function getNthStatusOptionsButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(4)`)
|
2018-04-14 18:47:55 -07:00
|
|
|
}
|
|
|
|
|
2019-11-17 21:23:32 -05:00
|
|
|
export function getNthFavoritedLabel (n) {
|
|
|
|
return getNthFavoriteButton(n).getAttribute('aria-label')
|
2018-02-24 14:49:28 -08:00
|
|
|
}
|
|
|
|
|
2018-04-11 22:55:11 -07:00
|
|
|
export function getNthShowOrHideButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-spoiler-button button`)
|
2018-04-11 22:55:11 -07:00
|
|
|
}
|
|
|
|
|
2018-02-24 14:49:28 -08:00
|
|
|
export function getFavoritesCount () {
|
|
|
|
return favoritesCountElement.innerCount
|
|
|
|
}
|
|
|
|
|
2018-02-24 18:20:33 -08:00
|
|
|
export function getNthReblogButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthStatusSelector(n)} .status-toolbar button:nth-child(2)`)
|
2018-02-24 18:20:33 -08:00
|
|
|
}
|
|
|
|
|
2019-11-17 21:23:32 -05:00
|
|
|
export function getNthRebloggedLabel (n) {
|
|
|
|
return getNthReblogButton(n).getAttribute('aria-label')
|
2018-02-24 18:20:33 -08:00
|
|
|
}
|
|
|
|
|
2018-04-14 18:47:55 -07:00
|
|
|
export function getNthDialogOptionsOption (n) {
|
|
|
|
return $(`.modal-dialog li:nth-child(${n}) button`)
|
|
|
|
}
|
|
|
|
|
2018-02-24 14:49:28 -08:00
|
|
|
export function getReblogsCount () {
|
|
|
|
return reblogsCountElement.innerCount
|
2018-02-19 17:04:37 -08:00
|
|
|
}
|
|
|
|
|
2018-06-08 21:54:11 -07:00
|
|
|
function getNthPinnedStatusSelector (n) {
|
|
|
|
return `.pinned-statuses article[aria-posinset="${n}"]`
|
|
|
|
}
|
|
|
|
|
2018-04-29 12:28:44 -07:00
|
|
|
export function getNthPinnedStatus (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(getNthPinnedStatusSelector(n))
|
2018-04-29 12:28:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNthPinnedStatusFavoriteButton (n) {
|
2018-06-08 21:54:11 -07:00
|
|
|
return $(`${getNthPinnedStatusSelector(n)} .status-toolbar button:nth-child(3)`)
|
2018-04-29 12:28:44 -07:00
|
|
|
}
|
|
|
|
|
2018-02-19 18:25:59 -08:00
|
|
|
export async function validateTimeline (t, timeline) {
|
2018-05-26 13:51:41 -07:00
|
|
|
const timeout = 30000
|
2018-02-19 17:04:37 -08:00
|
|
|
for (let i = 0; i < timeline.length; i++) {
|
2019-08-03 13:49:37 -07:00
|
|
|
const status = timeline[i]
|
2018-05-26 13:51:41 -07:00
|
|
|
// hovering forces TestCafé to scroll to that element: https://git.io/vABV2
|
2019-02-28 08:56:25 -08:00
|
|
|
await t.hover(getNthStatus(1 + i))
|
2018-02-19 17:04:37 -08:00
|
|
|
if (status.content) {
|
2019-02-28 08:56:25 -08:00
|
|
|
await t.expect(getNthStatusContent(1 + i).innerText)
|
2018-05-24 20:01:34 -07:00
|
|
|
.contains(status.content, { timeout })
|
2018-02-19 17:04:37 -08:00
|
|
|
}
|
|
|
|
if (status.spoiler) {
|
2019-02-28 08:56:25 -08:00
|
|
|
await t.expect(getNthStatusSpoiler(1 + i).innerText)
|
2018-05-24 20:01:34 -07:00
|
|
|
.contains(status.spoiler, { timeout })
|
2018-02-19 17:04:37 -08:00
|
|
|
}
|
|
|
|
if (status.followedBy) {
|
2019-02-28 08:56:25 -08:00
|
|
|
await t.expect(getNthStatusHeader(1 + i).innerText)
|
2018-06-09 15:04:47 -07:00
|
|
|
.match(new RegExp(status.followedBy + '\\s+followed you'), { timeout })
|
2018-02-19 17:04:37 -08:00
|
|
|
}
|
|
|
|
if (status.rebloggedBy) {
|
2019-02-28 08:56:25 -08:00
|
|
|
await t.expect(getNthStatusHeader(1 + i).innerText)
|
2018-06-09 15:04:47 -07:00
|
|
|
.match(new RegExp(status.rebloggedBy + '\\s+boosted your status'), { timeout })
|
2018-02-19 17:04:37 -08:00
|
|
|
}
|
|
|
|
if (status.favoritedBy) {
|
2019-02-28 08:56:25 -08:00
|
|
|
await t.expect(getNthStatusHeader(1 + i).innerText)
|
2018-06-09 15:04:47 -07:00
|
|
|
.match(new RegExp(status.favoritedBy + '\\s+favorited your status'), { timeout })
|
2018-02-19 17:04:37 -08:00
|
|
|
}
|
|
|
|
}
|
2018-02-19 18:25:59 -08:00
|
|
|
}
|
2018-02-20 21:08:26 -08:00
|
|
|
|
2018-02-21 09:26:22 -08:00
|
|
|
export async function scrollToStatus (t, n) {
|
2019-05-28 22:46:01 -07:00
|
|
|
return scrollFromStatusToStatus(t, 1, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function scrollFromStatusToStatus (t, start, end) {
|
2019-08-03 13:49:37 -07:00
|
|
|
const timeout = 20000
|
2019-05-28 22:46:01 -07:00
|
|
|
for (let i = start; i < end; i++) {
|
2018-08-29 21:42:57 -07:00
|
|
|
await t.expect(getNthStatus(i).exists).ok({ timeout })
|
2018-05-24 20:01:34 -07:00
|
|
|
.hover(getNthStatus(i))
|
2019-02-28 08:56:25 -08:00
|
|
|
.expect($(`${getNthStatusSelector(i)} .status-toolbar`).exists).ok({ timeout })
|
|
|
|
.hover($(`${getNthStatusSelector(i)} .status-toolbar`))
|
2018-02-21 09:26:22 -08:00
|
|
|
}
|
2019-05-28 22:46:01 -07:00
|
|
|
await t
|
|
|
|
.expect(getNthStatus(end).exists).ok({ timeout })
|
|
|
|
.hover(getNthStatus(end))
|
2018-02-21 09:26:22 -08:00
|
|
|
}
|
2018-03-10 20:24:07 -08: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-18 20:43:13 -07: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) {
|
2019-08-03 13:49:37 -07:00
|
|
|
const arr = []
|
2018-04-18 20:43:13 -07:00
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
arr.push(cb(i))
|
|
|
|
}
|
|
|
|
return arr
|
|
|
|
}
|