ActivityPub-federated video streaming platform using P2P directly in your web browser
Add E2E to change user email
Chocobozzz9480204f0ad3
diff --git a/client/e2e/src/po/login.po.ts b/client/e2e/src/po/login.po.tsindex 4826b89927..05da95f201 100644--- a/client/e2e/src/po/login.po.ts+++ b/client/e2e/src/po/login.po.ts@@ -1,9 +1,7 @@import { browserSleep, go, isAndroid } from '../utils'export class LoginPage {-constructor (private isMobileDevice: boolean) {-}async login (options: {@@ -51,8 +49,12 @@ export class LoginPage {return $('.alert-danger').getText()}- async loginAsRootUser () {- return this.login({ username: 'root', password: 'test' + this.getSuffix() })+ loginAsRootUser () {+ return this.login({ username: 'root', password: this.getRootPassword() })+ }++ getRootPassword () {+ return 'test' + this.getSuffix()}loginOnPeerTube2 () {diff --git a/client/e2e/src/po/my-account.po.ts b/client/e2e/src/po/my-account.po.tsindex 3afbd81b97..31f7ebcb30 100644--- a/client/e2e/src/po/my-account.po.ts+++ b/client/e2e/src/po/my-account.po.ts@@ -13,7 +13,9 @@ export class MyAccountPage {return $('a[href="/my-library/history/videos"]').click()}- // Settings+ // ---------------------------------------------------------------------------+ // My account settings+ // ---------------------------------------------------------------------------navigateToMySettings () {return $('a[href="/my-account"]').click()@@ -50,7 +52,24 @@ export class MyAccountPage {await submit.click()}- // My account Videos+ async updateEmail (email: string, password: string) {+ const emailInput = $('my-account-change-email #new-email')+ await emailInput.waitForDisplayed()+ await emailInput.setValue(email)++ const passwordInput = $('my-account-change-email #password')+ await passwordInput.waitForDisplayed()+ await passwordInput.setValue(password)++ const submit = $('my-account-change-email input[type=submit]')+ await submit.waitForClickable()+ await submit.scrollIntoView({ block: 'center' }) // Avoid issues with fixed header+ await submit.click()+ }++ // ---------------------------------------------------------------------------+ // My account videos+ // ---------------------------------------------------------------------------async removeVideo (name: string) {const container = await this.getVideoRow(name)@@ -84,7 +103,21 @@ export class MyAccountPage {return elements.length}+ async getVideoRow (name: string) {+ let el = $('.name*=' + name)++ await el.waitForDisplayed()++ while (await el.getTagName() !== 'tr') {+ el = el.parentElement()+ }++ return el+ }++ // ---------------------------------------------------------------------------// My account playlists+ // ---------------------------------------------------------------------------async getPlaylistVideosText (name: string) {const elem = await this.getPlaylist(name)@@ -134,22 +167,6 @@ export class MyAccountPage {})}- // My account Videos-- private async getVideoRow (name: string) {- let el = $('.name*=' + name)-- await el.waitForDisplayed()-- while (await el.getTagName() !== 'tr') {- el = el.parentElement()- }-- return el- }-- // My account playlists-private async getPlaylist (name: string) {const playlist = () => {return $$('my-video-playlist-miniature')diff --git a/client/e2e/src/suites-local/player-settings.e2e-spec.ts b/client/e2e/src/suites-local/player-settings.e2e-spec.tsnew file mode 100644index 0000000000..20457568a9--- /dev/null+++ b/client/e2e/src/suites-local/player-settings.e2e-spec.ts@@ -0,0 +1,83 @@+import { AnonymousSettingsPage } from '../po/anonymous-settings.po'+import { LoginPage } from '../po/login.po'+import { MyAccountPage } from '../po/my-account.po'+import { VideoPublishPage } from '../po/video-publish.po'+import { VideoWatchPage } from '../po/video-watch.po'+import { go, isMobileDevice, isSafari, waitServerUp } from '../utils'++describe('Player settings', () => {+ let videoPublishPage: VideoPublishPage+ let loginPage: LoginPage+ let videoWatchPage: VideoWatchPage+ let myAccountPage: MyAccountPage+ let anonymousSettingsPage: AnonymousSettingsPage++ before(async () => {+ await waitServerUp()++ loginPage = new LoginPage(isMobileDevice())+ videoPublishPage = new VideoPublishPage()+ 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 videoPublishPage.navigateTo()+ await videoPublishPage.uploadVideo('video.mp4')+ await videoPublishPage.validSecondStep('video')++ await videoPublishPage.clickOnWatch()+ 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/signup.e2e-spec.ts b/client/e2e/src/suites-local/signup.e2e-spec.tsindex f01e50f825..556ae2d0a0 100644--- a/client/e2e/src/suites-local/signup.e2e-spec.ts+++ b/client/e2e/src/suites-local/signup.e2e-spec.ts@@ -5,6 +5,7 @@ import { SignupPage } from '../po/signup.po'import {browserSleep,findEmailTo,+ getEmailPort,getScreenshotPath,getVerificationLink,go,@@ -236,15 +237,9 @@ describe('Signup', () => {describe('Email verification enabled', function () {const emails: any[] = []- let emailPort: numberbefore(async () => {- const key = browser.options.baseUrl + '-emailPort'- // FIXME: typings are wrong, get returns a promise- // FIXME: use * because the key is not properly escaped by the shared store when using get(key)- emailPort = (await (browser.sharedStore.get('*') as unknown as Promise<number>))[key]-- await MockSMTPServer.Instance.collectEmails(emailPort, emails)+ await MockSMTPServer.Instance.collectEmails(await getEmailPort(), emails)})describe('Direct registration', function () {diff --git a/client/e2e/src/suites-local/user-settings.e2e-spec.ts b/client/e2e/src/suites-local/user-settings.e2e-spec.tsindex 61c3e350eb..2b9b9e17e4 100644--- a/client/e2e/src/suites-local/user-settings.e2e-spec.ts+++ b/client/e2e/src/suites-local/user-settings.e2e-spec.ts@@ -1,83 +1,78 @@-import { AnonymousSettingsPage } from '../po/anonymous-settings.po'+import { AdminConfigPage } from '../po/admin-config.po'import { LoginPage } from '../po/login.po'import { MyAccountPage } from '../po/my-account.po'-import { VideoPublishPage } from '../po/video-publish.po'-import { VideoWatchPage } from '../po/video-watch.po'-import { go, isMobileDevice, isSafari, waitServerUp } from '../utils'+import {+ browserSleep,+ findEmailTo,+ getEmailPort,+ getScreenshotPath,+ getVerificationLink,+ go,+ isMobileDevice,+ MockSMTPServer,+ waitServerUp+} from '../utils'describe('User settings', () => {- let videoPublishPage: VideoPublishPagelet loginPage: LoginPage- let videoWatchPage: VideoWatchPagelet myAccountPage: MyAccountPage- let anonymousSettingsPage: AnonymousSettingsPage+ let adminConfigPage: AdminConfigPage++ const emails: any[] = []before(async () => {await waitServerUp()loginPage = new LoginPage(isMobileDevice())- videoPublishPage = new VideoPublishPage()- videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari())myAccountPage = new MyAccountPage()- anonymousSettingsPage = new AnonymousSettingsPage()+ adminConfigPage = new AdminConfigPage()++ await MockSMTPServer.Instance.collectEmails(await getEmailPort(), emails)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 () => {+ describe('Email', function () {+ before(async function () {await loginPage.loginAsRootUser()- await videoPublishPage.navigateTo()- await videoPublishPage.uploadVideo('video.mp4')- await videoPublishPage.validSecondStep('video')- await videoPublishPage.clickOnWatch()- await videoWatchPage.waitWatchVideoName('video')+ await adminConfigPage.toggleSignup(true)+ await adminConfigPage.toggleSignupEmailVerification(true)+ await adminConfigPage.save()- videoUrl = await browser.getUrl()+ await browser.refresh()})- beforeEach(async function () {- await goOnVideoWatchPage()- })+ it('Should ask to change the email', async function () {+ await myAccountPage.navigateToMySettings()+ await myAccountPage.updateEmail('[email protected]', loginPage.getRootPassword())- it('Should have P2P enabled for a logged in user', async function () {- await checkP2P(true)- })+ const pendingEmailBlock = $('.pending-email')+ await pendingEmailBlock.waitForDisplayed()+ await expect(pendingEmailBlock).toHaveText(expect.stringContaining('[email protected] is awaiting email verification'))- it('Should disable P2P for a logged in user', async function () {- await myAccountPage.navigateToMySettings()- await myAccountPage.clickOnP2PCheckbox()+ let email: { text: string }- await checkP2P(false)- })+ while (!(email = findEmailTo(emails, '[email protected]'))) {+ await browserSleep(100)+ }++ await go(getVerificationLink(email))- it('Should have P2P enabled for anonymous users', async function () {- await loginPage.logout()+ const alertBlock = $('.alert-success')+ await alertBlock.waitForDisplayed()+ await expect(alertBlock).toHaveText(expect.stringContaining('Email updated'))- await checkP2P(true)+ await myAccountPage.navigateToMySettings()+ const changeEmailBlock = $('.change-email .form-group-description')+ await changeEmailBlock.waitForDisplayed()+ await expect(changeEmailBlock).toHaveText(expect.stringContaining('Your current email is [email protected]'))})+ })- it('Should disable P2P for an anonymous user', async function () {- await anonymousSettingsPage.openSettings()- await anonymousSettingsPage.clickOnP2PCheckbox()+ after(async () => {+ MockSMTPServer.Instance.kill()- await checkP2P(false)- })+ await browser.saveScreenshot(getScreenshotPath('after-test.png'))})})diff --git a/client/e2e/src/utils/email.ts b/client/e2e/src/utils/email.tsindex 2ad1203334..97e4a5aa1d 100644--- a/client/e2e/src/utils/email.ts+++ b/client/e2e/src/utils/email.ts@@ -1,4 +1,4 @@-function getVerificationLink (email: { text: string }) {+export function getVerificationLink (email: { text: string }) {const { text } = emailconst regexp = /\[(?<link>http:\/\/[^\]]+)\]/g@@ -9,13 +9,15 @@ function getVerificationLink (email: { text: string }) {for (const match of matched) {const link = match.groups.link- if (link.includes('/verify-account/')) return link+ if (link.includes('/verify-account/')) {+ return link.replace('127.0.0.1', 'localhost')+ }}throw new Error('Could not find /verify-account/ link')}-function findEmailTo (emails: { text: string, to: { address: string }[] }[], to: string) {+export function findEmailTo (emails: { text: string, to: { address: string }[] }[], to: string) {for (const email of emails) {for (const { address } of email.to) {if (address === to) return email@@ -25,7 +27,12 @@ function findEmailTo (emails: { text: string, to: { address: string }[] }[], to:return undefined}-export {- getVerificationLink,- findEmailTo+export async function getEmailPort () {+ const key = browser.options.baseUrl + '-emailPort'+ // FIXME: typings are wrong, get returns a promise+ // FIXME: use * because the key is not properly escaped by the shared store when using get(key)+ const emailPort = (await (browser.sharedStore.get('*') as unknown as Promise<number>))[key]+ if (!emailPort) throw new Error('Invalid email port')++ return emailPort}diff --git a/client/e2e/src/utils/files.ts b/client/e2e/src/utils/files.tsindex c532c987e4..3f26258c8b 100644--- a/client/e2e/src/utils/files.ts+++ b/client/e2e/src/utils/files.ts@@ -1,17 +1,13 @@-import { mkdirSync } from 'fs'+import { mkdirSync, rmSync } from 'fs'import { join } from 'path'const SCREENSHOTS_DIRECTORY = 'screenshots'-function createScreenshotsDirectory () {+export function createScreenshotsDirectory () {+ rmSync(SCREENSHOTS_DIRECTORY, { recursive: true, force: true })mkdirSync(SCREENSHOTS_DIRECTORY, { recursive: true })}-function getScreenshotPath (filename: string) {+export function getScreenshotPath (filename: string) {return join(SCREENSHOTS_DIRECTORY, filename)}--export {- createScreenshotsDirectory,- getScreenshotPath-}diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.tsindex e2d88c703e..ef3c0cd8d4 100644--- a/client/e2e/src/utils/hooks.ts+++ b/client/e2e/src/utils/hooks.ts@@ -81,7 +81,7 @@ function buildConfig (suiteFile: string = undefined) {}}- if (filename === 'signup.e2e-spec.ts') {+ if (filename === 'signup.e2e-spec.ts' || filename === 'user-settings.e2e-spec.ts') {return {signup: {limit: -1diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.tsindex 22e4e12925..c2eaef3357 100644--- a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts+++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts@@ -2,7 +2,8 @@ import { NgClass, NgIf } from '@angular/common'import { Component, OnInit, inject } from '@angular/core'import { FormsModule, ReactiveFormsModule } from '@angular/forms'import { AuthService, ServerService, UserService } from '@app/core'-import { USER_EMAIL_VALIDATOR, USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators'+import { LOGIN_PASSWORD_VALIDATOR } from '@app/shared/form-validators/login-validators'+import { USER_EMAIL_VALIDATOR } from '@app/shared/form-validators/user-validators'import { FormReactive } from '@app/shared/shared-forms/form-reactive'import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'import { AlertComponent } from '@app/shared/shared-main/common/alert.component'@@ -31,7 +32,7 @@ export class MyAccountChangeEmailComponent extends FormReactive implements OnIningOnInit () {this.buildForm({'new-email': USER_EMAIL_VALIDATOR,- 'password': USER_PASSWORD_VALIDATOR+ 'password': LOGIN_PASSWORD_VALIDATOR})this.user = this.authService.getUser()