From a2b6fecfbc4e21e2243a5048c1adb21791f0e8ba Mon Sep 17 00:00:00 2001 From: Nikunj Beladiya <nikunj.beladiya@tarento.com> Date: Thu, 24 Sep 2020 17:29:08 +0530 Subject: [PATCH] Issue #SB-19777 fix: improve unit test cases --- .../contentplayer-page.component.spec.ts | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/app/client/src/app/modules/player-helper/components/contentplayer-page/contentplayer-page.component.spec.ts b/src/app/client/src/app/modules/player-helper/components/contentplayer-page/contentplayer-page.component.spec.ts index 157969f3a6..cd55e4a0e0 100644 --- a/src/app/client/src/app/modules/player-helper/components/contentplayer-page/contentplayer-page.component.spec.ts +++ b/src/app/client/src/app/modules/player-helper/components/contentplayer-page/contentplayer-page.component.spec.ts @@ -1,28 +1,34 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { RouterModule, ActivatedRoute, Router } from '@angular/router'; +import { RouterModule, ActivatedRoute, Router, NavigationStart } from '@angular/router'; import { SharedModule, ToasterService, NavigationHelperService, LayoutService } from '@sunbird/shared'; import { TelemetryModule, TelemetryService } from '@sunbird/telemetry'; import { configureTestSuite } from '@sunbird/test-util'; import { ContentPlayerPageComponent } from './contentplayer-page.component'; import { UtilService } from '../../../shared/services/util/util.service'; -import { of } from 'rxjs'; +import { of, Observable } from 'rxjs'; const fakeActivatedRoute = { - 'params': of({}), + 'params': of({contentId: '123'}), snapshot: { data: { telemetry: { env: 'library', pageid: 'collection-player', type: 'play' } - } + }, + queryParams: {} } }; class RouterStub { url: ''; + public navigationStart = new NavigationStart(0, '/learn'); navigate = jasmine.createSpy('navigate'); + public events = new Observable(observer => { + observer.next(this.navigationStart); + observer.complete(); + }); } describe('ContentPlayerComponent', () => { let component: ContentPlayerPageComponent; @@ -52,6 +58,28 @@ describe('ContentPlayerComponent', () => { expect(component).toBeTruthy(); }); + it('should call ngOnInit', () => { + const activateRoute = TestBed.get(ActivatedRoute); + activateRoute.snapshot.queryParams = { + contentType: 'course', l1Parent: '1234' + }; + spyOn(component, 'setPageExitTelemtry').and.callThrough(); + component.telemetryImpression = { context: { env: 'content' }, edata: { type: 'play', uri: '/resources/play/content/do_2130404918568960001454', 'pageid': 'content-player' } }; + component.ngOnInit(); + expect(component.contentType).toEqual('course'); + expect(component.setPageExitTelemtry).toHaveBeenCalled(); + expect(component.objectRollUp).toBeDefined(); + }); + + it('should get contentId from route params', () => { + const activateRoute = TestBed.get(ActivatedRoute); + spyOn(component, 'getContent').and.callThrough(); + component.getContentIdFromRoute(); + activateRoute.params.contentId = '123'; + expect(component.contentId).toEqual('123'); + expect(component.getContent).toHaveBeenCalled(); + }); + it('should call onAssessmentEvents', () => { spyOn(component.assessmentEvents, 'emit'); component.onAssessmentEvents({}); @@ -161,4 +189,13 @@ describe('ContentPlayerComponent', () => { component.setTelemetryData(); expect(component.telemetryImpression).toBeDefined(); }); + + it('should logTelemetry with defalut value', () => { + const telemetryService = TestBed.get(TelemetryService); + const activateRoute = TestBed.get(ActivatedRoute); + delete activateRoute.snapshot.data.telemetry; + spyOn(telemetryService, 'interact'); + component.logTelemetry('do_3434223'); + expect(telemetryService.interact).toHaveBeenCalled(); + }); }); -- GitLab