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