1 import { AdminConfigPage } from '../po/admin-config.po'
2 import { LoginPage } from '../po/login.po'
3 import { MyAccountPage } from '../po/my-account.po'
4 import { VideoListPage } from '../po/video-list.po'
5 import { VideoSearchPage } from '../po/video-search.po'
6 import { VideoUploadPage } from '../po/video-upload.po'
7 import { VideoWatchPage } from '../po/video-watch.po'
8 import { NSFWPolicy } from '../types/common'
9 import { isMobileDevice, isSafari, waitServerUp } from '../utils'
11 describe('Videos list', () => {
12 let videoListPage: VideoListPage
13 let videoUploadPage: VideoUploadPage
14 let adminConfigPage: AdminConfigPage
15 let loginPage: LoginPage
16 let myAccountPage: MyAccountPage
17 let videoSearchPage: VideoSearchPage
18 let videoWatchPage: VideoWatchPage
20 const seed = Math.random()
21 const nsfwVideo = seed + ' - nsfw'
22 const normalVideo = seed + ' - normal'
24 async function checkNormalVideo () {
25 expect(await videoListPage.videoExists(normalVideo)).toBeTruthy()
26 expect(await videoListPage.videoIsBlurred(normalVideo)).toBeFalsy()
29 async function checkNSFWVideo (policy: NSFWPolicy, filterText?: string) {
30 if (policy === 'do_not_list') {
31 if (filterText) expect(filterText).toContain('hidden')
33 expect(await videoListPage.videoExists(nsfwVideo)).toBeFalsy()
37 if (policy === 'blur') {
38 if (filterText) expect(filterText).toContain('blurred')
40 expect(await videoListPage.videoExists(nsfwVideo)).toBeTruthy()
41 expect(await videoListPage.videoIsBlurred(nsfwVideo)).toBeTruthy()
46 if (filterText) expect(filterText).toContain('displayed')
48 expect(await videoListPage.videoExists(nsfwVideo)).toBeTruthy()
49 expect(await videoListPage.videoIsBlurred(nsfwVideo)).toBeFalsy()
52 async function checkCommonVideoListPages (policy: NSFWPolicy) {
53 const promisesWithFilters = [
54 videoListPage.goOnRootAccount,
55 videoListPage.goOnLocal,
56 videoListPage.goOnRecentlyAdded,
57 videoListPage.goOnTrending,
58 videoListPage.goOnRootChannel
61 for (const p of promisesWithFilters) {
62 await p.call(videoListPage)
64 const filter = await videoListPage.getNSFWFilter()
65 const filterText = await filter.getText()
67 await checkNormalVideo()
68 await checkNSFWVideo(policy, filterText)
71 const promisesWithoutFilters = [
72 videoListPage.goOnRootAccountChannels,
73 videoListPage.goOnHomepage
75 for (const p of promisesWithoutFilters) {
76 await p.call(videoListPage)
78 await checkNormalVideo()
79 await checkNSFWVideo(policy)
83 async function checkSearchPage (policy: NSFWPolicy) {
84 await videoSearchPage.search(normalVideo)
85 await checkNormalVideo()
87 await videoSearchPage.search(nsfwVideo)
88 await checkNSFWVideo(policy)
91 async function updateAdminNSFW (nsfw: NSFWPolicy) {
92 await adminConfigPage.navigateTo('instance-information')
93 await adminConfigPage.updateNSFWSetting(nsfw)
94 await adminConfigPage.save()
97 async function updateUserNSFW (nsfw: NSFWPolicy) {
98 await myAccountPage.navigateToMySettings()
99 await myAccountPage.updateNSFW(nsfw)
106 beforeEach(async () => {
107 videoListPage = new VideoListPage(isMobileDevice(), isSafari())
108 adminConfigPage = new AdminConfigPage()
109 loginPage = new LoginPage(isMobileDevice())
110 videoUploadPage = new VideoUploadPage()
111 myAccountPage = new MyAccountPage()
112 videoSearchPage = new VideoSearchPage()
113 videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari())
115 await browser.maximizeWindow()
118 it('Should login and disable NSFW', async () => {
119 await loginPage.loginAsRootUser()
120 await updateUserNSFW('display')
123 it('Should set the homepage', async () => {
124 await adminConfigPage.navigateTo('instance-homepage')
125 await adminConfigPage.updateHomepage('<peertube-videos-list data-sort="-publishedAt"></peertube-videos-list>')
126 await adminConfigPage.save()
129 it('Should upload 2 videos (NSFW and classic videos)', async () => {
130 await videoUploadPage.navigateTo()
131 await videoUploadPage.uploadVideo('video.mp4')
132 await videoUploadPage.setAsNSFW()
133 await videoUploadPage.validSecondUploadStep(nsfwVideo)
135 await videoUploadPage.navigateTo()
136 await videoUploadPage.uploadVideo('video2.mp4')
137 await videoUploadPage.validSecondUploadStep(normalVideo)
140 it('Should logout', async function () {
141 await loginPage.logout()
144 describe('Anonymous users', function () {
146 it('Should correctly handle do not list', async () => {
147 await loginPage.loginAsRootUser()
148 await updateAdminNSFW('do_not_list')
150 await loginPage.logout()
151 await checkCommonVideoListPages('do_not_list')
152 await checkSearchPage('do_not_list')
155 it('Should correctly handle blur', async () => {
156 await loginPage.loginAsRootUser()
157 await updateAdminNSFW('blur')
159 await loginPage.logout()
160 await checkCommonVideoListPages('blur')
161 await checkSearchPage('blur')
164 it('Should correctly handle display', async () => {
165 await loginPage.loginAsRootUser()
166 await updateAdminNSFW('display')
168 await loginPage.logout()
169 await checkCommonVideoListPages('display')
170 await checkSearchPage('display')
174 describe('Logged in users', function () {
177 await loginPage.loginAsRootUser()
180 it('Should correctly handle do not list', async () => {
181 await updateUserNSFW('do_not_list')
182 await checkCommonVideoListPages('do_not_list')
183 await checkSearchPage('do_not_list')
186 it('Should correctly handle blur', async () => {
187 await updateUserNSFW('blur')
188 await checkCommonVideoListPages('blur')
189 await checkSearchPage('blur')
192 it('Should correctly handle display', async () => {
193 await updateUserNSFW('display')
194 await checkCommonVideoListPages('display')
195 await checkSearchPage('display')
199 await loginPage.logout()
203 describe('Default upload values', function () {
205 it('Should have default video values', async function () {
206 await loginPage.loginAsRootUser()
207 await videoUploadPage.navigateTo()
208 await videoUploadPage.uploadVideo('video3.mp4')
209 await videoUploadPage.validSecondUploadStep('video')
211 await videoWatchPage.waitWatchVideoName('video')
213 expect(await videoWatchPage.getPrivacy()).toBe('Public')
214 expect(await videoWatchPage.getLicence()).toBe('Unknown')
215 expect(await videoWatchPage.isDownloadEnabled()).toBeTruthy()
216 expect(await videoWatchPage.areCommentsEnabled()).toBeTruthy()