Commit a2b6fecf authored by Nikunj Beladiya's avatar Nikunj Beladiya
Browse files

Issue #SB-19777 fix: improve unit test cases

parent 65275efe
master Dark_theme SB-25589 SB-28090 aws_fileRead dependabot/npm_and_yarn/src/app/client/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/app/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/app/express-4.17.3 dependabot/npm_and_yarn/src/app/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/desktop/OpenRAP/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/desktop/OpenRAP/express-4.17.3 dependabot/npm_and_yarn/src/desktop/OpenRAP/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/desktop/OpenRAP/qs-6.5.3 dependabot/npm_and_yarn/src/desktop/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/desktop/express-4.17.3 dependabot/npm_and_yarn/src/desktop/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/desktop/qs-6.10.3 filters_5.1.1 gcp gcp_test keshavprasadms-patch-1 keshavprasadms-patch-2 release-3.3.0 release-3.3.1 release-3.3.2 release-3.4.0 release-3.4.1 release-3.4.2 release-3.4.3 release-3.4.4 release-3.4.5 release-3.4.6 release-3.4.7 release-3.5.0 release-3.5.1 release-3.5.2 release-3.5.3 release-3.6.0 release-3.6.1 release-3.6.5 release-3.6.6 release-3.7.0 release-3.7.1 release-3.7.2 release-3.8.0 release-3.8.1 release-3.8.2 release-3.8.3 release-3.9.0 release-3.9.1 release-3.9.2 release-3.9.3 release-4.0.0 release-4.0.1 release-4.0.2 release-4.1 release-4.1.0 release-4.1.1 release-4.10.0 release-4.10.0.1 release-4.10.1 release-4.10.2 release-4.10.2.1 release-4.10.2.2 release-4.10.3 release-4.2.0 release-4.2.1 release-4.3.0 release-4.3.1 release-4.4.0 release-4.4.1 release-4.5.0 release-4.5.1 release-4.5.2 release-4.6.0 release-4.7.0 release-4.7.1 release-4.8.0 release-4.8.5 release-4.9.0 release-4.9.1 release-5.0.0 release-5.0.0.1 release-5.0.0.2 release-5.0.0.3 release-5.0.1 release-5.0.2 release-5.1.0 release-5.1.1 revert-5244-sh-809 revert-5260-SB-table-3.3.0 revert-8284-release-5.0.0 sharathkashyap-patch-1 Tags unavailable
No related merge requests found
Showing with 41 additions and 4 deletions
+41 -4
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();
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment