aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/po/video-list.po.ts
blob: f62c79adcb9456339bfe4961ef2f99d10c2720ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { browserSleep, go } from '../utils'

export class VideoListPage {

  constructor (private isMobileDevice: boolean, private isSafari: boolean) {

  }

  async goOnVideosList () {
    let url: string

    // We did not upload a file on a mobile device
    if (this.isMobileDevice === true || this.isSafari === true) {
      url = 'https://peertube2.cpy.re/videos/local'
    } else {
      url = '/videos/recently-added'
    }

    await go(url)

    // Waiting the following element does not work on Safari...
    if (this.isSafari) return browserSleep(3000)

    await this.waitForList()
  }

  async goOnLocal () {
    await $('.menu-link[href="/videos/local"]').click()
    await this.waitForTitle('Local videos')
  }

  async goOnRecentlyAdded () {
    await $('.menu-link[href="/videos/recently-added"]').click()
    await this.waitForTitle('Recently added')
  }

  async goOnTrending () {
    await $('.menu-link[href="/videos/trending"]').click()
    await this.waitForTitle('Trending')
  }

  async goOnHomepage () {
    await go('/home')
    await this.waitForList()
  }

  async goOnRootChannel () {
    await go('/c/root_channel/videos')
    await this.waitForList()
  }

  async goOnRootAccount () {
    await go('/a/root/videos')
    await this.waitForList()
  }

  async goOnRootAccountChannels () {
    await go('/a/root/video-channels')
    await this.waitForList()
  }

  getNSFWFilter () {
    return $$('.active-filter').filter(async a => {
      return (await a.getText()).includes('Sensitive')
    }).then(f => f[0])
  }

  async getVideosListName () {
    const elems = await $$('.videos .video-miniature .video-miniature-name')
    const texts = await Promise.all(elems.map(e => e.getText()))

    return texts.map(t => t.trim())
  }

  videoExists (name: string) {
    return $('.video-miniature-name=' + name).isDisplayed()
  }

  async videoIsBlurred (name: string) {
    const filter = await $('.video-miniature-name=' + name).getCSSProperty('filter')

    return filter.value !== 'none'
  }

  async clickOnVideo (videoName: string) {
    const video = async () => {
      const videos = await $$('.videos .video-miniature .video-miniature-name').filter(async e => {
        const t = await e.getText()

        return t === videoName
      })

      return videos[0]
    }

    await browser.waitUntil(async () => {
      const elem = await video()

      return elem?.isClickable()
    });

    (await video()).click()

    await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
  }

  async clickOnFirstVideo () {
    const video = () => $('.videos .video-miniature .video-thumbnail')
    const videoName = () => $('.videos .video-miniature .video-miniature-name')

    await video().waitForClickable()

    const textToReturn = await videoName().getText()
    await video().click()

    await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))

    return textToReturn
  }

  private waitForList () {
    return $('.videos .video-miniature .video-miniature-name').waitForDisplayed()
  }

  private waitForTitle (title: string) {
    return $('h1=' + title).waitForDisplayed()
  }
}