From 6d210220be0875d63461829d83c6e3a59d05cf7a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Sep 2021 10:27:04 +0200 Subject: Fix NSFW filter and add tests --- client/e2e/src/po/admin-config.po.ts | 29 ++++++++ client/e2e/src/po/login.po.ts | 20 +++++- client/e2e/src/po/my-account.ts | 18 +++++ client/e2e/src/po/player.po.ts | 5 +- client/e2e/src/po/video-list.po.ts | 128 +++++++++++++++++++++++++++++++++++ client/e2e/src/po/video-search.po.ts | 11 +++ client/e2e/src/po/video-upload.po.ts | 5 ++ client/e2e/src/po/video-watch.po.ts | 67 ++---------------- 8 files changed, 219 insertions(+), 64 deletions(-) create mode 100644 client/e2e/src/po/admin-config.po.ts create mode 100644 client/e2e/src/po/video-list.po.ts create mode 100644 client/e2e/src/po/video-search.po.ts (limited to 'client/e2e/src/po') diff --git a/client/e2e/src/po/admin-config.po.ts b/client/e2e/src/po/admin-config.po.ts new file mode 100644 index 000000000..a15184781 --- /dev/null +++ b/client/e2e/src/po/admin-config.po.ts @@ -0,0 +1,29 @@ +import { browserSleep, go } from '../utils' + +export class AdminConfigPage { + + async navigateTo (tab: 'instance-homepage' | 'basic-configuration' | 'instance-information') { + const waitTitles = { + 'instance-homepage': 'INSTANCE HOMEPAGE', + 'basic-configuration': 'APPEARANCE', + 'instance-information': 'INSTANCE' + } + + await go('/admin/config/edit-custom#' + tab) + + await $('.inner-form-title=' + waitTitles[tab]).waitForDisplayed() + } + + updateNSFWSetting (newValue: 'do_not_list' | 'blur' | 'display') { + return $('#instanceDefaultNSFWPolicy').selectByAttribute('value', newValue) + } + + updateHomepage (newValue: string) { + return $('#instanceCustomHomepageContent').setValue(newValue) + } + + async save () { + await $('input[type=submit]').click() + await browserSleep(200) + } +} diff --git a/client/e2e/src/po/login.po.ts b/client/e2e/src/po/login.po.ts index 8e3030e43..486b9a6d8 100644 --- a/client/e2e/src/po/login.po.ts +++ b/client/e2e/src/po/login.po.ts @@ -1,6 +1,7 @@ import { go } from '../utils' export class LoginPage { + async loginAsRootUser () { await go('/login') @@ -8,7 +9,7 @@ export class LoginPage { await browser.execute(`window.localStorage.setItem('no_welcome_modal', 'true')`) await $('input#username').setValue('root') - await $('input#password').setValue('test1') + await $('input#password').setValue('test' + this.getSuffix()) await browser.pause(1000) @@ -19,7 +20,24 @@ export class LoginPage { await expect(this.getLoggedInInfoElem()).toHaveText('root') } + async logout () { + await $('.logged-in-more').click() + + const logout = () => $('.dropdown-item*=Log out') + + await logout().waitForDisplayed() + await logout().click() + + await $('.login-buttons-block').waitForDisplayed() + } + private getLoggedInInfoElem () { return $('.logged-in-display-name') } + + private getSuffix () { + return browser.config.baseUrl + ? browser.config.baseUrl.slice(-1) + : '1' + } } diff --git a/client/e2e/src/po/my-account.ts b/client/e2e/src/po/my-account.ts index 85dc02805..8b5e79b5e 100644 --- a/client/e2e/src/po/my-account.ts +++ b/client/e2e/src/po/my-account.ts @@ -14,6 +14,24 @@ export class MyAccountPage { return $('a[href="/my-library/history/videos"]').click() } + // Settings + + navigateToMySettings () { + return $('a[href="/my-account"]').click() + } + + async updateNSFW (newValue: 'do_not_list' | 'blur' | 'display') { + const nsfw = $('#nsfwPolicy') + + await nsfw.waitForDisplayed() + await nsfw.scrollIntoView(false) // Avoid issues with fixed header on firefox + await nsfw.selectByAttribute('value', newValue) + + const submit = $('my-user-video-settings input[type=submit]') + await submit.scrollIntoView(false) + await submit.click() + } + // My account Videos async removeVideo (name: string) { diff --git a/client/e2e/src/po/player.po.ts b/client/e2e/src/po/player.po.ts index 372e8ab20..fca3bcdba 100644 --- a/client/e2e/src/po/player.po.ts +++ b/client/e2e/src/po/player.po.ts @@ -15,6 +15,9 @@ export class PlayerPage { waitUntilPlaylistInfo (text: string, maxTime: number) { return browser.waitUntil(async () => { + // Without this we have issues on iphone + await $('.video-js').click() + return (await $('.video-js .vjs-playlist-info').getText()).includes(text) }, { timeout: maxTime }) } @@ -42,7 +45,7 @@ export class PlayerPage { await browserSleep(2000) await browser.waitUntil(async () => { - return (await this.getWatchVideoPlayerCurrentTime()) >= 2 + return (await this.getWatchVideoPlayerCurrentTime()) >= waitUntilSec }) await videojsElem().click() diff --git a/client/e2e/src/po/video-list.po.ts b/client/e2e/src/po/video-list.po.ts new file mode 100644 index 000000000..f62c79adc --- /dev/null +++ b/client/e2e/src/po/video-list.po.ts @@ -0,0 +1,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() + } +} diff --git a/client/e2e/src/po/video-search.po.ts b/client/e2e/src/po/video-search.po.ts new file mode 100644 index 000000000..5446718d1 --- /dev/null +++ b/client/e2e/src/po/video-search.po.ts @@ -0,0 +1,11 @@ +export class VideoSearchPage { + + async search (search: string) { + await $('#search-video').setValue(search) + await $('my-header .icon-search').click() + + await browser.waitUntil(() => { + return $('my-video-miniature').isDisplayed() + }) + } +} diff --git a/client/e2e/src/po/video-upload.po.ts b/client/e2e/src/po/video-upload.po.ts index 34f916b55..dd437c390 100644 --- a/client/e2e/src/po/video-upload.po.ts +++ b/client/e2e/src/po/video-upload.po.ts @@ -1,4 +1,5 @@ import { join } from 'path' +import { clickOnCheckbox } from '../utils' export class VideoUploadPage { async navigateTo () { @@ -30,6 +31,10 @@ export class VideoUploadPage { }) } + setAsNSFW () { + return clickOnCheckbox('nsfw') + } + async validSecondUploadStep (videoName: string) { const nameInput = $('input#name') await nameInput.clearValue() diff --git a/client/e2e/src/po/video-watch.po.ts b/client/e2e/src/po/video-watch.po.ts index c07f4b25f..41425f4d7 100644 --- a/client/e2e/src/po/video-watch.po.ts +++ b/client/e2e/src/po/video-watch.po.ts @@ -1,37 +1,16 @@ -import { FIXTURE_URLS } from '../urls' -import { browserSleep, go } from '../utils' +import { browserSleep, FIXTURE_URLS, go } from '../utils' export class VideoWatchPage { - async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) { - let url: string - - // We did not upload a file on a mobile device - if (isMobileDevice === true || 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 (isSafari) return browserSleep(3000) - await $('.videos .video-miniature .video-miniature-name').waitForDisplayed() - } - - async getVideosListName () { - const elems = await $$('.videos .video-miniature .video-miniature-name') - const texts = await Promise.all(elems.map(e => e.getText())) + constructor (private isMobileDevice: boolean, private isSafari: boolean) { - return texts.map(t => t.trim()) } - waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) { - if (isSafari) return browserSleep(5000) + waitWatchVideoName (videoName: string) { + if (this.isSafari) return browserSleep(5000) // On mobile we display the first node, on desktop the second - const index = isMobileDevice ? 0 : 1 + const index = this.isMobileDevice ? 0 : 1 return browser.waitUntil(async () => { return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName) @@ -58,42 +37,6 @@ export class VideoWatchPage { return go(FIXTURE_URLS.HLS_PLAYLIST_EMBED) } - 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 - } - async clickOnUpdate () { const dropdown = $('my-video-actions-dropdown .action-button') await dropdown.click() -- cgit v1.2.3