From 44d4ee4fcb7cf8beebac73f85693c09919b91e66 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Jan 2020 14:23:19 +0100 Subject: Fix e2e tests --- client/e2e/fixtures/video.mp4 | Bin 619469 -> 619477 bytes client/e2e/src/po/app.po.ts | 21 +++++++++++ client/e2e/src/videos.e2e-spec.ts | 9 +++++ client/src/app/shared/rxjs/zone.ts | 40 +++++++++++++++++++++ .../user-subscription/user-subscription.service.ts | 14 +++++--- .../video-playlist/video-playlist.service.ts | 14 +++++--- 6 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 client/e2e/src/po/app.po.ts create mode 100644 client/src/app/shared/rxjs/zone.ts (limited to 'client') diff --git a/client/e2e/fixtures/video.mp4 b/client/e2e/fixtures/video.mp4 index f9c9e2dd6..c9ba8fd04 100644 Binary files a/client/e2e/fixtures/video.mp4 and b/client/e2e/fixtures/video.mp4 differ diff --git a/client/e2e/src/po/app.po.ts b/client/e2e/src/po/app.po.ts new file mode 100644 index 000000000..a636e825f --- /dev/null +++ b/client/e2e/src/po/app.po.ts @@ -0,0 +1,21 @@ +import { browser, by, element } from 'protractor' + +export class AppPage { + + async closeWelcomeModal () { + const firstHandle = await browser.getWindowHandle() + + if (await element(by.css('.configure-instance-button')).isPresent() === false) return + + await element(by.css('.configure-instance-button')).click() + + await browser.switchTo().window(firstHandle) + + await browser.refresh() + + await element(by.css('.form-group-checkbox')).click() + await element(by.css('.action-button-cancel')).click() + + await browser.switchTo().window(firstHandle) + } +} diff --git a/client/e2e/src/videos.e2e-spec.ts b/client/e2e/src/videos.e2e-spec.ts index 27706a506..075add531 100644 --- a/client/e2e/src/videos.e2e-spec.ts +++ b/client/e2e/src/videos.e2e-spec.ts @@ -4,6 +4,7 @@ import { LoginPage } from './po/login.po' import { browser } from 'protractor' import { VideoUpdatePage } from './po/video-update.po' import { MyAccountPage } from './po/my-account' +import { AppPage } from './po/app.po' async function skipIfUploadNotSupported () { if (await isMobileDevice() || await isSafari()) { @@ -30,6 +31,7 @@ describe('Videos workflow', () => { let videoUpdatePage: VideoUpdatePage let myAccountPage: MyAccountPage let loginPage: LoginPage + let appPage: AppPage let videoName = new Date().getTime() + ' video' const video2Name = new Date().getTime() + ' second video' @@ -42,6 +44,7 @@ describe('Videos workflow', () => { videoUpdatePage = new VideoUpdatePage() myAccountPage = new MyAccountPage() loginPage = new LoginPage() + appPage = new AppPage() if (await isMobileDevice()) { console.log('Mobile device detected.') @@ -61,6 +64,12 @@ describe('Videos workflow', () => { return loginPage.loginAsRootUser() }) + it('Should close the welcome modal', async () => { + if (await skipIfUploadNotSupported()) return + + await appPage.closeWelcomeModal() + }) + it('Should upload a video', async () => { if (await skipIfUploadNotSupported()) return diff --git a/client/src/app/shared/rxjs/zone.ts b/client/src/app/shared/rxjs/zone.ts new file mode 100644 index 000000000..74eed7032 --- /dev/null +++ b/client/src/app/shared/rxjs/zone.ts @@ -0,0 +1,40 @@ +import { SchedulerLike, Subscription } from 'rxjs' +import { NgZone } from '@angular/core' + +class LeaveZoneScheduler implements SchedulerLike { + constructor (private zone: NgZone, private scheduler: SchedulerLike) { + } + + schedule (...args: any[]): Subscription { + return this.zone.runOutsideAngular(() => + this.scheduler.schedule.apply(this.scheduler, args) + ) + } + + now (): number { + return this.scheduler.now() + } +} + +class EnterZoneScheduler implements SchedulerLike { + constructor (private zone: NgZone, private scheduler: SchedulerLike) { + } + + schedule (...args: any[]): Subscription { + return this.zone.run(() => + this.scheduler.schedule.apply(this.scheduler, args) + ) + } + + now (): number { + return this.scheduler.now() + } +} + +export function leaveZone (zone: NgZone, scheduler: SchedulerLike): SchedulerLike { + return new LeaveZoneScheduler(zone, scheduler) +} + +export function enterZone (zone: NgZone, scheduler: SchedulerLike): SchedulerLike { + return new EnterZoneScheduler(zone, scheduler) +} diff --git a/client/src/app/shared/user-subscription/user-subscription.service.ts b/client/src/app/shared/user-subscription/user-subscription.service.ts index bfb5848bc..9af9ba23e 100644 --- a/client/src/app/shared/user-subscription/user-subscription.service.ts +++ b/client/src/app/shared/user-subscription/user-subscription.service.ts @@ -1,7 +1,7 @@ -import { bufferTime, catchError, filter, map, tap, share, switchMap } from 'rxjs/operators' -import { Observable, ReplaySubject, Subject, of, merge } from 'rxjs' +import { bufferTime, catchError, filter, map, observeOn, share, switchMap, tap } from 'rxjs/operators' +import { asyncScheduler, merge, Observable, of, ReplaySubject, Subject } from 'rxjs' import { HttpClient, HttpParams } from '@angular/common/http' -import { Injectable } from '@angular/core' +import { Injectable, NgZone } from '@angular/core' import { ResultList } from '../../../../../shared' import { environment } from '../../../environments/environment' import { RestExtractor, RestService } from '../rest' @@ -11,6 +11,7 @@ import { VideoChannel as VideoChannelServer } from '../../../../../shared/models import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model' import { uniq } from 'lodash-es' import * as debug from 'debug' +import { enterZone, leaveZone } from '@app/shared/rxjs/zone' const logger = debug('peertube:subscriptions:UserSubscriptionService') @@ -32,13 +33,16 @@ export class UserSubscriptionService { constructor ( private authHttp: HttpClient, private restExtractor: RestExtractor, - private restService: RestService + private restService: RestService, + private ngZone: NgZone ) { this.existsObservable = merge( this.existsSubject.pipe( - bufferTime(500), + // We leave Angular zone so Protractor does not get stuck + bufferTime(500, leaveZone(this.ngZone, asyncScheduler)), filter(uris => uris.length !== 0), map(uris => uniq(uris)), + observeOn(enterZone(this.ngZone, asyncScheduler)), switchMap(uris => this.doSubscriptionsExist(uris)), share() ), diff --git a/client/src/app/shared/video-playlist/video-playlist.service.ts b/client/src/app/shared/video-playlist/video-playlist.service.ts index fc5eb5337..bae6f9e04 100644 --- a/client/src/app/shared/video-playlist/video-playlist.service.ts +++ b/client/src/app/shared/video-playlist/video-playlist.service.ts @@ -1,6 +1,6 @@ -import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' -import { Injectable } from '@angular/core' -import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' +import { bufferTime, catchError, filter, map, observeOn, share, switchMap, tap } from 'rxjs/operators' +import { Injectable, NgZone } from '@angular/core' +import { asyncScheduler, merge, Observable, of, ReplaySubject, Subject } from 'rxjs' import { RestExtractor } from '../rest/rest-extractor.service' import { HttpClient, HttpParams } from '@angular/common/http' import { ResultList, VideoPlaylistElementCreate, VideoPlaylistElementUpdate } from '../../../../../shared' @@ -23,6 +23,7 @@ import { VideoPlaylistElement as ServerVideoPlaylistElement } from '@shared/mode import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-element.model' import { uniq } from 'lodash-es' import * as debug from 'debug' +import { enterZone, leaveZone } from '@app/shared/rxjs/zone' const logger = debug('peertube:playlists:VideoPlaylistService') @@ -49,13 +50,16 @@ export class VideoPlaylistService { private authHttp: HttpClient, private serverService: ServerService, private restExtractor: RestExtractor, - private restService: RestService + private restService: RestService, + private ngZone: NgZone ) { this.videoExistsInPlaylistObservable = merge( this.videoExistsInPlaylistNotifier.pipe( - bufferTime(500), + // We leave Angular zone so Protractor does not get stuck + bufferTime(500, leaveZone(this.ngZone, asyncScheduler)), filter(videoIds => videoIds.length !== 0), map(videoIds => uniq(videoIds)), + observeOn(enterZone(this.ngZone, asyncScheduler)), switchMap(videoIds => this.doVideosExistInPlaylist(videoIds)), share() ), -- cgit v1.2.3