From a9bfa85d2cdf13670aaced740da5b493fbeddfce Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Dec 2021 15:58:10 +0100 Subject: Add ability for admins to set default p2p policy --- client/e2e/src/po/anonymous-settings.po.ts | 21 +++ client/e2e/src/po/my-account.po.ts | 150 +++++++++++++++++++++ client/e2e/src/po/my-account.ts | 135 ------------------- client/e2e/src/po/video-upload.po.ts | 8 +- client/e2e/src/po/video-watch.po.ts | 13 +- client/e2e/src/suites-all/videos.e2e-spec.ts | 2 +- .../custom-server-defaults.e2e-spec.ts | 75 +++++++++-- .../e2e/src/suites-local/user-settings.e2e-spec.ts | 82 +++++++++++ .../e2e/src/suites-local/videos-list.e2e-spec.ts | 2 +- client/e2e/src/utils/elements.ts | 21 ++- client/e2e/src/utils/hooks.ts | 3 + 11 files changed, 356 insertions(+), 156 deletions(-) create mode 100644 client/e2e/src/po/anonymous-settings.po.ts create mode 100644 client/e2e/src/po/my-account.po.ts delete mode 100644 client/e2e/src/po/my-account.ts create mode 100644 client/e2e/src/suites-local/user-settings.e2e-spec.ts (limited to 'client/e2e/src') diff --git a/client/e2e/src/po/anonymous-settings.po.ts b/client/e2e/src/po/anonymous-settings.po.ts new file mode 100644 index 000000000..180d371fa --- /dev/null +++ b/client/e2e/src/po/anonymous-settings.po.ts @@ -0,0 +1,21 @@ +import { getCheckbox } from '../utils' + +export class AnonymousSettingsPage { + + async openSettings () { + const link = await $$('.menu-link').filter(async i => { + return await i.getText() === 'My settings' + }).then(links => links[0]) + + await link.click() + + await $('my-user-video-settings').waitForDisplayed() + } + + async clickOnP2PCheckbox () { + const p2p = getCheckbox('p2pEnabled') + await p2p.waitForClickable() + + await p2p.click() + } +} diff --git a/client/e2e/src/po/my-account.po.ts b/client/e2e/src/po/my-account.po.ts new file mode 100644 index 000000000..13a764e87 --- /dev/null +++ b/client/e2e/src/po/my-account.po.ts @@ -0,0 +1,150 @@ +import { getCheckbox, go } from '../utils' + +export class MyAccountPage { + + navigateToMyVideos () { + return $('a[href="/my-library/videos"]').click() + } + + navigateToMyPlaylists () { + return $('a[href="/my-library/video-playlists"]').click() + } + + navigateToMyHistory () { + 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) + + await this.submitVideoSettings() + } + + async clickOnP2PCheckbox () { + const p2p = getCheckbox('p2pEnabled') + + await p2p.waitForClickable() + await p2p.scrollIntoView(false) // Avoid issues with fixed header on firefox + + await p2p.click() + + await this.submitVideoSettings() + } + + private async submitVideoSettings () { + const submit = $('my-user-video-settings input[type=submit]') + await submit.scrollIntoView(false) + await submit.click() + } + + // My account Videos + + async removeVideo (name: string) { + const container = await this.getVideoElement(name) + + await container.$('.dropdown-toggle').click() + + const dropdownMenu = () => container.$$('.dropdown-menu .dropdown-item')[1] + + await dropdownMenu().waitForDisplayed() + return dropdownMenu().click() + } + + validRemove () { + return $('input[type=submit]').click() + } + + async countVideos (names: string[]) { + const elements = await $$('.video').filter(async e => { + const t = await e.$('.video-miniature-name').getText() + + return names.some(n => t.includes(n)) + }) + + return elements.length + } + + // My account playlists + + async getPlaylistVideosText (name: string) { + const elem = await this.getPlaylist(name) + + return elem.$('.miniature-playlist-info-overlay').getText() + } + + async clickOnPlaylist (name: string) { + const elem = await this.getPlaylist(name) + + return elem.$('.miniature-thumbnail').click() + } + + async countTotalPlaylistElements () { + await $('').waitForDisplayed() + + return $$('').length + } + + playPlaylist () { + return $('.playlist-info .miniature-thumbnail').click() + } + + async goOnAssociatedPlaylistEmbed () { + let url = await browser.getUrl() + url = url.replace('/w/p/', '/video-playlists/embed/') + url = url.replace(':3333', ':9001') + + return go(url) + } + + // My account Videos + + private async getVideoElement (name: string) { + const video = async () => { + const videos = await $$('.video').filter(async e => { + const t = await e.$('.video-miniature-name').getText() + + return t.includes(name) + }) + + return videos[0] + } + + await browser.waitUntil(async () => { + return (await video()).isDisplayed() + }) + + return video() + } + + // My account playlists + + private async getPlaylist (name: string) { + const playlist = () => { + return $$('my-video-playlist-miniature') + .filter(async e => { + const t = await e.$('.miniature-name').getText() + + return t.includes(name) + }) + .then(elems => elems[0]) + } + + await browser.waitUntil(async () => { + const el = await playlist() + + return el?.isDisplayed() + }) + + return playlist() + } +} diff --git a/client/e2e/src/po/my-account.ts b/client/e2e/src/po/my-account.ts deleted file mode 100644 index b51614fd9..000000000 --- a/client/e2e/src/po/my-account.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { go } from '../utils' - -export class MyAccountPage { - - navigateToMyVideos () { - return $('a[href="/my-library/videos"]').click() - } - - navigateToMyPlaylists () { - return $('a[href="/my-library/video-playlists"]').click() - } - - navigateToMyHistory () { - 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) { - const container = await this.getVideoElement(name) - - await container.$('.dropdown-toggle').click() - - const dropdownMenu = () => container.$$('.dropdown-menu .dropdown-item')[1] - - await dropdownMenu().waitForDisplayed() - return dropdownMenu().click() - } - - validRemove () { - return $('input[type=submit]').click() - } - - async countVideos (names: string[]) { - const elements = await $$('.video').filter(async e => { - const t = await e.$('.video-miniature-name').getText() - - return names.some(n => t.includes(n)) - }) - - return elements.length - } - - // My account playlists - - async getPlaylistVideosText (name: string) { - const elem = await this.getPlaylist(name) - - return elem.$('.miniature-playlist-info-overlay').getText() - } - - async clickOnPlaylist (name: string) { - const elem = await this.getPlaylist(name) - - return elem.$('.miniature-thumbnail').click() - } - - async countTotalPlaylistElements () { - await $('').waitForDisplayed() - - return $$('').length - } - - playPlaylist () { - return $('.playlist-info .miniature-thumbnail').click() - } - - async goOnAssociatedPlaylistEmbed () { - let url = await browser.getUrl() - url = url.replace('/w/p/', '/video-playlists/embed/') - url = url.replace(':3333', ':9001') - - return go(url) - } - - // My account Videos - - private async getVideoElement (name: string) { - const video = async () => { - const videos = await $$('.video').filter(async e => { - const t = await e.$('.video-miniature-name').getText() - - return t.includes(name) - }) - - return videos[0] - } - - await browser.waitUntil(async () => { - return (await video()).isDisplayed() - }) - - return video() - } - - // My account playlists - - private async getPlaylist (name: string) { - const playlist = () => { - return $$('my-video-playlist-miniature') - .filter(async e => { - const t = await e.$('.miniature-name').getText() - - return t.includes(name) - }) - .then(elems => elems[0]) - } - - await browser.waitUntil(async () => { - const el = await playlist() - - return el?.isDisplayed() - }) - - return playlist() - } -} diff --git a/client/e2e/src/po/video-upload.po.ts b/client/e2e/src/po/video-upload.po.ts index dd437c390..2206b56c3 100644 --- a/client/e2e/src/po/video-upload.po.ts +++ b/client/e2e/src/po/video-upload.po.ts @@ -1,5 +1,5 @@ import { join } from 'path' -import { clickOnCheckbox } from '../utils' +import { getCheckbox, selectCustomSelect } from '../utils' export class VideoUploadPage { async navigateTo () { @@ -32,7 +32,7 @@ export class VideoUploadPage { } setAsNSFW () { - return clickOnCheckbox('nsfw') + return getCheckbox('nsfw').click() } async validSecondUploadStep (videoName: string) { @@ -47,6 +47,10 @@ export class VideoUploadPage { }) } + setAsPublic () { + return selectCustomSelect('privacy', 'Public') + } + private getSecondStepSubmitButton () { return $('.submit-container my-button') } diff --git a/client/e2e/src/po/video-watch.po.ts b/client/e2e/src/po/video-watch.po.ts index 1406c971a..cecda3a8b 100644 --- a/client/e2e/src/po/video-watch.po.ts +++ b/client/e2e/src/po/video-watch.po.ts @@ -39,12 +39,23 @@ export class VideoWatchPage { return $('my-video-comment-add').isExisting() } + isPrivacyWarningDisplayed () { + return $('my-privacy-concerns').isDisplayed() + } + async goOnAssociatedEmbed () { let url = await browser.getUrl() url = url.replace('/w/', '/videos/embed/') url = url.replace(':3333', ':9001') - return go(url) + await go(url) + await $('.vjs-big-play-button').waitForDisplayed() + } + + async isEmbedWarningDisplayed () { + const text = await $('.vjs-dock-description').getText() + + return !!text.trim() } goOnP2PMediaLoaderEmbed () { diff --git a/client/e2e/src/suites-all/videos.e2e-spec.ts b/client/e2e/src/suites-all/videos.e2e-spec.ts index 3b8305a25..b3a87c8e2 100644 --- a/client/e2e/src/suites-all/videos.e2e-spec.ts +++ b/client/e2e/src/suites-all/videos.e2e-spec.ts @@ -1,5 +1,5 @@ import { LoginPage } from '../po/login.po' -import { MyAccountPage } from '../po/my-account' +import { MyAccountPage } from '../po/my-account.po' import { PlayerPage } from '../po/player.po' import { VideoListPage } from '../po/video-list.po' import { VideoUpdatePage } from '../po/video-update.po' diff --git a/client/e2e/src/suites-local/custom-server-defaults.e2e-spec.ts b/client/e2e/src/suites-local/custom-server-defaults.e2e-spec.ts index c2c8edcc9..e060d382f 100644 --- a/client/e2e/src/suites-local/custom-server-defaults.e2e-spec.ts +++ b/client/e2e/src/suites-local/custom-server-defaults.e2e-spec.ts @@ -1,7 +1,7 @@ import { LoginPage } from '../po/login.po' import { VideoUploadPage } from '../po/video-upload.po' import { VideoWatchPage } from '../po/video-watch.po' -import { isMobileDevice, isSafari, waitServerUp } from '../utils' +import { go, isMobileDevice, isSafari, waitServerUp } from '../utils' describe('Custom server defaults', () => { let videoUploadPage: VideoUploadPage @@ -10,9 +10,7 @@ describe('Custom server defaults', () => { before(async () => { await waitServerUp() - }) - beforeEach(async () => { loginPage = new LoginPage() videoUploadPage = new VideoUploadPage() videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari()) @@ -20,18 +18,69 @@ describe('Custom server defaults', () => { await browser.maximizeWindow() }) - it('Should upload a video with custom default values', async function () { - await loginPage.loginAsRootUser() - await videoUploadPage.navigateTo() - await videoUploadPage.uploadVideo() - await videoUploadPage.validSecondUploadStep('video') + describe('Publish default values', function () { + before(async function () { + await loginPage.loginAsRootUser() + }) + + it('Should upload a video with custom default values', async function () { + await videoUploadPage.navigateTo() + await videoUploadPage.uploadVideo() + await videoUploadPage.validSecondUploadStep('video') - await videoWatchPage.waitWatchVideoName('video') + await videoWatchPage.waitWatchVideoName('video') - expect(await videoWatchPage.getPrivacy()).toBe('Internal') - expect(await videoWatchPage.getLicence()).toBe('Attribution - Non Commercial') - expect(await videoWatchPage.isDownloadEnabled()).toBeFalsy() - expect(await videoWatchPage.areCommentsEnabled()).toBeFalsy() + expect(await videoWatchPage.getPrivacy()).toBe('Internal') + expect(await videoWatchPage.getLicence()).toBe('Attribution - Non Commercial') + expect(await videoWatchPage.isDownloadEnabled()).toBeFalsy() + expect(await videoWatchPage.areCommentsEnabled()).toBeFalsy() + }) + + after(async function () { + await loginPage.logout() + }) }) + describe('P2P', function () { + let videoUrl: string + + async function goOnVideoWatchPage () { + await go(videoUrl) + await videoWatchPage.waitWatchVideoName('video') + } + + async function checkP2P (enabled: boolean) { + await goOnVideoWatchPage() + expect(await videoWatchPage.isPrivacyWarningDisplayed()).toEqual(enabled) + + await videoWatchPage.goOnAssociatedEmbed() + expect(await videoWatchPage.isEmbedWarningDisplayed()).toEqual(enabled) + } + + before(async () => { + await loginPage.loginAsRootUser() + await videoUploadPage.navigateTo() + await videoUploadPage.uploadVideo() + await videoUploadPage.setAsPublic() + await videoUploadPage.validSecondUploadStep('video') + + await videoWatchPage.waitWatchVideoName('video') + + videoUrl = await browser.getUrl() + }) + + beforeEach(async function () { + await goOnVideoWatchPage() + }) + + it('Should have P2P disabled for a logged in user', async function () { + await checkP2P(false) + }) + + it('Should have P2P disabled for anonymous users', async function () { + await loginPage.logout() + + await checkP2P(false) + }) + }) }) diff --git a/client/e2e/src/suites-local/user-settings.e2e-spec.ts b/client/e2e/src/suites-local/user-settings.e2e-spec.ts new file mode 100644 index 000000000..b87501cd1 --- /dev/null +++ b/client/e2e/src/suites-local/user-settings.e2e-spec.ts @@ -0,0 +1,82 @@ +import { AnonymousSettingsPage } from '../po/anonymous-settings.po' +import { LoginPage } from '../po/login.po' +import { MyAccountPage } from '../po/my-account.po' +import { VideoUploadPage } from '../po/video-upload.po' +import { VideoWatchPage } from '../po/video-watch.po' +import { go, isMobileDevice, isSafari, waitServerUp } from '../utils' + +describe('User settings', () => { + let videoUploadPage: VideoUploadPage + let loginPage: LoginPage + let videoWatchPage: VideoWatchPage + let myAccountPage: MyAccountPage + let anonymousSettingsPage: AnonymousSettingsPage + + before(async () => { + await waitServerUp() + + loginPage = new LoginPage() + videoUploadPage = new VideoUploadPage() + videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari()) + myAccountPage = new MyAccountPage() + anonymousSettingsPage = new AnonymousSettingsPage() + + await browser.maximizeWindow() + }) + + describe('P2P', function () { + let videoUrl: string + + async function goOnVideoWatchPage () { + await go(videoUrl) + await videoWatchPage.waitWatchVideoName('video') + } + + async function checkP2P (enabled: boolean) { + await goOnVideoWatchPage() + expect(await videoWatchPage.isPrivacyWarningDisplayed()).toEqual(enabled) + + await videoWatchPage.goOnAssociatedEmbed() + expect(await videoWatchPage.isEmbedWarningDisplayed()).toEqual(enabled) + } + + before(async () => { + await loginPage.loginAsRootUser() + await videoUploadPage.navigateTo() + await videoUploadPage.uploadVideo() + await videoUploadPage.validSecondUploadStep('video') + + await videoWatchPage.waitWatchVideoName('video') + + videoUrl = await browser.getUrl() + }) + + beforeEach(async function () { + await goOnVideoWatchPage() + }) + + it('Should have P2P enabled for a logged in user', async function () { + await checkP2P(true) + }) + + it('Should disable P2P for a logged in user', async function () { + await myAccountPage.navigateToMySettings() + await myAccountPage.clickOnP2PCheckbox() + + await checkP2P(false) + }) + + it('Should have P2P enabled for anonymous users', async function () { + await loginPage.logout() + + await checkP2P(true) + }) + + it('Should disable P2P for an anonymous user', async function () { + await anonymousSettingsPage.openSettings() + await anonymousSettingsPage.clickOnP2PCheckbox() + + await checkP2P(false) + }) + }) +}) diff --git a/client/e2e/src/suites-local/videos-list.e2e-spec.ts b/client/e2e/src/suites-local/videos-list.e2e-spec.ts index bca6018b9..ce57261b9 100644 --- a/client/e2e/src/suites-local/videos-list.e2e-spec.ts +++ b/client/e2e/src/suites-local/videos-list.e2e-spec.ts @@ -1,6 +1,6 @@ import { AdminConfigPage } from '../po/admin-config.po' import { LoginPage } from '../po/login.po' -import { MyAccountPage } from '../po/my-account' +import { MyAccountPage } from '../po/my-account.po' import { VideoListPage } from '../po/video-list.po' import { VideoSearchPage } from '../po/video-search.po' import { VideoUploadPage } from '../po/video-upload.po' diff --git a/client/e2e/src/utils/elements.ts b/client/e2e/src/utils/elements.ts index cadc46cce..315718879 100644 --- a/client/e2e/src/utils/elements.ts +++ b/client/e2e/src/utils/elements.ts @@ -1,7 +1,22 @@ -function clickOnCheckbox (name: string) { - return $(`my-peertube-checkbox[inputname=${name}] label`).click() +function getCheckbox (name: string) { + return $(`my-peertube-checkbox[inputname=${name}] label`) +} + +async function selectCustomSelect (id: string, valueLabel: string) { + await $(`[formcontrolname=${id}] .ng-arrow-wrapper`).click() + + const option = await $$(`[formcontrolname=${id}] .ng-option`).filter(async o => { + const text = await o.getText() + + return text.trimStart().startsWith(valueLabel) + }).then(options => options[0]) + + await option.waitForDisplayed() + + return option.click() } export { - clickOnCheckbox + getCheckbox, + selectCustomSelect } diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.ts index e42c6a5d8..2f3d10fe3 100644 --- a/client/e2e/src/utils/hooks.ts +++ b/client/e2e/src/utils/hooks.ts @@ -55,6 +55,9 @@ function buildConfig (suiteFile: string = undefined) { comments_enabled: false, privacy: 4, licence: 4 + }, + p2p: { + enabled: false } } } -- cgit v1.2.3