From b834342bd66de6f8f3b592152ed4c05f3dbfafd5 Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Fri, 3 Jun 2022 12:53:04 +0530 Subject: [PATCH 1/9] Issue #SB-0000 feat : Implementation of Play - Pause and Normal screen for Interactive Content. --- package.json | 2 +- projects/sunbird-video-player/package.json | 4 ++-- .../video-player/video-player.component.ts | 18 +++++++++++++++--- .../lib/sunbird-video-player.component.html | 2 +- .../src/lib/sunbird-video-player.component.ts | 14 ++++++++++++++ src/app/app.component.html | 8 ++++++-- src/app/app.component.ts | 11 ++++++++++- 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 35b250d..5e60174 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "reflect-metadata": "^0.1.13", "rxjs": "~6.3.3", "tslib": "^1.9.0", - "video.js": "7.4.1", + "video.js": "7.18.1", "videojs-contrib-quality-levels": "2.1.0", "videojs-http-source-selector": "1.1.6", "zone.js": "~0.10.3" diff --git a/projects/sunbird-video-player/package.json b/projects/sunbird-video-player/package.json index 989c564..b89afb6 100644 --- a/projects/sunbird-video-player/package.json +++ b/projects/sunbird-video-player/package.json @@ -1,11 +1,11 @@ { "name": "@project-sunbird/sunbird-video-player-v9", - "version": "4.10.1", + "version": "4.10.2", "peerDependencies": { "@angular/common": ">= 8.0.0", "@angular/core": ">= 8.0.0", "@types/video.js": "7.5.5", - "video.js": "7.4.1", + "video.js": "7.18.1", "@project-sunbird/client-services": "^3.4.11", "@project-sunbird/sb-styles": "0.0.7", "@project-sunbird/sunbird-quml-player-v9": "4.9.7", diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts index dd6201f..a98155e 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts @@ -1,5 +1,5 @@ import { HttpClient } from '@angular/common/http'; -import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnDestroy, Output, +import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnDestroy, Output, OnChanges, SimpleChanges, Renderer2, ViewChild, ViewEncapsulation, OnInit } from '@angular/core'; import { QuestionCursor } from '@project-sunbird/sunbird-quml-player-v9'; import * as _ from 'lodash-es'; @@ -13,8 +13,9 @@ import { ViewerService } from '../../services/viewer.service'; styleUrls: ['./video-player.component.scss'], encapsulation: ViewEncapsulation.None }) -export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy { +export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, OnChanges{ @Input() config: any; + @Input() action: string; @Output() questionSetData = new EventEmitter(); @Output() playerInstance = new EventEmitter(); transcripts = []; @@ -143,6 +144,17 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy { }); } + ngOnChanges(changes: SimpleChanges): void { + if(changes.action && this.player){ + if(changes.action.currentValue !== changes.action.previousValue){ + if(changes.action.currentValue === 'play') + this.play(); + else if(changes.action.currentValue === 'pause') + this.pause(); + } + } + } + onLoadMetadata(e) { this.totalDuration = this.viewerService.metaData.totalDuration = this.player.duration(); if (this.transcripts && this.transcripts.length && this.player.transcript) { @@ -292,7 +304,7 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy { backward() { if (this.player) { - this.player.currentTime(this.player.currentTime() + this.time); + this.player.currentTime(this.player.currentTime() - this.time); } this.toggleForwardRewindButton(); this.viewerService.raiseHeartBeatEvent('BACKWARD'); diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html index 9e657ea..92ec6de 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html @@ -2,7 +2,7 @@ - + ; @Output() telemetryEvent: EventEmitter = new EventEmitter(); @ViewChild('videoPlayer', { static: true }) videoPlayerRef: ElementRef; @@ -37,6 +38,7 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes videoInstance: any; currentInterceptionTime; currentInterceptionUIId; + isFullScreen = false; constructor( public videoPlayerService: SunbirdVideoPlayerService, @@ -217,6 +219,10 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes } this.videoInstance.play(); this.videoInstance.controls(true); + if (!document.fullscreenElement && this.isFullScreen) { //if currently video is not in full screen and was previously full screen then set it back to full screen again + document.getElementsByClassName('video-js')[0].requestFullscreen() + .catch((err) => console.error(err)) + } } } @@ -227,6 +233,14 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes this.QumlPlayerConfig.metadata['showEndPage'] = 'No'; this.currentInterceptionTime = time; this.currentInterceptionUIId = identifier; + if (document.fullscreenElement) { + this.isFullScreen = true; + document.exitFullscreen() + .catch((err) => console.error(err)) + } + else { + this.isFullScreen = false; + } this.showQumlPlayer = true; } diff --git a/src/app/app.component.html b/src/app/app.component.html index c710b1e..4ddfca7 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,8 +1,12 @@
- -
+ +
+
+   + +

Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi eos pariatur ea reiciendis mollitia accusantium, maxime fugiat omnis quo possimus dolor eaque dicta rem repellat autem, tenetur praesentium quos veritatis!

Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi eos pariatur ea reiciendis mollitia accusantium, maxime fugiat omnis quo possimus dolor eaque dicta rem repellat autem, tenetur praesentium quos veritatis!

diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fdfa26f..24c86bb 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -10,7 +10,8 @@ import { ApiService } from './services/api.service'; }) export class AppComponent { playerConfig: PlayerConfig; - contentId = 'do_21310353244132147214643'; + contentId = 'do_21310353608830976014671';//'do_21310353244132147214643'; + action = 'play'; constructor(private apiService: ApiService) { } @@ -49,4 +50,12 @@ export class AppComponent { telemetryEvent(event) { // console.log('in app: ', JSON.stringify(event)); } + + play(){ + this.action = 'play'; + } + + pause(){ + this.action = 'pause'; + } } From 9bc1c1c039fb3747bc2167ba0a3164d019342a75 Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Fri, 3 Jun 2022 13:11:18 +0530 Subject: [PATCH 2/9] Issue #SB-0000 fix : Lint errors --- .../components/video-player/video-player.component.ts | 11 ++++++----- .../src/lib/sunbird-video-player.component.ts | 10 +++++----- src/app/app.component.ts | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts index a98155e..c764cbf 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts @@ -13,7 +13,7 @@ import { ViewerService } from '../../services/viewer.service'; styleUrls: ['./video-player.component.scss'], encapsulation: ViewEncapsulation.None }) -export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, OnChanges{ +export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, OnChanges { @Input() config: any; @Input() action: string; @Output() questionSetData = new EventEmitter(); @@ -145,12 +145,13 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, O } ngOnChanges(changes: SimpleChanges): void { - if(changes.action && this.player){ - if(changes.action.currentValue !== changes.action.previousValue){ - if(changes.action.currentValue === 'play') + if (changes.action && this.player) { + if (changes.action.currentValue !== changes.action.previousValue) { + if (changes.action.currentValue === 'play') { this.play(); - else if(changes.action.currentValue === 'pause') + } else if (changes.action.currentValue === 'pause') { this.pause(); + } } } } diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts index d5af9c9..1afeb1e 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts @@ -219,9 +219,10 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes } this.videoInstance.play(); this.videoInstance.controls(true); - if (!document.fullscreenElement && this.isFullScreen) { //if currently video is not in full screen and was previously full screen then set it back to full screen again + // if currently video is not in full screen and was previously full screen then set it back to full screen again + if (!document.fullscreenElement && this.isFullScreen) { document.getElementsByClassName('video-js')[0].requestFullscreen() - .catch((err) => console.error(err)) + .catch((err) => console.error(err)); } } } @@ -236,9 +237,8 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes if (document.fullscreenElement) { this.isFullScreen = true; document.exitFullscreen() - .catch((err) => console.error(err)) - } - else { + .catch((err) => console.error(err)); + } else { this.isFullScreen = false; } this.showQumlPlayer = true; diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 24c86bb..addd260 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -10,7 +10,7 @@ import { ApiService } from './services/api.service'; }) export class AppComponent { playerConfig: PlayerConfig; - contentId = 'do_21310353608830976014671';//'do_21310353244132147214643'; + contentId = 'do_21310353608830976014671'; // 'do_21310353244132147214643'; action = 'play'; constructor(private apiService: ApiService) { } @@ -51,11 +51,11 @@ export class AppComponent { // console.log('in app: ', JSON.stringify(event)); } - play(){ + play() { this.action = 'play'; } - pause(){ + pause() { this.action = 'pause'; } } From 16b53c932af9b6da1c3c3cd25f102783276f7ec5 Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Mon, 6 Jun 2022 20:57:32 +0530 Subject: [PATCH 3/9] Issue #SB-0000 fix : Issues raised for PR --- projects/sunbird-video-player/package.json | 2 +- .../video-player/video-player.component.ts | 17 +++++++++++------ .../src/lib/playerInterfaces.ts | 7 +++++++ .../src/lib/sunbird-video-player.component.ts | 3 ++- src/app/app.component.ts | 13 ++++++++++--- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/projects/sunbird-video-player/package.json b/projects/sunbird-video-player/package.json index b89afb6..acb9913 100644 --- a/projects/sunbird-video-player/package.json +++ b/projects/sunbird-video-player/package.json @@ -1,6 +1,6 @@ { "name": "@project-sunbird/sunbird-video-player-v9", - "version": "4.10.2", + "version": "4.10.3", "peerDependencies": { "@angular/common": ">= 8.0.0", "@angular/core": ">= 8.0.0", diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts index 751f22c..973399e 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts @@ -6,6 +6,7 @@ import * as _ from 'lodash-es'; import 'videojs-contrib-quality-levels'; import videojshttpsourceselector from 'videojs-http-source-selector'; import { ViewerService } from '../../services/viewer.service'; +import { IAction } from '../../playerInterfaces'; @Component({ selector: 'video-player', @@ -15,7 +16,7 @@ import { ViewerService } from '../../services/viewer.service'; }) export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, OnChanges { @Input() config: any; - @Input() action: string; + @Input() action?: IAction; @Output() questionSetData = new EventEmitter(); @Output() playerInstance = new EventEmitter(); transcripts = []; @@ -147,11 +148,15 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, O ngOnChanges(changes: SimpleChanges): void { if (changes.action && this.player) { if (changes.action.currentValue !== changes.action.previousValue) { - if (changes.action.currentValue === 'play') { - this.play(); - } else if (changes.action.currentValue === 'pause') { - this.pause(); - } + switch (changes.action.currentValue.name) { + case 'play': + this.play(); + break; + case 'pause': + this.pause(); + break; + default: console.warn('Invalid Case!'); + } } } } diff --git a/projects/sunbird-video-player/src/lib/playerInterfaces.ts b/projects/sunbird-video-player/src/lib/playerInterfaces.ts index 22d903f..670efbc 100644 --- a/projects/sunbird-video-player/src/lib/playerInterfaces.ts +++ b/projects/sunbird-video-player/src/lib/playerInterfaces.ts @@ -76,3 +76,10 @@ export interface Transcript { languageCode: string; } export interface Transcripts extends Array {} + +export interface IAction { + name: string; + props?: { + [propName: string]: any; + }; +} diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts index 1afeb1e..4a8c7a2 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts @@ -5,6 +5,7 @@ import { import { ErrorService , errorCode , errorMessage, ISideBarEvent } from '@project-sunbird/sunbird-player-sdk-v9'; import { PlayerConfig } from './playerInterfaces'; +import { IAction } from './playerInterfaces'; import { ViewerService } from './services/viewer.service'; import { SunbirdVideoPlayerService } from './sunbird-video-player.service'; @Component({ @@ -15,7 +16,7 @@ import { SunbirdVideoPlayerService } from './sunbird-video-player.service'; export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDestroy { @Input() playerConfig: PlayerConfig; - @Input() action: string; + @Input() action?: IAction; @Output() playerEvent: EventEmitter; @Output() telemetryEvent: EventEmitter = new EventEmitter(); @ViewChild('videoPlayer', { static: true }) videoPlayerRef: ElementRef; diff --git a/src/app/app.component.ts b/src/app/app.component.ts index addd260..4c2e58e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -11,7 +11,10 @@ import { ApiService } from './services/api.service'; export class AppComponent { playerConfig: PlayerConfig; contentId = 'do_21310353608830976014671'; // 'do_21310353244132147214643'; - action = 'play'; + action = + { + name : 'play', + }; constructor(private apiService: ApiService) { } @@ -52,10 +55,14 @@ export class AppComponent { } play() { - this.action = 'play'; + this.action = { + name : 'play' + }; } pause() { - this.action = 'pause'; + this.action = { + name : 'pause' + }; } } From 24550b1b5d9c0269a28a1810da7c9f933ef4736f Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Fri, 10 Jun 2022 11:09:47 +0530 Subject: [PATCH 4/9] Issue #SB-0000 test : Added unit test cases --- .../video-player.component.spec.ts | 156 +++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts index 3729da4..734ef82 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts @@ -33,8 +33,9 @@ describe('VideoPlayerComponent', () => { it('should call pause()', () => { spyOn(component, 'toggleForwardRewindButton').and.callFake(() => 'true'); spyOn(component.viewerService, 'raiseHeartBeatEvent').and.callFake(() => 'true'); + // the first parameter is the name of the object and the second parameter is the name of the method to be spied upon component.player = { - pause: jasmine.createSpy('pause') + pause: jasmine.createSpy('pause') //?function }; component.pause(); expect(component.showPauseButton).toBeFalsy(); @@ -265,4 +266,157 @@ describe('VideoPlayerComponent', () => { expect(component.viewerService.metaData.transcripts).toEqual(['en', 'bn']); expect(component.viewerService.raiseHeartBeatEvent).toHaveBeenCalledWith(telemetryObject.type, telemetryObject.extra); }); + it('should pause the window on question set addition on add question set click', () => { + const changes = { + "config": { + "currentValue": { + "traceId": "afhjgh", + "sideMenu": { + "showShare": true, + "showDownload": true, + "showReplay": true, + "showExit": true, + "enable": false + }, + "transcripts": [], + "actions": [ + { + "play": 0 + }, + { + "pause": 51.103101 + } + ], + "volume": [], + "playBackSpeeds": [], + "totalDuration": 137.56, + "currentDuration": 51.103101 + }, + "firstChange": true, + "previousValue": undefined, + isFirstChange: () => { + return true; + } + }, + "action": { + "currentValue": { + "name": "play" + }, + "firstChange": true, + "previousValue": undefined, + isFirstChange: () => { + return true; + } + } + } + component.player = { + play: jasmine.createSpy('play') + }; + spyOn(component,'play'); + component.ngOnChanges(changes); + expect(component.play).toHaveBeenCalled(); + }); + it('should play the video from point it was paused while adding question set on cancel click', () => { + const changes = { + "config": { + "currentValue": { + "traceId": "afhjgh", + "sideMenu": { + "showShare": true, + "showDownload": true, + "showReplay": true, + "showExit": true, + "enable": false + }, + "transcripts": [], + "actions": [ + { + "play": 0 + }, + { + "pause": 51.103101 + } + ], + "volume": [], + "playBackSpeeds": [], + "totalDuration": 137.56, + "currentDuration": 51.103101 + }, + "firstChange": true, + "previousValue": undefined, + isFirstChange: () => { + return true; + } + }, + "action": { + "currentValue": { + "name": "pause" + }, + "firstChange": true, + "previousValue": undefined, + isFirstChange: () => { + return true; + } + } + } + component.player = { + pause: jasmine.createSpy('pause') + }; + spyOn(component,'pause'); + component.ngOnChanges(changes); + expect(component.pause).toHaveBeenCalled(); + }); + it('should not take any action on blank name property ', () => { + const changes = { + "config": { + "currentValue": { + "traceId": "afhjgh", + "sideMenu": { + "showShare": true, + "showDownload": true, + "showReplay": true, + "showExit": true, + "enable": false + }, + "transcripts": [], + "actions": [ + { + "play": 0 + }, + { + "pause": 51.103101 + } + ], + "volume": [], + "playBackSpeeds": [], + "totalDuration": 137.56, + "currentDuration": 51.103101 + }, + "firstChange": true, + "previousValue": undefined, + isFirstChange: () => { + return true; + } + }, + "action": { + "currentValue": { + "name": "" + }, + "firstChange": true, + "previousValue": undefined, + isFirstChange: () => { + return true; + } + } + } + component.player = { + play: jasmine.createSpy('play'), + pause: jasmine.createSpy('pause') + }; + spyOn(component,'pause'); + spyOn(component,'play'); + component.ngOnChanges(changes); + expect(component.pause).not.toHaveBeenCalled(); + expect(component.play).not.toHaveBeenCalled(); + }); }); From 0f2a8dca561ba7858719cd6d10e837818b79a38e Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Fri, 10 Jun 2022 11:14:14 +0530 Subject: [PATCH 5/9] Issue #SB-0000 test : Removed unnecessary comments --- .../lib/components/video-player/video-player.component.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts index 734ef82..68d1730 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts @@ -33,9 +33,8 @@ describe('VideoPlayerComponent', () => { it('should call pause()', () => { spyOn(component, 'toggleForwardRewindButton').and.callFake(() => 'true'); spyOn(component.viewerService, 'raiseHeartBeatEvent').and.callFake(() => 'true'); - // the first parameter is the name of the object and the second parameter is the name of the method to be spied upon component.player = { - pause: jasmine.createSpy('pause') //?function + pause: jasmine.createSpy('pause') }; component.pause(); expect(component.showPauseButton).toBeFalsy(); From 97fa3058af25588b4f721a042d925ccf627f1210 Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Fri, 10 Jun 2022 12:49:34 +0530 Subject: [PATCH 6/9] Issue #SB-0000 fix : Lint errors --- .../video-player.component.spec.ts | 188 +++++++++--------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts index 68d1730..0db2244 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts @@ -265,157 +265,157 @@ describe('VideoPlayerComponent', () => { expect(component.viewerService.metaData.transcripts).toEqual(['en', 'bn']); expect(component.viewerService.raiseHeartBeatEvent).toHaveBeenCalledWith(telemetryObject.type, telemetryObject.extra); }); - it('should pause the window on question set addition on add question set click', () => { + it('should pause the window on question set addition on add question set click', () => { const changes = { - "config": { - "currentValue": { - "traceId": "afhjgh", - "sideMenu": { - "showShare": true, - "showDownload": true, - "showReplay": true, - "showExit": true, - "enable": false + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false }, - "transcripts": [], - "actions": [ + transcripts: [], + actions: [ { - "play": 0 + play: 0 }, { - "pause": 51.103101 + pause: 51.103101 } ], - "volume": [], - "playBackSpeeds": [], - "totalDuration": 137.56, - "currentDuration": 51.103101 + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 }, - "firstChange": true, - "previousValue": undefined, + firstChange: true, + previousValue: undefined, isFirstChange: () => { return true; } }, - "action": { - "currentValue": { - "name": "play" + action: { + currentValue: { + name: 'play' }, - "firstChange": true, - "previousValue": undefined, + firstChange: true, + previousValue: undefined, isFirstChange: () => { return true; } } - } - component.player = { - play: jasmine.createSpy('play') }; - spyOn(component,'play'); - component.ngOnChanges(changes); - expect(component.play).toHaveBeenCalled(); + component.player = { + play: jasmine.createSpy('play') + }; + spyOn(component, 'play'); + component.ngOnChanges(changes); + expect(component.play).toHaveBeenCalled(); }); it('should play the video from point it was paused while adding question set on cancel click', () => { const changes = { - "config": { - "currentValue": { - "traceId": "afhjgh", - "sideMenu": { - "showShare": true, - "showDownload": true, - "showReplay": true, - "showExit": true, - "enable": false + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false }, - "transcripts": [], - "actions": [ + transcripts: [], + actions: [ { - "play": 0 + play: 0 }, { - "pause": 51.103101 + pause: 51.103101 } ], - "volume": [], - "playBackSpeeds": [], - "totalDuration": 137.56, - "currentDuration": 51.103101 + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 }, - "firstChange": true, - "previousValue": undefined, + firstChange: true, + previousValue: undefined, isFirstChange: () => { return true; } }, - "action": { - "currentValue": { - "name": "pause" + action: { + currentValue: { + name: 'pause' }, - "firstChange": true, - "previousValue": undefined, + firstChange: true, + previousValue: undefined, isFirstChange: () => { return true; } } - } - component.player = { - pause: jasmine.createSpy('pause') }; - spyOn(component,'pause'); - component.ngOnChanges(changes); - expect(component.pause).toHaveBeenCalled(); + component.player = { + pause: jasmine.createSpy('pause') + }; + spyOn(component, 'pause'); + component.ngOnChanges(changes); + expect(component.pause).toHaveBeenCalled(); }); it('should not take any action on blank name property ', () => { const changes = { - "config": { - "currentValue": { - "traceId": "afhjgh", - "sideMenu": { - "showShare": true, - "showDownload": true, - "showReplay": true, - "showExit": true, - "enable": false + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false }, - "transcripts": [], - "actions": [ + transcripts: [], + actions: [ { - "play": 0 + play: 0 }, { - "pause": 51.103101 + pause: 51.103101 } ], - "volume": [], - "playBackSpeeds": [], - "totalDuration": 137.56, - "currentDuration": 51.103101 + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 }, - "firstChange": true, - "previousValue": undefined, + firstChange: true, + previousValue: undefined, isFirstChange: () => { return true; } }, - "action": { - "currentValue": { - "name": "" + action: { + currentValue: { + name: '' }, - "firstChange": true, - "previousValue": undefined, + firstChange: true, + previousValue: undefined, isFirstChange: () => { return true; } } - } - component.player = { - play: jasmine.createSpy('play'), - pause: jasmine.createSpy('pause') }; - spyOn(component,'pause'); - spyOn(component,'play'); - component.ngOnChanges(changes); - expect(component.pause).not.toHaveBeenCalled(); - expect(component.play).not.toHaveBeenCalled(); + component.player = { + play: jasmine.createSpy('play'), + pause: jasmine.createSpy('pause') + }; + spyOn(component, 'pause'); + spyOn(component, 'play'); + component.ngOnChanges(changes); + expect(component.pause).not.toHaveBeenCalled(); + expect(component.play).not.toHaveBeenCalled(); }); }); From 56873bfc0f289fb50310482809b17fe1e71f6e46 Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Wed, 15 Jun 2022 18:26:34 +0530 Subject: [PATCH 7/9] Issue #SB-0000 test : Added more unit test cases --- README.md | 3 +- .../video-player.component.spec.ts | 4 +- .../video-player/video-player.component.ts | 8 +- .../src/lib/services/viewer.service.ts | 2 +- .../lib/sunbird-video-player.component.html | 2 +- .../sunbird-video-player.component.spec.ts | 273 +++++++++++++++++- .../src/lib/sunbird-video-player.component.ts | 20 +- src/app/app.component.spec.ts | 15 + 8 files changed, 314 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e041b65..440b52d 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ var playerConfig = { ## Available components |Feature| Notes| Selector|Code|Input|Output |--|--|--|------------------------------------------------------------------------------------------|---|--| -| Video Player | Can be used to render videos | sunbird-video-player| *``*|playerConfig|playerEvent, telemetryEvent| +| Video Player | Can be used to render videos | sunbird-video-player| *``*|playerConfig,action|playerEvent, telemetryEvent|

@@ -217,6 +217,7 @@ Click to see the steps - [Import](README.md#step-3-import-the-modules-and-compon +> Note : An additional property named `action` can be added to the above statement to implement pause and play functionality for the video player. ## Step 5: Send input to render VIDEO player Click to see the input data - [playerConfig](README.md#step-4-send-input-to-render-video-player) diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts index 0db2244..36f9461 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts @@ -265,7 +265,7 @@ describe('VideoPlayerComponent', () => { expect(component.viewerService.metaData.transcripts).toEqual(['en', 'bn']); expect(component.viewerService.raiseHeartBeatEvent).toHaveBeenCalledWith(telemetryObject.type, telemetryObject.extra); }); - it('should pause the window on question set addition on add question set click', () => { + it('should play the video from point it was paused while adding question set on cancel click', () => { const changes = { config: { currentValue: { @@ -315,7 +315,7 @@ describe('VideoPlayerComponent', () => { component.ngOnChanges(changes); expect(component.play).toHaveBeenCalled(); }); - it('should play the video from point it was paused while adding question set on cancel click', () => { + it('should pause the video on question set addition on add question set click', () => { const changes = { config: { currentValue: { diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts index 973399e..0979686 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.ts @@ -85,7 +85,9 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, O }); this.viewerService.questionCursor.getAllQuestionSet(identifiers).subscribe( (response) => { - this.viewerService.maxScore = response.reduce((a, b) => a + b, 0); + if (!_.isEmpty(response)) { + this.viewerService.maxScore = response.reduce((a, b) => a + b, 0); + } } ); } @@ -148,7 +150,7 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, O ngOnChanges(changes: SimpleChanges): void { if (changes.action && this.player) { if (changes.action.currentValue !== changes.action.previousValue) { - switch (changes.action.currentValue.name) { + switch (changes.action.currentValue.name) { case 'play': this.play(); break; @@ -156,7 +158,7 @@ export class VideoPlayerComponent implements AfterViewInit, OnInit, OnDestroy, O this.pause(); break; default: console.warn('Invalid Case!'); - } + } } } } diff --git a/projects/sunbird-video-player/src/lib/services/viewer.service.ts b/projects/sunbird-video-player/src/lib/services/viewer.service.ts index e2973cb..6c24db1 100644 --- a/projects/sunbird-video-player/src/lib/services/viewer.service.ts +++ b/projects/sunbird-video-player/src/lib/services/viewer.service.ts @@ -38,7 +38,7 @@ export class ViewerService { public interceptionResponses: any = {}; public showScore = false; public scoreObtained: any = 0; - public maxScore: any = 0; + public maxScore: number; public playerInstance: any; public contentMap = {}; public isEndEventRaised = false; diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html index 92ec6de..1d9486b 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.html @@ -2,7 +2,7 @@ - + { 'content failed to load , No Internet Available', 'CPV2_INT_CONNECT_01: content failed to load , No Internet Available', component.traceId); }); + + it('should keep the video paused on QumlPlayer load till it is shown', () => { + const changes = { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + }; + component.action = { + name: 'pause' + }; + component.playerAction = { + name: 'play' + }; + component.showQumlPlayer = true; + spyOn(component, 'ngOnChanges').and.callThrough(); + component.ngOnChanges(changes); + expect(component.ngOnChanges).toHaveBeenCalled(); + expect(component.showQumlPlayer).toBeTruthy(); + expect(component.playerAction.name).toEqual('play'); + }); + + it('#ngOnChange() should update play/pause when QumlPlayer is off', () => { + const changes = { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + }; + component.action = { + name: 'pause' + }; + component.playerAction = { + name: 'play' + }; + component.showQumlPlayer = false; + spyOn(component, 'ngOnChanges').and.callThrough(); + component.ngOnChanges(changes); + expect(component.ngOnChanges).toHaveBeenCalled(); + expect(component.showQumlPlayer).toBeFalsy(); + expect(component.playerAction.name).toEqual('pause'); + }); + + it('#ngOnChange() should not set action.name value', () => { + const changes = { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + }; + changes.action = undefined; + component.action = { + name : '' + }; + component.showQumlPlayer = true; + spyOn(component, 'ngOnChanges').and.callThrough(); + component.ngOnChanges(changes); + expect(component.ngOnChanges).toHaveBeenCalled(); + expect(component.showQumlPlayer).toBeTruthy(); + expect(component.action.name).toEqual(''); + }); + + it('#qumlPlayerEvents() should not call videoInstance.play and videoInstance.controls', () => { + component.videoInstance = { + play() { return; }, + controls(event) { return; } + }; + spyOn(component.videoInstance, 'play').and.callFake(() => {}); + spyOn(component.videoInstance, 'controls').and.callFake(() => {}); + spyOn(component, 'qumlPlayerEvents').and.callThrough(); + component.qumlPlayerEvents({eid: 'Start'}); + expect(component.qumlPlayerEvents).toHaveBeenCalled(); + expect(component.videoInstance.play).not.toHaveBeenCalled(); + expect(component.videoInstance.controls).not.toHaveBeenCalled(); + }); + + it('#qumlPlayerEvents() should call videoInstance.play and videoInstance.controls', () => { + const qumlEventSummary = { + eid: 'QUML_SUMMARY', + ver: '1.0', + edata: { + type: 'QUML_SUMMARY', + currentIndex: 0, + duration: 16, + extra: [{id: 'score', value: 1}] + } + }; + component.videoInstance = { + play() { return; }, + controls(event) { return; } + }; + component.isFullScreen = false; + component.currentInterceptionTime = '5e242d8c-b6dd-4b6b-b147-ca63d449c975'; + const wrapper = document.createElement('div'); + wrapper.innerHTML = `
`; + spyOn(document, 'querySelector').and.returnValue(wrapper); + spyOn(document, 'fullscreenElement').and.returnValue(true); + spyOn(component.videoInstance, 'play').and.callFake(() => {}); + spyOn(component.videoInstance, 'controls').and.callFake(() => {}); + spyOn(component, 'qumlPlayerEvents').and.callThrough(); + component.qumlPlayerEvents(qumlEventSummary); + expect(component.qumlPlayerEvents).toHaveBeenCalled(); + expect(component.videoInstance.play).toHaveBeenCalled(); + expect(component.videoInstance.controls).toHaveBeenCalled(); + }); + + it('#qumlPlayerEvents() should set player to full screen', () => { + const qumlEventSummary = { + eid: 'QUML_SUMMARY', + ver: '1.0', + edata: { + type: 'QUML_SUMMARY', + currentIndex: 0, + duration: 16, + extra: [{id: 'score', value: 1}] + } + }; + component.videoInstance = { + play() { return; }, + controls(event) { return; } + }; + component.isFullScreen = false; + component.currentInterceptionTime = '5e242d8c-b6dd-4b6b-b147-ca63d449c975'; + spyOn(console, 'error').and.callFake(() => {}); + spyOn(document, 'getElementsByClassName').and.returnValue([{ + requestFullscreen() {} + }]); + spyOn(document, 'querySelector').and.returnValue(undefined); + spyOn(document, 'fullscreenElement').and.returnValue(true); + spyOn(component.videoInstance, 'play').and.callFake(() => {}); + spyOn(component.videoInstance, 'controls').and.callFake(() => {}); + spyOn(component, 'qumlPlayerEvents').and.callThrough(); + component.qumlPlayerEvents(qumlEventSummary); + expect(component.qumlPlayerEvents).toHaveBeenCalled(); + expect(component.videoInstance.play).toHaveBeenCalled(); + expect(component.videoInstance.controls).toHaveBeenCalled(); + expect(document.getElementsByClassName('video-js')[0]).toBeDefined(); + expect(console.error).not.toHaveBeenCalled(); +}); + + it('#questionSetData() should not call document.exitFullscreen()', () => { + component.isFullScreen = false; + component.currentInterceptionTime = undefined; + component.currentInterceptionUIId = undefined; + component.QumlPlayerConfig = {metadata: {showStartPage: '', showEndPage: ''}}; + spyOn(component, 'questionSetData').and.callThrough(); + spyOn(document, 'exitFullscreen').and.callFake(() => {}); + const parameter = { + response: {name: 'Video'}, + time : 100, + identifier: 'do_123' + }; + component.questionSetData(parameter); + expect(component.QumlPlayerConfig.metadata).toBeDefined(); + expect(component.QumlPlayerConfig.metadata.showStartPage).toEqual('No'); + expect(component.QumlPlayerConfig.metadata.showEndPage).toEqual('No'); + expect(component.currentInterceptionTime).toEqual(100); + expect(component.currentInterceptionUIId).toEqual('do_123'); + expect(component.isFullScreen).toBeFalsy(); + expect(document.exitFullscreen).not.toHaveBeenCalled(); + }); }); diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts index 4a8c7a2..c2f122a 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.ts @@ -1,5 +1,6 @@ +import { ThrowStmt } from '@angular/compiler'; import { - ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, + ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, OnChanges, SimpleChanges, HostListener, ElementRef, ViewChild, AfterViewInit, Renderer2, OnDestroy } from '@angular/core'; import { ErrorService , errorCode , errorMessage, ISideBarEvent } from '@project-sunbird/sunbird-player-sdk-v9'; @@ -13,7 +14,7 @@ import { SunbirdVideoPlayerService } from './sunbird-video-player.service'; templateUrl: './sunbird-video-player.component.html', styleUrls: ['./sunbird-video-player.component.scss'] }) -export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDestroy { +export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDestroy, OnChanges { @Input() playerConfig: PlayerConfig; @Input() action?: IAction; @@ -40,6 +41,7 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes currentInterceptionTime; currentInterceptionUIId; isFullScreen = false; + playerAction: IAction; constructor( public videoPlayerService: SunbirdVideoPlayerService, @@ -123,6 +125,14 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes this.setTelemetryObjectRollup(this.playerConfig.metadata.identifier); } + ngOnChanges(changes: SimpleChanges): void { + if (changes.action) { + if (!this.showQumlPlayer) { + this.playerAction = this.action; + } + } + } + raiseInternetDisconnectionError = () => { const code = errorCode.internetConnectivity; const message = errorMessage.internetConnectivity; @@ -222,8 +232,10 @@ export class SunbirdVideoPlayerComponent implements OnInit, AfterViewInit, OnDes this.videoInstance.controls(true); // if currently video is not in full screen and was previously full screen then set it back to full screen again if (!document.fullscreenElement && this.isFullScreen) { - document.getElementsByClassName('video-js')[0].requestFullscreen() - .catch((err) => console.error(err)); + if (document.getElementsByClassName('video-js')[0]) { + document.getElementsByClassName('video-js')[0].requestFullscreen() + .catch((err) => console.error(err)); + } } } } diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index b2e4222..c855600 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -28,4 +28,19 @@ describe('AppComponent', () => { const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('Welcome to sunbird-video-player-app!'); }); + + it(`should play the video`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + spyOn(app, 'play').and.callFake(() => 'true'); + expect(app.action.name).toEqual('play'); + }); + + it(`should pause the video`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + spyOn(app, 'pause').and.callFake(() => 'true'); + expect(app.action.name).toEqual('pause'); + }); + }); From b1a797bf4192e3afde3f4d0cc3d216ad8f78337b Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Wed, 15 Jun 2022 19:56:05 +0530 Subject: [PATCH 8/9] Issue #SB-0000 refactor : Some changes in test data files --- .../video-player.component.data.ts | 128 ++++++++++++++++- .../video-player.component.spec.ts | 132 +---------------- ...unbird-video-player.component.spec.data.ts | 127 +++++++++++++++++ .../sunbird-video-player.component.spec.ts | 134 +----------------- 4 files changed, 261 insertions(+), 260 deletions(-) diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.data.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.data.ts index 03bbbfd..e8c4377 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.data.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.data.ts @@ -21,5 +21,131 @@ export const mockData = { // tslint:disable-next-line:max-line-length artifactUrl: 'https://cdn.jsdelivr.net/gh/tombyrer/videojs-transcript-click@1.0/demo/captions.ar.vtt' } - ] + ], + changesForPlay: { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'play' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + }, + changesForPause: { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + }, + changesForBlank: { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: '' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + } }; diff --git a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts index 36f9461..777353a 100644 --- a/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts +++ b/projects/sunbird-video-player/src/lib/components/video-player/video-player.component.spec.ts @@ -266,155 +266,29 @@ describe('VideoPlayerComponent', () => { expect(component.viewerService.raiseHeartBeatEvent).toHaveBeenCalledWith(telemetryObject.type, telemetryObject.extra); }); it('should play the video from point it was paused while adding question set on cancel click', () => { - const changes = { - config: { - currentValue: { - traceId: 'afhjgh', - sideMenu: { - showShare: true, - showDownload: true, - showReplay: true, - showExit: true, - enable: false - }, - transcripts: [], - actions: [ - { - play: 0 - }, - { - pause: 51.103101 - } - ], - volume: [], - playBackSpeeds: [], - totalDuration: 137.56, - currentDuration: 51.103101 - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - }, - action: { - currentValue: { - name: 'play' - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - } - }; component.player = { play: jasmine.createSpy('play') }; spyOn(component, 'play'); - component.ngOnChanges(changes); + component.ngOnChanges(mockData.changesForPlay); expect(component.play).toHaveBeenCalled(); }); it('should pause the video on question set addition on add question set click', () => { - const changes = { - config: { - currentValue: { - traceId: 'afhjgh', - sideMenu: { - showShare: true, - showDownload: true, - showReplay: true, - showExit: true, - enable: false - }, - transcripts: [], - actions: [ - { - play: 0 - }, - { - pause: 51.103101 - } - ], - volume: [], - playBackSpeeds: [], - totalDuration: 137.56, - currentDuration: 51.103101 - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - }, - action: { - currentValue: { - name: 'pause' - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - } - }; component.player = { pause: jasmine.createSpy('pause') }; spyOn(component, 'pause'); - component.ngOnChanges(changes); + component.ngOnChanges(mockData.changesForPause); expect(component.pause).toHaveBeenCalled(); }); it('should not take any action on blank name property ', () => { - const changes = { - config: { - currentValue: { - traceId: 'afhjgh', - sideMenu: { - showShare: true, - showDownload: true, - showReplay: true, - showExit: true, - enable: false - }, - transcripts: [], - actions: [ - { - play: 0 - }, - { - pause: 51.103101 - } - ], - volume: [], - playBackSpeeds: [], - totalDuration: 137.56, - currentDuration: 51.103101 - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - }, - action: { - currentValue: { - name: '' - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - } - }; component.player = { play: jasmine.createSpy('play'), pause: jasmine.createSpy('pause') }; spyOn(component, 'pause'); spyOn(component, 'play'); - component.ngOnChanges(changes); + component.ngOnChanges(mockData.changesForBlank); expect(component.pause).not.toHaveBeenCalled(); expect(component.play).not.toHaveBeenCalled(); }); diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.data.ts b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.data.ts index ac203ca..5ae4b0d 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.data.ts +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.data.ts @@ -35,5 +35,132 @@ export const mockData = { showDownload: true, showReplay: true, showExit: true + }, + mockChangesForPlay: { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + + }, + mockChangesForPause: { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } + }, + mockChangesForDefault: { + config: { + currentValue: { + traceId: 'afhjgh', + sideMenu: { + showShare: true, + showDownload: true, + showReplay: true, + showExit: true, + enable: false + }, + transcripts: [], + actions: [ + { + play: 0 + }, + { + pause: 51.103101 + } + ], + volume: [], + playBackSpeeds: [], + totalDuration: 137.56, + currentDuration: 51.103101 + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + }, + action: { + currentValue: { + name: 'pause' + }, + firstChange: true, + previousValue: undefined, + isFirstChange: () => { + return true; + } + } } }; diff --git a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.ts b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.ts index a269c05..ebf6b1a 100644 --- a/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.ts +++ b/projects/sunbird-video-player/src/lib/sunbird-video-player.component.spec.ts @@ -150,49 +150,8 @@ describe('SunbirdVideoPlayerComponent', () => { 'CPV2_INT_CONNECT_01: content failed to load , No Internet Available', component.traceId); }); + it('should keep the video paused on QumlPlayer load till it is shown', () => { - const changes = { - config: { - currentValue: { - traceId: 'afhjgh', - sideMenu: { - showShare: true, - showDownload: true, - showReplay: true, - showExit: true, - enable: false - }, - transcripts: [], - actions: [ - { - play: 0 - }, - { - pause: 51.103101 - } - ], - volume: [], - playBackSpeeds: [], - totalDuration: 137.56, - currentDuration: 51.103101 - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - }, - action: { - currentValue: { - name: 'pause' - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - } - }; component.action = { name: 'pause' }; @@ -201,55 +160,13 @@ describe('SunbirdVideoPlayerComponent', () => { }; component.showQumlPlayer = true; spyOn(component, 'ngOnChanges').and.callThrough(); - component.ngOnChanges(changes); + component.ngOnChanges(mockData.mockChangesForPlay); expect(component.ngOnChanges).toHaveBeenCalled(); expect(component.showQumlPlayer).toBeTruthy(); expect(component.playerAction.name).toEqual('play'); }); it('#ngOnChange() should update play/pause when QumlPlayer is off', () => { - const changes = { - config: { - currentValue: { - traceId: 'afhjgh', - sideMenu: { - showShare: true, - showDownload: true, - showReplay: true, - showExit: true, - enable: false - }, - transcripts: [], - actions: [ - { - play: 0 - }, - { - pause: 51.103101 - } - ], - volume: [], - playBackSpeeds: [], - totalDuration: 137.56, - currentDuration: 51.103101 - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - }, - action: { - currentValue: { - name: 'pause' - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - } - }; component.action = { name: 'pause' }; @@ -258,62 +175,19 @@ describe('SunbirdVideoPlayerComponent', () => { }; component.showQumlPlayer = false; spyOn(component, 'ngOnChanges').and.callThrough(); - component.ngOnChanges(changes); + component.ngOnChanges(mockData.mockChangesForPause); expect(component.ngOnChanges).toHaveBeenCalled(); expect(component.showQumlPlayer).toBeFalsy(); expect(component.playerAction.name).toEqual('pause'); }); it('#ngOnChange() should not set action.name value', () => { - const changes = { - config: { - currentValue: { - traceId: 'afhjgh', - sideMenu: { - showShare: true, - showDownload: true, - showReplay: true, - showExit: true, - enable: false - }, - transcripts: [], - actions: [ - { - play: 0 - }, - { - pause: 51.103101 - } - ], - volume: [], - playBackSpeeds: [], - totalDuration: 137.56, - currentDuration: 51.103101 - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - }, - action: { - currentValue: { - name: 'pause' - }, - firstChange: true, - previousValue: undefined, - isFirstChange: () => { - return true; - } - } - }; - changes.action = undefined; component.action = { name : '' }; component.showQumlPlayer = true; spyOn(component, 'ngOnChanges').and.callThrough(); - component.ngOnChanges(changes); + component.ngOnChanges(mockData.mockChangesForDefault); expect(component.ngOnChanges).toHaveBeenCalled(); expect(component.showQumlPlayer).toBeTruthy(); expect(component.action.name).toEqual(''); From 242f9efe0b0c644fcd94eac85e79d81a034635a6 Mon Sep 17 00:00:00 2001 From: Kshitija Kadam Date: Thu, 7 Jul 2022 12:28:55 +0530 Subject: [PATCH 9/9] Issue #SB-0000 chore: Updated player version --- projects/sunbird-video-player/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/sunbird-video-player/package.json b/projects/sunbird-video-player/package.json index acb9913..3596232 100644 --- a/projects/sunbird-video-player/package.json +++ b/projects/sunbird-video-player/package.json @@ -1,6 +1,6 @@ { "name": "@project-sunbird/sunbird-video-player-v9", - "version": "4.10.3", + "version": "5.0.1", "peerDependencies": { "@angular/common": ">= 8.0.0", "@angular/core": ">= 8.0.0",