Skip to content

Commit

Permalink
Issue #KN-517 feat: Epub player Web component output updation
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshilimi committed Nov 8, 2022
1 parent a0a2055 commit f649b9a
Show file tree
Hide file tree
Showing 5 changed files with 2,131 additions and 150,369 deletions.
4 changes: 2 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"optimization": false,
"optimization": true,
"namedChunks": true
},
"configurations": {
Expand Down Expand Up @@ -215,7 +215,7 @@
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"optimization": true,
"namedChunks": true
},
"configurations": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { NO_ERRORS_SCHEMA, SimpleChanges, SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ViwerService } from './services/viewerService/viwer-service';
import { mockData } from './services/viewerService/viwer-service.spec.data';

import { EpubPlayerComponent } from './sunbird-epub-player.component';
import { EpubPlayerService } from './sunbird-epub-player.service';
import { epubPlayerConstants, telemetryType } from './sunbird-epub.constant';
import { HttpClientTestingModule } from '@angular/common/http/testing';



Expand All @@ -17,6 +18,7 @@ describe('EpubPlayerComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [EpubPlayerComponent],
imports: [HttpClientTestingModule],
schemas: [NO_ERRORS_SCHEMA],
providers: [ViwerService, EpubPlayerService]
})
Expand Down Expand Up @@ -140,4 +142,24 @@ describe('EpubPlayerComponent', () => {
jasmine.clock().tick(11);
expect(component.progress).toEqual(30);
});
it('should call ngOnChanges and call ngOnInit when isInitialized is true', () => {
component.isInitialized = true;
const changes: SimpleChanges = {
action: new SimpleChange('play', 'view', true),
playerConfig: new SimpleChange('play', 'view', true)
};
spyOn(component, 'ngOnInit');
component.ngOnChanges(changes);
expect(component.ngOnInit).toHaveBeenCalled();
});
it('should call ngOnChanges and should not call ngOnInit when isInitialized is false', () => {
component.isInitialized = false;
const changes: SimpleChanges = {
action: new SimpleChange('play', 'view', true),
playerConfig: new SimpleChange('play', 'view', true)
};
spyOn(component, 'ngOnInit');
component.ngOnChanges(changes);
expect(component.ngOnInit).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class EpubPlayerComponent implements OnInit, OnChanges, OnDestroy, AfterV
showExit: false,
showPrint: false
};
public isInitialized = false;
viewState = this.fromConst.LOADING;
intervalRef: any;
progress = 0;
Expand Down Expand Up @@ -63,14 +64,16 @@ export class EpubPlayerComponent implements OnInit, OnChanges, OnDestroy, AfterV
}

async ngOnInit() {
this.isInitialized = true;
if (this.playerConfig) {
if (typeof this.playerConfig === 'string') {
try {
this.playerConfig = JSON.parse(this.playerConfig);
} catch (error) {
console.error('Invalid playerConfig: ', error);
}
}

}
// initializing services
this.viwerService.initialize(this.playerConfig);
this.epubPlayerService.initialize(this.playerConfig);
Expand Down Expand Up @@ -103,6 +106,10 @@ export class EpubPlayerComponent implements OnInit, OnChanges, OnDestroy, AfterV
if (changes.showFullScreen && !changes?.showFullScreen?.firstChange) {
this.showFullScreen = changes.showFullScreen.currentValue;
}
if (changes.playerConfig.firstChange && this.isInitialized) {
// Calling for web component explicitly and life cycle works in different order
this.ngOnInit();
}
}
ngAfterViewInit() {
const epubPlayerElement = this.epubPlayerRef.nativeElement;
Expand Down
Loading

0 comments on commit f649b9a

Please sign in to comment.