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(false) // Avoid issues with fixed header on firefox
28 await nsfw.selectByAttribute('value', newValue)
30 await this.submitVideoSettings()
33 async clickOnP2PCheckbox () {
34 const p2p = await getCheckbox('p2pEnabled')
36 await p2p.waitForClickable()
37 await p2p.scrollIntoView(false) // Avoid issues with fixed header on firefox
41 await this.submitVideoSettings()
44 private async submitVideoSettings () {
45 const submit = $('my-user-video-settings input[type=submit]')
46 await submit.scrollIntoView(false)
52 async removeVideo (name: string) {
53 const container = await this.getVideoElement(name)
55 await container.$('.dropdown-toggle').click()
57 const dropdownMenu = () => container.$$('.dropdown-menu .dropdown-item')[1]
59 await dropdownMenu().waitForDisplayed()
60 return dropdownMenu().click()
64 return $('input[type=submit]').click()
67 async countVideos (names: string[]) {
68 const elements = await $$('.video').filter(async e => {
69 const t = await e.$('.video-miniature-name').getText()
71 return names.some(n => t.includes(n))
74 return elements.length
77 // My account playlists
79 async getPlaylistVideosText (name: string) {
80 const elem = await this.getPlaylist(name)
82 return elem.$('.miniature-playlist-info-overlay').getText()
85 async clickOnPlaylist (name: string) {
86 const elem = await this.getPlaylist(name)
88 return elem.$('.miniature-thumbnail').click()
91 async countTotalPlaylistElements () {
92 await $('<my-video-playlist-element-miniature>').waitForDisplayed()
94 return $$('<my-video-playlist-element-miniature>').length
98 return $('.playlist-info .miniature-thumbnail').click()
101 async goOnAssociatedPlaylistEmbed () {
102 let url = await browser.getUrl()
103 url = url.replace('/w/p/', '/video-playlists/embed/')
104 url = url.replace(':3333', ':9001')
111 private async getVideoElement (name: string) {
112 const video = async () => {
113 const videos = await $$('.video').filter(async e => {
114 const t = await e.$('.video-miniature-name').getText()
116 return t.includes(name)
122 await browser.waitUntil(async () => {
123 return (await video()).isDisplayed()
129 // My account playlists
131 private async getPlaylist (name: string) {
132 const playlist = () => {
133 return $$('my-video-playlist-miniature')
135 const t = await e.$('.miniature-name').getText()
137 return t.includes(name)
139 .then(elems => elems[0])
142 await browser.waitUntil(async () => {
143 const el = await playlist()
145 return el?.isDisplayed()