Skip to content

Commit

Permalink
Issue #SH-838 merge: Merge pull request #1210 from AmiableAnil/releas…
Browse files Browse the repository at this point in the history
…e-3.2.0

Issue #SH-838 fix: Fixed the updated course message from join traning…
  • Loading branch information
swayangjit authored Aug 10, 2020
2 parents aaa55a8 + c01058e commit 228e229
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
</ion-card>

<ion-card class="card-box-shadow">
<ion-card-content *ngIf="!showSheenAnimation || (!guestUser && showSheenAnimation && isAlreadyEnrolled)"
<ion-card-content *ngIf="!showSheenAnimation || (!isGuestUser && showSheenAnimation && isAlreadyEnrolled)"
class="card-content-bottom-0 card-content-top-0">
<ion-segment class="d-flex" [(ngModel)]="segmentType" (ionChange)="onSegmentChange($event)">
<ion-segment-button value="info" class="flex-5">
Expand Down Expand Up @@ -212,7 +212,7 @@
</div>
</ion-card-content>
</ion-card>
<ion-card *ngIf="(guestUser && showSheenAnimation) || (!guestUser && showSheenAnimation && !isAlreadyEnrolled)"
<ion-card *ngIf="(isGuestUser && showSheenAnimation) || (!isGuestUser && showSheenAnimation && !isAlreadyEnrolled)"
class="card-box-shadow p-8">
<ion-card-content class="card-content-bottom-0 card-content-top-0 animation-bottom-card">
<div class="skeleton-animation-item-1">
Expand Down Expand Up @@ -260,7 +260,7 @@
</ion-card>

</div>
<div *ngIf="(guestUser &&!showSheenAnimation) || (!guestUser && !showSheenAnimation)" [ngSwitch]="segmentType">
<div *ngIf="(isGuestUser &&!showSheenAnimation) || (!isGuestUser && !showSheenAnimation)" [ngSwitch]="segmentType">
<ion-card *ngSwitchCase="'info'">
<ion-card-content class="ion-no-padding">
<div class="ion-padding">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,34 @@ describe('EnrolledCourseDetailsPage', () => {
});
});

describe('updateEnrolledCourseData', () => {
it('should update enroll details list by invoked updateEnrolledCourseData()', (done) => {
// arrange
mockCourseService.getEnrolledCourses = jest.fn(() => of([{
batchId: 'sample-batch-id',
courseId: 'sample-course-id'
}]));
enrolledCourseDetailsPage.courseCardData = {
batchId: 'sample-batch-id'
};
mockAppGlobalService.setEnrolledCourseList = jest.fn();
// act
enrolledCourseDetailsPage.updateEnrolledCourseData();
// assert
setTimeout(() => {
expect(mockAppGlobalService.setEnrolledCourseList).toHaveBeenCalled();
expect(mockCourseService.getEnrolledCourses).toHaveBeenCalled();
done();
}, 0);
});
});

describe('subscribeUtilityEvents()', () => {
it('#subscribeUtilityEvents should handle error condition', (done) => {
// arrange
mockUtilityService.getBuildConfigValue = jest.fn(() => Promise.reject(true));
mockEvents.subscribe = jest.fn(() => ({ batchId: 'SAMPLE_BATCH_ID', courseId: 'SAMPLE_COURSE_ID' }));
spyOn(enrolledCourseDetailsPage, 'updateEnrolledCourseList').and.stub();
spyOn(enrolledCourseDetailsPage, 'updateEnrolledCourseData').and.stub();
spyOn(enrolledCourseDetailsPage, 'getBatchDetails').and.stub();
// assert
enrolledCourseDetailsPage.subscribeUtilityEvents();
Expand All @@ -556,9 +578,13 @@ describe('EnrolledCourseDetailsPage', () => {

it('should update courseCard data and return base url by invoked subscribeUtilityEvents()', (done) => {
// arrange
mockAppGlobalService.getActiveProfileUid = jest.fn(() => Promise.resolve('some_uid'));
mockAppGlobalService.isUserLoggedIn = jest.fn(() => true);
mockUtilityService.getBuildConfigValue = jest.fn(() => Promise.resolve('SAMPLE_BASE_URL'));
mockEvents.subscribe = jest.fn((_, fn) => fn({ batchId: 'SAMPLE_BATCH_ID', courseId: 'SAMPLE_COURSE_ID' }));
spyOn(enrolledCourseDetailsPage, 'updateEnrolledCourseList').and.stub();
jest.spyOn(enrolledCourseDetailsPage, 'updateEnrolledCourseData').mockImplementation(() => {
return Promise.resolve();
});
enrolledCourseDetailsPage.course = { createdBy: 'SAMPLE_CREATOR' };
enrolledCourseDetailsPage.stickyPillsRef = {
nativeElement: {
Expand All @@ -578,11 +604,13 @@ describe('EnrolledCourseDetailsPage', () => {
enrolledCourseDetailsPage.subscribeUtilityEvents();
// assert
setTimeout(() => {
expect(mockAppGlobalService.getActiveProfileUid).toHaveBeenCalled();
expect(mockAppGlobalService.isUserLoggedIn).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.baseUrl).toBe('SAMPLE_BASE_URL');
expect(mockUtilityService.getBuildConfigValue).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.course.createdBy).not.toEqual('SAMPLE_USER');
expect(mockCourseService.getEnrolledCourses).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.updateEnrolledCourseList).toBeCalled();
// expect(mockCourseService.getEnrolledCourses).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.updateEnrolledCourseData).toBeCalled();
expect(enrolledCourseDetailsPage.getAllBatches).toBeCalled();
expect(enrolledCourseDetailsPage.getBatchDetails).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.joinTraining).toBeCalled();
Expand All @@ -592,23 +620,6 @@ describe('EnrolledCourseDetailsPage', () => {
});
});

describe('updateEnrolledCourseList', () => {
it('should update enroll details list by invoked updateEnrolledCourseList()', () => {
// arrange
const userDetails = mockAppGlobalService.getUserId = jest.fn(() => 'SAMPLE_USER_ID');
const fetchEnrolledCourseRequest: FetchEnrolledCourseRequest = {
userId: 'SAMPLE_USER_ID'
};
mockCourseService.getEnrolledCourses = jest.fn(() => of([{}]));
mockZone.run = jest.fn((fn) => fn());
// act
enrolledCourseDetailsPage.updateEnrolledCourseList(mockEnrolledData.extras.state.content);
// assert
expect(mockAppGlobalService.getUserId).toHaveBeenCalled();
expect(mockCourseService.getEnrolledCourses).toHaveBeenCalled();
});
});

describe('extractApiResponse()', () => {
it('should return last played content and license', () => {
// assert
Expand Down Expand Up @@ -656,7 +667,7 @@ describe('EnrolledCourseDetailsPage', () => {
describe('checkCurrentUserType', () => {
it('should checked current user type for cath part by invoked checkCurrentUserType()', () => {
// arrange
enrolledCourseDetailsPage.guestUser = true;
enrolledCourseDetailsPage.isGuestUser = true;
mockAppGlobalService.getGuestUserInfo = jest.fn(() => Promise.reject('SAMPLE_USER'));
// act
enrolledCourseDetailsPage.checkCurrentUserType();
Expand Down Expand Up @@ -717,15 +728,15 @@ describe('EnrolledCourseDetailsPage', () => {
describe('rateContent()', () => {
it('should not show user rating for content if guest user', (done) => {
// arrange
enrolledCourseDetailsPage.guestUser = true;
enrolledCourseDetailsPage.isGuestUser = true;
mockCommonUtilService.isAccessibleForNonStudentRole = jest.fn(() => true);
enrolledCourseDetailsPage.profileType = ProfileType.TEACHER;
mockCommonUtilService.showToast = jest.fn();
// act
enrolledCourseDetailsPage.rateContent('');
// assert
setTimeout(() => {
expect(enrolledCourseDetailsPage.guestUser).toBeTruthy();
expect(enrolledCourseDetailsPage.isGuestUser).toBeTruthy();
expect(mockCommonUtilService.isAccessibleForNonStudentRole).toHaveBeenCalledWith(ProfileType.TEACHER);
expect(mockCommonUtilService.showToast).toHaveBeenCalledWith('SIGNIN_TO_USE_FEATURE');
done();
Expand All @@ -734,7 +745,7 @@ describe('EnrolledCourseDetailsPage', () => {

it('should not show user rating for content if content is not available locally and user in not a guest user', (done) => {
// arrange
enrolledCourseDetailsPage.guestUser = false;
enrolledCourseDetailsPage.isGuestUser = false;
enrolledCourseDetailsPage.course = {
isAvailableLocally: false
};
Expand All @@ -743,15 +754,15 @@ describe('EnrolledCourseDetailsPage', () => {
enrolledCourseDetailsPage.rateContent('');
// assert
setTimeout(() => {
expect(enrolledCourseDetailsPage.guestUser).toBeFalsy();
expect(enrolledCourseDetailsPage.isGuestUser).toBeFalsy();
expect(mockCommonUtilService.showToast).toHaveBeenCalledWith('TRY_BEFORE_RATING');
done();
}, 0);
});

it('should show user rating for content for loggedin user', (done) => {
// arrange
enrolledCourseDetailsPage.guestUser = false;
enrolledCourseDetailsPage.isGuestUser = false;
enrolledCourseDetailsPage.course = {
isAvailableLocally: true
};
Expand All @@ -763,7 +774,7 @@ describe('EnrolledCourseDetailsPage', () => {
enrolledCourseDetailsPage.rateContent('');
// assert
setTimeout(() => {
expect(enrolledCourseDetailsPage.guestUser).toBeFalsy();
expect(enrolledCourseDetailsPage.isGuestUser).toBeFalsy();
expect(mockPopoverCtrl.create).not.toBeUndefined();
expect(enrolledCourseDetailsPage.userRating).toBe(2);
expect(enrolledCourseDetailsPage.ratingComment).toBe('some_comment');
Expand Down Expand Up @@ -1457,7 +1468,7 @@ describe('EnrolledCourseDetailsPage', () => {
describe('enrollIntoBatch()', () => {
it('should call promptToLogin()', (done) => {
// arrange
enrolledCourseDetailsPage.guestUser = true;
enrolledCourseDetailsPage.isGuestUser = true;
const batch = {
id: '121232312'
};
Expand All @@ -1475,7 +1486,7 @@ describe('EnrolledCourseDetailsPage', () => {

it('should should successfuly enroll', (done) => {
// arrange
enrolledCourseDetailsPage.guestUser = false;
enrolledCourseDetailsPage.isGuestUser = false;
mockLocalCourseService.prepareEnrollCourseRequest = jest.fn(() => ({ id: 'sample-id' }));
const presentFn = jest.fn(() => Promise.resolve());
const dismissFn = jest.fn(() => Promise.resolve());
Expand Down Expand Up @@ -1512,7 +1523,7 @@ describe('EnrolledCourseDetailsPage', () => {

it('should should fail', (done) => {
// arrange
enrolledCourseDetailsPage.guestUser = false;
enrolledCourseDetailsPage.isGuestUser = false;
mockLocalCourseService.prepareEnrollCourseRequest = jest.fn(() => ({ id: 'sample-id' }));
const presentFn = jest.fn(() => Promise.resolve());
const dismissFn = jest.fn(() => Promise.resolve());
Expand Down Expand Up @@ -2175,24 +2186,21 @@ describe('EnrolledCourseDetailsPage', () => {
// act
enrolledCourseDetailsPage.subscribeSdkEvent();
// assert
expect(mockHeaderService.hideHeader).toBeCalled();
expect(enrolledCourseDetailsPage.importContent).toBeCalled();
expect(mockEventsBusService.events).toBeCalled();
expect(mockZone.run).toBeCalled();
});
});

describe('ionViewWillEnter()', () => {
it('should be aguest user, ', (done) => {
mockAppGlobalService.getUserId = jest.fn(() => {
return 'sample_user_id';
});
it('should be a guest user, ', (done) => {
mockAppGlobalService.getActiveProfileUid = jest.fn(() => Promise.resolve('some_uid'));
// act
mockHeaderService.headerEventEmitted$ = {
subscribe: jest.fn(() => { })
};
enrolledCourseDetailsPage.guestUser = true;
enrolledCourseDetailsPage.isGuestUser = true;
enrolledCourseDetailsPage.isAlreadyEnrolled = false;
mockHeaderService.showHeaderWithBackButton = jest.fn();
jest.spyOn(enrolledCourseDetailsPage, 'checkLoggedInOrGuestUser').mockImplementation();
jest.spyOn(enrolledCourseDetailsPage, 'checkCurrentUserType').mockImplementation();
spyOn(enrolledCourseDetailsPage, 'isCourseEnrolled').and.stub();
spyOn(enrolledCourseDetailsPage, 'subscribeSdkEvent').and.stub();
Expand All @@ -2205,35 +2213,30 @@ describe('EnrolledCourseDetailsPage', () => {
jest.spyOn(enrolledCourseDetailsPage, 'handleHeaderEvents').mockImplementation(() => {
return Promise.resolve();
});
// assert
enrolledCourseDetailsPage.ionViewWillEnter().then(() => {
expect(mockAppGlobalService.getActiveProfileUid).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.checkCurrentUserType).toHaveBeenCalled();
expect(enrolledCourseDetailsPage.guestUser).toEqual(true);
expect(enrolledCourseDetailsPage.isGuestUser).toEqual(true);
expect(mockHeaderService.showHeaderWithBackButton).toBeCalled();
expect(enrolledCourseDetailsPage.isCourseEnrolled).toBeCalled();
expect(enrolledCourseDetailsPage.subscribeSdkEvent).toBeCalled();
expect(enrolledCourseDetailsPage.populateCorRelationData).toBeCalled();
expect(enrolledCourseDetailsPage.handleBackButton).toBeCalled();
done();
});
// assert
expect(enrolledCourseDetailsPage.checkLoggedInOrGuestUser).toHaveBeenCalled();
});

it('should be a guest user, ', (done) => {
it('should not be a guest user, ', (done) => {
// act
const data = {

};
mockAppGlobalService.setEnrolledCourseList = jest.fn();
enrolledCourseDetailsPage.guestUser = false;
mockAppGlobalService.getActiveProfileUid = jest.fn(() => Promise.resolve('some_uid'));
mockAppGlobalService.isUserLoggedIn = jest.fn(() => true);
enrolledCourseDetailsPage.isGuestUser = false;
enrolledCourseDetailsPage.isAlreadyEnrolled = false;
enrolledCourseDetailsPage.courseCardData = mockCourseCardData_2;
mockHeaderService.headerEventEmitted$ = {
subscribe: jest.fn(() => { })
};
jest.spyOn(enrolledCourseDetailsPage, 'checkLoggedInOrGuestUser').mockImplementation(() => {
return Promise.resolve();
});
mockHeaderService.headerEventEmitted$ = of({
subscribe: jest.fn((fn) => fn({}))
});
Expand All @@ -2247,13 +2250,17 @@ describe('EnrolledCourseDetailsPage', () => {
jest.spyOn(enrolledCourseDetailsPage, 'getAllBatches').mockImplementation(() => {
return Promise.resolve();
});
jest.spyOn(enrolledCourseDetailsPage, 'updateEnrolledCourseData').mockImplementation(() => {
return Promise.resolve();
});
mockCourseService.getEnrolledCourses = jest.fn(() => of(mockEnrolledCourses));
mockHeaderService.showHeaderWithBackButton = jest.fn();
// act
enrolledCourseDetailsPage.ionViewWillEnter();
// assert
setTimeout(() => {
expect(mockAppGlobalService.setEnrolledCourseList).toHaveBeenCalled();
expect(mockAppGlobalService.getActiveProfileUid).toHaveBeenCalled();
expect(mockAppGlobalService.isUserLoggedIn).toHaveBeenCalled();
done();
}, 0);
});
Expand Down
Loading

0 comments on commit 228e229

Please sign in to comment.