]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/my-account.po.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / my-account.po.ts
1 import { getCheckbox, go } from '../utils'
2
3 export class MyAccountPage {
4
5 navigateToMyVideos () {
6 return $('a[href="/my-library/videos"]').click()
7 }
8
9 navigateToMyPlaylists () {
10 return $('a[href="/my-library/video-playlists"]').click()
11 }
12
13 navigateToMyHistory () {
14 return $('a[href="/my-library/history/videos"]').click()
15 }
16
17 // Settings
18
19 navigateToMySettings () {
20 return $('a[href="/my-account"]').click()
21 }
22
23 async updateNSFW (newValue: 'do_not_list' | 'blur' | 'display') {
24 const nsfw = $('#nsfwPolicy')
25
26 await nsfw.waitForDisplayed()
27 await nsfw.scrollIntoView(false) // Avoid issues with fixed header on firefox
28 await nsfw.selectByAttribute('value', newValue)
29
30 await this.submitVideoSettings()
31 }
32
33 async clickOnP2PCheckbox () {
34 const p2p = await getCheckbox('p2pEnabled')
35
36 await p2p.waitForClickable()
37 await p2p.scrollIntoView(false) // Avoid issues with fixed header on firefox
38
39 await p2p.click()
40
41 await this.submitVideoSettings()
42 }
43
44 private async submitVideoSettings () {
45 const submit = $('my-user-video-settings input[type=submit]')
46 await submit.scrollIntoView(false)
47 await submit.click()
48 }
49
50 // My account Videos
51
52 async removeVideo (name: string) {
53 const container = await this.getVideoElement(name)
54
55 await container.$('.dropdown-toggle').click()
56
57 const deleteItem = () => {
58 return $$('.dropdown-menu .dropdown-item').find<WebdriverIO.Element>(async v => {
59 const text = await v.getText()
60
61 return text.includes('Delete')
62 })
63 }
64
65 await (await deleteItem()).waitForClickable()
66
67 return (await deleteItem()).click()
68 }
69
70 validRemove () {
71 return $('input[type=submit]').click()
72 }
73
74 async countVideos (names: string[]) {
75 const elements = await $$('.video').filter(async e => {
76 const t = await e.$('.video-miniature-name').getText()
77
78 return names.some(n => t.includes(n))
79 })
80
81 return elements.length
82 }
83
84 // My account playlists
85
86 async getPlaylistVideosText (name: string) {
87 const elem = await this.getPlaylist(name)
88
89 return elem.$('.miniature-playlist-info-overlay').getText()
90 }
91
92 async clickOnPlaylist (name: string) {
93 const elem = await this.getPlaylist(name)
94
95 return elem.$('.miniature-thumbnail').click()
96 }
97
98 async countTotalPlaylistElements () {
99 await $('<my-video-playlist-element-miniature>').waitForDisplayed()
100
101 return $$('<my-video-playlist-element-miniature>').length
102 }
103
104 playPlaylist () {
105 return $('.playlist-info .miniature-thumbnail').click()
106 }
107
108 async goOnAssociatedPlaylistEmbed () {
109 let url = await browser.getUrl()
110 url = url.replace('/w/p/', '/video-playlists/embed/')
111 url = url.replace(':3333', ':9001')
112
113 return go(url)
114 }
115
116 // My account Videos
117
118 private async getVideoElement (name: string) {
119 const video = async () => {
120 const videos = await $$('.video').filter(async e => {
121 const t = await e.$('.video-miniature-name').getText()
122
123 return t.includes(name)
124 })
125
126 return videos[0]
127 }
128
129 await browser.waitUntil(async () => {
130 return (await video()).isDisplayed()
131 })
132
133 return video()
134 }
135
136 // My account playlists
137
138 private async getPlaylist (name: string) {
139 const playlist = () => {
140 return $$('my-video-playlist-miniature')
141 .filter(async e => {
142 const t = await e.$('.miniature-name').getText()
143
144 return t.includes(name)
145 })
146 .then(elems => elems[0])
147 }
148
149 await browser.waitUntil(async () => {
150 const el = await playlist()
151
152 return el?.isDisplayed()
153 })
154
155 return playlist()
156 }
157 }