1 import { getCheckbox, go } from '../utils'
3 export class MyAccountPage {
5 navigateToMyVideos () {
6 return $('a[href="/my-library/videos"]').click()
9 navigateToMyPlaylists () {
10 return $('a[href="/my-library/video-playlists"]').click()
13 navigateToMyHistory () {
14 return $('a[href="/my-library/history/videos"]').click()
19 navigateToMySettings () {
20 return $('a[href="/my-account"]').click()
23 async updateNSFW (newValue: 'do_not_list' | 'blur' | 'display') {
24 const nsfw = $('#nsfwPolicy')
26 await nsfw.waitForDisplayed()
27 await nsfw.scrollIntoView({ block: 'center' }) // Avoid issues with fixed header
28 await nsfw.waitForClickable()
30 await nsfw.selectByAttribute('value', newValue)
32 await this.submitVideoSettings()
35 async clickOnP2PCheckbox () {
36 const p2p = await getCheckbox('p2pEnabled')
38 await p2p.waitForClickable()
39 await p2p.scrollIntoView({ block: 'center' }) // Avoid issues with fixed header
43 await this.submitVideoSettings()
46 private async submitVideoSettings () {
47 const submit = $('my-user-video-settings input[type=submit]')
49 await submit.waitForClickable()
50 await submit.scrollIntoView({ block: 'center' }) // Avoid issues with fixed header
56 async removeVideo (name: string) {
57 const container = await this.getVideoElement(name)
59 await container.$('.dropdown-toggle').click()
61 const deleteItem = () => {
62 return $$('.dropdown-menu .dropdown-item').find<WebdriverIO.Element>(async v => {
63 const text = await v.getText()
65 return text.includes('Delete')
69 await (await deleteItem()).waitForClickable()
71 return (await deleteItem()).click()
75 return $('input[type=submit]').click()
78 async countVideos (names: string[]) {
79 const elements = await $$('.video').filter(async e => {
80 const t = await e.$('.video-miniature-name').getText()
82 return names.some(n => t.includes(n))
85 return elements.length
88 // My account playlists
90 async getPlaylistVideosText (name: string) {
91 const elem = await this.getPlaylist(name)
93 return elem.$('.miniature-playlist-info-overlay').getText()
96 async clickOnPlaylist (name: string) {
97 const elem = await this.getPlaylist(name)
99 return elem.$('.miniature-thumbnail').click()
102 async countTotalPlaylistElements () {
103 await $('<my-video-playlist-element-miniature>').waitForDisplayed()
105 return $$('<my-video-playlist-element-miniature>').length
109 return $('.playlist-info .miniature-thumbnail').click()
112 async goOnAssociatedPlaylistEmbed () {
113 let url = await browser.getUrl()
114 url = url.replace('/w/p/', '/video-playlists/embed/')
115 url = url.replace(':3333', ':9001')
122 private async getVideoElement (name: string) {
123 const video = async () => {
124 const videos = await $$('.video').filter(async e => {
125 const t = await e.$('.video-miniature-name').getText()
127 return t.includes(name)
133 await browser.waitUntil(async () => {
134 return (await video()).isDisplayed()
140 // My account playlists
142 private async getPlaylist (name: string) {
143 const playlist = () => {
144 return $$('my-video-playlist-miniature')
146 const t = await e.$('.miniature-name').getText()
148 return t.includes(name)
150 .then(elems => elems[0])
153 await browser.waitUntil(async () => {
154 const el = await playlist()
156 return el?.isDisplayed()