1 import { AdminConfigPage } from '../po/admin-config.po'
2 import { LoginPage } from '../po/login.po'
3 import { MyAccountPage } from '../po/my-account'
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 { NSFWPolicy } from '../types/common'
8 import { isMobileDevice, isSafari, waitServerUp } from '../utils'
10 describe('Videos list', () => {
11 let videoListPage: VideoListPage
12 let videoUploadPage: VideoUploadPage
13 let adminConfigPage: AdminConfigPage
14 let loginPage: LoginPage
15 let myAccountPage: MyAccountPage
16 let videoSearchPage: VideoSearchPage
18 const seed = Math.random()
19 const nsfwVideo = seed + ' - nsfw'
20 const normalVideo = seed + ' - normal'
22 async function checkNormalVideo () {
23 expect(await videoListPage.videoExists(normalVideo)).toBeTruthy()
24 expect(await videoListPage.videoIsBlurred(normalVideo)).toBeFalsy()
27 async function checkNSFWVideo (policy: NSFWPolicy, filterText?: string) {
28 if (policy === 'do_not_list') {
29 if (filterText) expect(filterText).toContain('hidden')
31 expect(await videoListPage.videoExists(nsfwVideo)).toBeFalsy()
35 if (policy === 'blur') {
36 if (filterText) expect(filterText).toContain('blurred')
38 expect(await videoListPage.videoExists(nsfwVideo)).toBeTruthy()
39 expect(await videoListPage.videoIsBlurred(nsfwVideo)).toBeTruthy()
44 if (filterText) expect(filterText).toContain('displayed')
46 expect(await videoListPage.videoExists(nsfwVideo)).toBeTruthy()
47 expect(await videoListPage.videoIsBlurred(nsfwVideo)).toBeFalsy()
50 async function checkCommonVideoListPages (policy: NSFWPolicy) {
51 const promisesWithFilters = [
52 videoListPage.goOnRootAccount,
53 videoListPage.goOnLocal,
54 videoListPage.goOnRecentlyAdded,
55 videoListPage.goOnTrending,
56 videoListPage.goOnRootChannel
59 for (const p of promisesWithFilters) {
60 await p.call(videoListPage)
62 const filter = await videoListPage.getNSFWFilter()
63 const filterText = await filter.getText()
65 await checkNormalVideo()
66 await checkNSFWVideo(policy, filterText)
69 const promisesWithoutFilters = [
70 videoListPage.goOnRootAccountChannels,
71 videoListPage.goOnHomepage
73 for (const p of promisesWithoutFilters) {
74 await p.call(videoListPage)
76 await checkNormalVideo()
77 await checkNSFWVideo(policy)
81 async function checkSearchPage (policy: NSFWPolicy) {
82 await videoSearchPage.search(normalVideo)
83 await checkNormalVideo()
85 await videoSearchPage.search(nsfwVideo)
86 await checkNSFWVideo(policy)
89 async function updateAdminNSFW (nsfw: NSFWPolicy) {
90 await adminConfigPage.navigateTo('instance-information')
91 await adminConfigPage.updateNSFWSetting(nsfw)
92 await adminConfigPage.save()
95 async function updateUserNSFW (nsfw: NSFWPolicy) {
96 await myAccountPage.navigateToMySettings()
97 await myAccountPage.updateNSFW(nsfw)
104 beforeEach(async () => {
105 videoListPage = new VideoListPage(isMobileDevice(), isSafari())
106 adminConfigPage = new AdminConfigPage()
107 loginPage = new LoginPage()
108 videoUploadPage = new VideoUploadPage()
109 myAccountPage = new MyAccountPage()
110 videoSearchPage = new VideoSearchPage()
112 await browser.maximizeWindow()
115 it('Should login and disable NSFW', async () => {
116 await loginPage.loginAsRootUser()
117 await updateUserNSFW('display')
120 it('Should set the homepage', async () => {
121 await adminConfigPage.navigateTo('instance-homepage')
122 await adminConfigPage.updateHomepage('<peertube-videos-list data-sort="-publishedAt"></peertube-videos-list>')
123 await adminConfigPage.save()
126 it('Should upload 2 videos (NSFW and classic videos)', async () => {
127 await videoUploadPage.navigateTo()
128 await videoUploadPage.uploadVideo()
129 await videoUploadPage.setAsNSFW()
130 await videoUploadPage.validSecondUploadStep(nsfwVideo)
132 await videoUploadPage.navigateTo()
133 await videoUploadPage.uploadVideo()
134 await videoUploadPage.validSecondUploadStep(normalVideo)
137 it('Should logout', async function () {
138 await loginPage.logout()
141 describe('Anonymous users', function () {
143 it('Should correctly handle do not list', async () => {
144 await loginPage.loginAsRootUser()
145 await updateAdminNSFW('do_not_list')
147 await loginPage.logout()
148 await checkCommonVideoListPages('do_not_list')
149 await checkSearchPage('do_not_list')
152 it('Should correctly handle blur', async () => {
153 await loginPage.loginAsRootUser()
154 await updateAdminNSFW('blur')
156 await loginPage.logout()
157 await checkCommonVideoListPages('blur')
158 await checkSearchPage('blur')
161 it('Should correctly handle display', async () => {
162 await loginPage.loginAsRootUser()
163 await updateAdminNSFW('display')
165 await loginPage.logout()
166 await checkCommonVideoListPages('display')
167 await checkSearchPage('display')
171 describe('Logged in users', function () {
174 await loginPage.loginAsRootUser()
177 it('Should correctly handle do not list', async () => {
178 await updateUserNSFW('do_not_list')
179 await checkCommonVideoListPages('do_not_list')
180 await checkSearchPage('do_not_list')
183 it('Should correctly handle blur', async () => {
184 await updateUserNSFW('blur')
185 await checkCommonVideoListPages('blur')
186 await checkSearchPage('blur')
189 it('Should correctly handle display', async () => {
190 await updateUserNSFW('display')
191 await checkCommonVideoListPages('display')
192 await checkSearchPage('display')