]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/po/video-watch.po.ts
Fix hls redundancy pruning
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
CommitLineData
12d6b873 1import { FIXTURE_URLS } from '../urls'
3419e0e1 2import { browserSleep, go } from '../utils'
5f92c4dc
C
3
4export class VideoWatchPage {
1fad099d 5 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
0b33c520
C
6 let url: string
7
1fad099d
C
8 // We did not upload a file on a mobile device
9 if (isMobileDevice === true || isSafari === true) {
0b33c520
C
10 url = 'https://peertube2.cpy.re/videos/local'
11 } else {
12 url = '/videos/recently-added'
13 }
5f92c4dc 14
3419e0e1 15 await go(url)
d1bd87e0
C
16
17 // Waiting the following element does not work on Safari...
ee68bbc4 18 if (isSafari) return browserSleep(3000)
d1bd87e0 19
3419e0e1 20 await $('.videos .video-miniature .video-miniature-name').waitForDisplayed()
5f92c4dc
C
21 }
22
3419e0e1
C
23 async getVideosListName () {
24 const elems = await $$('.videos .video-miniature .video-miniature-name')
25 const texts = await Promise.all(elems.map(e => e.getText()))
26
27 return texts.map(t => t.trim())
5f92c4dc
C
28 }
29
6247b205 30 waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
ee68bbc4
C
31 if (isSafari) return browserSleep(5000)
32
6247b205
C
33 // On mobile we display the first node, on desktop the second
34 const index = isMobileDevice ? 0 : 1
35
3419e0e1
C
36 return browser.waitUntil(async () => {
37 return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName)
38 })
5f92c4dc
C
39 }
40
e69cb173 41 getVideoName () {
3419e0e1 42 return this.getVideoNameElement().then(e => e.getText())
e69cb173
C
43 }
44
7f90579c 45 async goOnAssociatedEmbed () {
3419e0e1 46 let url = await browser.getUrl()
18305950 47 url = url.replace('/w/', '/videos/embed/')
7f90579c 48 url = url.replace(':3333', ':9001')
ee68bbc4 49
3419e0e1 50 return go(url)
7f90579c 51 }
91d95589 52
3419e0e1 53 goOnP2PMediaLoaderEmbed () {
12d6b873 54 return go(FIXTURE_URLS.HLS_EMBED)
7f90579c 55 }
cd4d7a2c 56
3419e0e1 57 goOnP2PMediaLoaderPlaylistEmbed () {
12d6b873 58 return go(FIXTURE_URLS.HLS_PLAYLIST_EMBED)
5f92c4dc
C
59 }
60
cd4d7a2c 61 async clickOnVideo (videoName: string) {
3419e0e1
C
62 const video = async () => {
63 const videos = await $$('.videos .video-miniature .video-miniature-name').filter(async e => {
64 const t = await e.getText()
65
66 return t === videoName
67 })
68
69 return videos[0]
70 }
71
72 await browser.waitUntil(async () => {
73 const elem = await video()
3cf198e4 74
3419e0e1
C
75 return elem?.isClickable()
76 });
0b33c520 77
3419e0e1
C
78 (await video()).click()
79
80 await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
0b33c520
C
81 }
82
83 async clickOnFirstVideo () {
3419e0e1
C
84 const video = () => $('.videos .video-miniature .video-thumbnail')
85 const videoName = () => $('.videos .video-miniature .video-miniature-name')
86
87 await video().waitForClickable()
1fad099d 88
3419e0e1
C
89 const textToReturn = await videoName().getText()
90 await video().click()
5f92c4dc 91
3419e0e1 92 await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
5f92c4dc 93
0b33c520 94 return textToReturn
5f92c4dc
C
95 }
96
e69cb173 97 async clickOnUpdate () {
3419e0e1 98 const dropdown = $('my-video-actions-dropdown .action-button')
e69cb173
C
99 await dropdown.click()
100
3419e0e1
C
101 await $('.dropdown-menu.show .dropdown-item').waitForDisplayed()
102 const items = await $$('.dropdown-menu.show .dropdown-item')
e69cb173
C
103
104 for (const item of items) {
105 const href = await item.getAttribute('href')
106
3419e0e1 107 if (href?.includes('/update/')) {
e69cb173
C
108 await item.click()
109 return
110 }
111 }
112 }
113
3419e0e1
C
114 clickOnSave () {
115 return $('.action-button-save').click()
e69cb173
C
116 }
117
bbe078ba 118 async createPlaylist (name: string) {
3419e0e1
C
119 const newPlaylistButton = () => $('.new-playlist-button')
120
121 await newPlaylistButton().waitForClickable()
122 await newPlaylistButton().click()
123
124 const displayName = () => $('#displayName')
bbe078ba 125
3419e0e1
C
126 await displayName().waitForDisplayed()
127 await displayName().setValue(name)
bbe078ba 128
3419e0e1 129 return $('.new-playlist-block input[type=submit]').click()
bbe078ba
C
130 }
131
132 async saveToPlaylist (name: string) {
3419e0e1
C
133 const playlist = () => $('my-video-add-to-playlist').$(`.playlist=${name}`)
134
135 await playlist().waitForDisplayed()
136
137 return playlist().click()
e69cb173
C
138 }
139
140 waitUntilVideoName (name: string, maxTime: number) {
3419e0e1
C
141 return browser.waitUntil(async () => {
142 return (await this.getVideoName()) === name
143 }, { timeout: maxTime })
e69cb173
C
144 }
145
3419e0e1 146 private async getVideoNameElement () {
e69cb173 147 // We have 2 video info name block, pick the first that is not empty
3419e0e1
C
148 const elem = async () => {
149 const elems = await $$('.video-info-first-row .video-info-name').filter(e => e.isDisplayed())
150
151 return elems[0]
152 }
153
154 await browser.waitUntil(async () => {
155 const e = await elem()
156
157 return e?.isDisplayed()
158 })
159
160 return elem()
e69cb173 161 }
5f92c4dc 162}