]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/my-account.po.ts
Fix local e2e tests
[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({ block: 'center' }) // Avoid issues with fixed header
28 await nsfw.waitForClickable()
29
30 await nsfw.selectByAttribute('value', newValue)
31
32 await this.submitVideoSettings()
33 }
34
35 async clickOnP2PCheckbox () {
36 const p2p = await getCheckbox('p2pEnabled')
37
38 await p2p.waitForClickable()
39 await p2p.scrollIntoView({ block: 'center' }) // Avoid issues with fixed header
40
41 await p2p.click()
42
43 await this.submitVideoSettings()
44 }
45
46 private async submitVideoSettings () {
47 const submit = $('my-user-video-settings input[type=submit]')
48
49 await submit.waitForClickable()
50 await submit.scrollIntoView({ block: 'center' }) // Avoid issues with fixed header
51 await submit.click()
52 }
53
54 // My account Videos
55
56 async removeVideo (name: string) {
57 const container = await this.getVideoElement(name)
58
59 await container.$('.dropdown-toggle').click()
60
61 const deleteItem = () => {
62 return $$('.dropdown-menu .dropdown-item').find<WebdriverIO.Element>(async v => {
63 const text = await v.getText()
64
65 return text.includes('Delete')
66 })
67 }
68
69 await (await deleteItem()).waitForClickable()
70
71 return (await deleteItem()).click()
72 }
73
74 validRemove () {
75 return $('input[type=submit]').click()
76 }
77
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
86 }
87
88 // My account playlists
89
90 async getPlaylistVideosText (name: string) {
91 const elem = await this.getPlaylist(name)
92
93 return elem.$('.miniature-playlist-info-overlay').getText()
94 }
95
96 async clickOnPlaylist (name: string) {
97 const elem = await this.getPlaylist(name)
98
99 return elem.$('.miniature-thumbnail').click()
100 }
101
102 async countTotalPlaylistElements () {
103 await $('<my-video-playlist-element-miniature>').waitForDisplayed()
104
105 return $$('<my-video-playlist-element-miniature>').length
106 }
107
108 playPlaylist () {
109 return $('.playlist-info .miniature-thumbnail').click()
110 }
111
112 async goOnAssociatedPlaylistEmbed () {
113 let url = await browser.getUrl()
114 url = url.replace('/w/p/', '/video-playlists/embed/')
115 url = url.replace(':3333', ':9001')
116
117 return go(url)
118 }
119
120 // My account Videos
121
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()
138 }
139
140 // My account playlists
141
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()
160 }
161 }