Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Issue #SB-9344 merge: Merge pull request #476 from raghav14/release-1…
Browse files Browse the repository at this point in the history
….14.0-sprint2

Release 1.14.0 sprint2
  • Loading branch information
AmiableAnil authored Feb 15, 2019
2 parents 5252988 + 36ed50f commit 497f09f
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 50 deletions.
6 changes: 5 additions & 1 deletion src/__tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { TncUpdateHandlerService } from '@app/service/handlers/tnc-update-handle
import { LogoutHandlerService } from '@app/service/handlers/logout-handler.service';
import { DomSanitizer } from '@angular/platform-browser';
import { ImageLoader } from 'ionic-image-loader';
import { Network } from '@ionic-native/network';
export type Mockify<T> = {
[P in keyof T]: jest.Mock<{}>;
};
Expand Down Expand Up @@ -133,7 +134,8 @@ export const commonUtilServiceMock = createSpyObj<CommonUtilService>([
'getLoader',
'getTranslatedValue',
'showContentComingSoonAlert',
'toLocaleUpperCase'
'toLocaleUpperCase',
'showExitPopUp'
]);

export const eventsMock = createSpyObj<Events>([
Expand Down Expand Up @@ -396,3 +398,5 @@ export const userExistRequestMock = createSpyObj<UserExistRequest>([
export const generateOTPRequestMock = createSpyObj<GenerateOTPRequest>([

]);

export const networkMock = createSpyObj<Network>([]);
53 changes: 34 additions & 19 deletions src/pages/courses/courses.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CoursesPage} from './courses';
import {Environment, ImpressionType, PageAssembleCriteria, PageAssembleFilter, PageId, ProfileType} from 'sunbird';
import {mockRes as CourseBatchesMock} from '@app/pages/course-batches/course-batches.spec.data';
import {mockRes as CourseMock} from '../courses/courses.spec.data';
import { CoursesPage } from './courses';
import { Environment, ImpressionType, PageAssembleCriteria, PageAssembleFilter, PageId, ProfileType } from 'sunbird';
import { mockRes as CourseBatchesMock } from '@app/pages/course-batches/course-batches.spec.data';
import { mockRes as CourseMock } from '../courses/courses.spec.data';
import {
appGlobalServiceMock,
appVersionMock,
Expand All @@ -19,9 +19,10 @@ import {
telemetryGeneratorServiceMock,
zoneMock
} from '@app/__tests__/mocks';
import {ContentType} from '@app/app';
import {SearchPage} from '@app/pages/search';
import {ViewMoreActivityPage} from '@app/pages/view-more-activity';
import { ContentType } from '@app/app';
import { SearchPage } from '@app/pages/search';
import { ViewMoreActivityPage } from '@app/pages/view-more-activity';
import { networkMock } from '../../__tests__/mocks';

describe('CoursesPage', () => {
let coursesPage: CoursesPage;
Expand All @@ -30,11 +31,24 @@ describe('CoursesPage', () => {
sharedPreferencesMock.getString.mockResolvedValue('SAMPLE_LANGUAGE');
appVersionMock.getAppName.mockResolvedValue('SAMPLE_APP_NAME');

coursesPage = new CoursesPage(appVersionMock as any, navCtrlMock as any, courseServiceMock as any,
pageAssembleServiceMock as any, zoneMock as any, sunbirdQRScannerMock as any, popoverCtrlMock as any,
eventsMock as any, contentServiceMock as any, sharedPreferencesMock as any, appGlobalServiceMock as any,
courseUtilServiceMock as any, formAndFrameworkUtilServiceMock as any, commonUtilServiceMock as any,
telemetryGeneratorServiceMock as any);
coursesPage = new CoursesPage(
appVersionMock as any,
navCtrlMock as any,
courseServiceMock as any,
pageAssembleServiceMock as any,
zoneMock as any,
sunbirdQRScannerMock as any,
popoverCtrlMock as any,
eventsMock as any,
contentServiceMock as any,
sharedPreferencesMock as any,
appGlobalServiceMock as any,
courseUtilServiceMock as any,
formAndFrameworkUtilServiceMock as any,
commonUtilServiceMock as any,
telemetryGeneratorServiceMock as any,
networkMock as any
);

jest.resetAllMocks();
jest.clearAllTimers();
Expand Down Expand Up @@ -111,7 +125,7 @@ describe('CoursesPage', () => {

it('should reinitialize all parameters on ionViewWillLeave()', () => {
// arrange
coursesPage.tabBarElement = {style: {}};
coursesPage.tabBarElement = { style: {} };

// act
coursesPage.ionViewWillLeave();
Expand All @@ -127,10 +141,11 @@ describe('CoursesPage', () => {
it('should invoke getEnrolledCourses when enrollcourse event is fired', () => {
// arrange
spyOn(coursesPage, 'getEnrolledCourses').and.stub();
const data = { batchId: '213123123'};

// act
coursesPage.subscribeUtilityEvents();
eventsMock.subscribe.mock.calls[3][1].call(coursesPage, JSON.parse(CourseMock.courseUpdate));
eventsMock.subscribe.mock.calls[6][1].call(coursesPage, data);

// assert
expect(coursesPage.getEnrolledCourses).toHaveBeenCalledWith(false, false);
Expand Down Expand Up @@ -385,7 +400,7 @@ describe('CoursesPage', () => {
it('should show filter page if course filter is available', () => {
// arrange
spyOn(coursesPage, 'showFilterPage').and.stub();
popoverCtrlMock.create.mockReturnValue({present: jest.fn()});
popoverCtrlMock.create.mockReturnValue({ present: jest.fn() });
pageAssembleServiceMock.getPageAssemble.mockResolvedValue(JSON.stringify(CourseMock.popularCoursesResponse));
formAndFrameworkUtilServiceMock.getCourseFilterConfig.mockResolvedValue(CourseMock.courseConfigFilter);
coursesPage.courseFilter = CourseMock.courseConfigFilter;
Expand Down Expand Up @@ -416,7 +431,7 @@ describe('CoursesPage', () => {

it('should not call Page API if network is off ', () => {
// arrange
(commonUtilServiceMock.networkInfo as any) = {isNetworkAvailable: false};
(commonUtilServiceMock.networkInfo as any) = { isNetworkAvailable: false };
spyOn(coursesPage, 'getCourseTabData').and.stub();

// act
Expand All @@ -428,7 +443,7 @@ describe('CoursesPage', () => {

it('should call Page API if network is available on retryShowingPopularCourses()', () => {
// arrange
(commonUtilServiceMock.networkInfo as any) = {isNetworkAvailable: true};
(commonUtilServiceMock.networkInfo as any) = { isNetworkAvailable: true };
spyOn(coursesPage, 'getCourseTabData').and.stub();

// act
Expand Down Expand Up @@ -545,7 +560,7 @@ describe('CoursesPage', () => {
describe('should handle all the scenarios for importContent() method', () => {
it('should show error message if content is not available to download', (done) => {
// arrange
coursesPage.tabBarElement = {style: {}};
coursesPage.tabBarElement = { style: {} };
contentServiceMock.importContent.mockResolvedValue(CourseMock.failureimportResponse);

// act
Expand All @@ -562,7 +577,7 @@ describe('CoursesPage', () => {

it('should show error message when importContent() throws error', (done) => {
// arrange
coursesPage.tabBarElement = {style: {}};
coursesPage.tabBarElement = { style: {} };
contentServiceMock.importContent.mockRejectedValue(undefined);

// act
Expand Down
5 changes: 1 addition & 4 deletions src/pages/language-settings/language-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ describe('LanguageSettingsPage', () => {
platformMock.registerBackButtonAction.mock.calls[0][0].call(languageSettingsPage);

// assert
expect(platformMock.exitApp).toHaveBeenCalled();
expect(telemetryGeneratorServiceMock.generateEndTelemetry).toHaveBeenCalledWith(
'app', '', '', Environment.ONBOARDING
);
expect(commonUtilServiceMock.showExitPopUp).toHaveBeenCalled();
});
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/pages/onboarding/onboarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('OnboardingPage', () => {
});

describe('signIn', () => {
it('should show loader and generateLoginInteractTelemetry', () => {
it('should show loader and generateLoginInteractTelemetry', (done) => {
// arrange
const loader = {present: jest.fn()};
loadingControllerMock.create.mockReturnValue(loader);
Expand All @@ -155,8 +155,11 @@ describe('OnboardingPage', () => {
onboardingPage.signIn();

// assert
expect(loader.present).toHaveBeenCalled();
expect(telemetryGeneratorServiceMock.generateInteractTelemetry).toHaveBeenCalled();
setTimeout(() => {
expect(loader.present).toHaveBeenCalled();
expect(telemetryGeneratorServiceMock.generateInteractTelemetry).toHaveBeenCalled();
done();
}, 0);
});

it('should dismiss loader when doOAuthStepOne throws error', (done) => {
Expand All @@ -169,8 +172,6 @@ describe('OnboardingPage', () => {
onboardingPage.signIn();

// assert
expect(loader.present).toHaveBeenCalled();

setTimeout(() => {
expect(loader.dismiss).toHaveBeenCalled();
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,6 @@ describe('PersonalDetailsEditPage', () => {

expect(personalDetailsEditPage.submitForm).toHaveBeenCalled();
});
it('to enable Onsubmit button', () => {
// arrange
personalDetailsEditPage.profileEditForm.controls['name'].setValue('');
spyOn(personalDetailsEditPage, 'showErrorToastMessage').and.stub();
// act

personalDetailsEditPage.onSubmit();

// assert

expect(personalDetailsEditPage.showErrorToastMessage).toHaveBeenCalledWith('NAME');
});
it('hows Toast Message with `red` color', () => {
// arrange
commonUtilServiceMock.translateMessage.mockReturnValue('NAME_HINT');
Expand Down
52 changes: 46 additions & 6 deletions src/pages/profile/profile-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ describe('ProfilePage', () => {
spyOn(profilePage, 'refreshProfileData').and.returnValue(Promise.resolve(['hfhgf']));
// act
profilePage.doRefresh().then(() => {
expect(eventsMock.publish).toHaveBeenCalledWith('refresh:profile');
expect(loader.dismiss).toHaveBeenCalled();
done();
setTimeout(() => {
expect(eventsMock.publish).toHaveBeenCalledWith('refresh:profile');
expect(loader.dismiss).toHaveBeenCalled();
done();
}, 500);
});
});
it('it should call dofresher() to refresh profile ', (done) => {
Expand Down Expand Up @@ -174,7 +176,8 @@ describe('ProfilePage', () => {

it('should show check the format user locations() ', () => {
// arrangw
profilePage.profile = mockProfileRes.profileDetailsMock;
profilePage.profile = JSON.parse(mockProfileRes.profileDetailsMock);

// act
profilePage.formatUserLocation();
// assert
Expand Down Expand Up @@ -317,13 +320,50 @@ describe('ProfilePage', () => {
// assert
setTimeout(() => {
expect(navCtrlMock.push).toHaveBeenCalled();
expect(navCtrlMock.push).toHaveBeenCalledWith(EnrolledCourseDetailsPage, { content: 'content' });
expect(navCtrlMock.push).toHaveBeenCalledWith(CollectionDetailsPage, { content: 'content' });
expect(navCtrlMock.push).toHaveBeenCalledWith(ContentDetailsPage, { content: 'content' });
done();
}, 0);
});

it('it should call navigateToDetailPage() to course or content detail page', (done) => {
// arrange
const values = new Map();
values['sectionName'] = 'Contributions';
values['positionClicked'] = 0;
spyOn(telemetryGeneratorServiceMock, 'generateInteractTelemetry').and.callThrough();
spyOn(profilePage, 'trainingsCompleted').and.stub();
courseServiceMock.getEnrolledCourses.mockRejectedValue(JSON.stringify(mockProfileRes.getEnrolledCourses));
const content = {contentType: 'Course'};
// act
profilePage.navigateToDetailPage(content, 'Layout', 0);
// assert
setTimeout(() => {
expect(navCtrlMock.push).toHaveBeenCalled();
expect(navCtrlMock.push).toHaveBeenCalledWith(EnrolledCourseDetailsPage, { content: content});
done();
}, 0);
});

it('it should call navigateToDetailPage() to course or content detail page', (done) => {
// arrange
const values = new Map();
values['sectionName'] = 'Contributions';
values['positionClicked'] = 0;
spyOn(telemetryGeneratorServiceMock, 'generateInteractTelemetry').and.callThrough();
spyOn(profilePage, 'trainingsCompleted').and.stub();
courseServiceMock.getEnrolledCourses.mockRejectedValue(JSON.stringify(mockProfileRes.getEnrolledCourses));

const content = {mimeType: 'application/vnd.ekstep.content-collection'};
// act
profilePage.navigateToDetailPage(content, 'Layout', 0);
// assert
setTimeout(() => {
expect(navCtrlMock.push).toHaveBeenCalled();
expect(navCtrlMock.push).toHaveBeenCalledWith(CollectionDetailsPage, { content: content });
done();
}, 0);
});

it('it should call updateLocalProfile() for current user ', (done) => {
// arrange
profileServiceMock.getCurrentUser.mockResolvedValue(mockProfileRes.profileDetailsMock);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/profile/profile.spec.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const mockProfileRes = {
+ ' whether the object has the specified property as its own property (as opposed to inheriting it).","topics":[],'
+ '"userName":"vivek","userId":"0b5b8cf8-a1b6-41d9-862d-ebc242f0b962","emailVerified":false,'
+ '"lastLoginTime":1.536669035858E12,"createdDate":"2018-09-11 12:28:49:017+0000",'
+ '"createdBy":"659b011a-06ec-4107-84ad-955e16b0a48a"}',
+ '"createdBy":"659b011a-06ec-4107-84ad-955e16b0a48a",'
+ '"userLocations":[{}, {}]}',

eduDetailsMock: {
createdBy: '0b5b8cf8-a1b6-41d9-862d-ebc242f0b962',
Expand Down
5 changes: 3 additions & 2 deletions src/pages/search/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../../app/app.constant';
import { EnrolledCourseDetailsPage } from '../enrolled-course-details/enrolled-course-details';
import { CollectionDetailsPage } from '../collection-details/collection-details';
import { CollectionDetailsEtbPage } from '../collection-details-etb/collection-details-etb';
import { ContentDetailsPage } from '../content-details/content-details';
import { doesNotThrow } from 'assert';
import { empty } from 'rxjs/observable/empty';
Expand Down Expand Up @@ -190,7 +191,7 @@ describe.only('SearchPage', () => {
// act
searchPage.showContentDetails(content);
// assert
expect(navCtrlMock.push).toHaveBeenCalledWith(CollectionDetailsPage, expect.objectContaining({}));
expect(navCtrlMock.push).toHaveBeenCalledWith(CollectionDetailsEtbPage, expect.objectContaining({}));
});
it('should navigate to ContentDetails Page for showContentDetails()', () => {
// arrange
Expand Down Expand Up @@ -510,7 +511,7 @@ describe.only('SearchPage', () => {
it('should show error if nothing is added in queuedIdentifiers and network is not available downloadParentContent() ', (done) => {
// arrange
const data = JSON.stringify(mockRes.enqueuedOthersImportContentResponse);
(contentServiceMock.importContent as any).mockReturnValue(Promise.resolve(data));
contentServiceMock.importContent.mockResolvedValue(data);
searchPage.isDownloadStarted = false;
commonUtilServiceMock.networkInfo = { isNetworkAvailable: false } as any;
(commonUtilServiceMock.showToast as any).mockReturnValue('ERROR_OFFLINE_MODE');
Expand Down

0 comments on commit 497f09f

Please sign in to comment.