Skip to content

Commit

Permalink
Issue ED-4046 fix: Added Download and play option for ecml contents.
Browse files Browse the repository at this point in the history
  • Loading branch information
swayangjit committed Jun 27, 2024
1 parent 2f32659 commit 0b2954e
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ describe('SbAppSharePopupComponent', () => {
dismiss: jest.fn()
};
const mockPlatform: Partial<Platform> = {
is: jest.fn()
is: jest.fn(),
backButton: {
subscribeWithPriority: jest.fn((_, fn) => fn({
unsubscribe: jest.fn()
})),
} as any
};
const mocksocialSharing: Partial<SocialSharing> = {
share: jest.fn()
Expand Down Expand Up @@ -152,14 +157,17 @@ describe('SbAppSharePopupComponent', () => {
});
});

it('should populate apk size and shareUrl', () => {
it('should populate apk size and shareUrl', (done) => {
// arrange
const unsubscribeFn = jest.fn();
mockPlatform.backButton = {
subscribeWithPriority: jest.fn((_, fn) => fn()),
} as any;
sbAppSharePopupComponent.backButtonFunc = {
unsubscribe: unsubscribeFn
subscribeWithPriority: jest.fn((_, cb) => {
setTimeout(() => {
cb();
}, 0);
return {
unsubscribe: jest.fn()
};
}),
} as any;
// act
sbAppSharePopupComponent.ngOnInit();
Expand All @@ -174,17 +182,21 @@ describe('SbAppSharePopupComponent', () => {
expect(sbAppSharePopupComponent.shareUrl).toEqual(
'https://play.google.com/store/apps/details?id=org.sunbird.' +
'app&referrer=utm_source%3Dmobile%26utm_campaign%3Dshare_app');
done()
}, 0);
});

it('should not brek if getAPKSize() gives error response', () => {
it('should not brek if getAPKSize() gives error response', (done) => {
// arrange
const unsubscribeFn = jest.fn();
mockPlatform.backButton = {
subscribeWithPriority: jest.fn((_, fn) => fn()),
} as any;
sbAppSharePopupComponent.backButtonFunc = {
unsubscribe: unsubscribeFn
subscribeWithPriority: jest.fn((_, cb) => {
setTimeout(() => {
cb();
}, 0);
return {
unsubscribe: jest.fn()
};
}),
} as any;

mockUtilityService.getApkSize = jest.fn(() => Promise.reject({}));
Expand All @@ -201,6 +213,7 @@ describe('SbAppSharePopupComponent', () => {
expect(sbAppSharePopupComponent.shareUrl).toEqual(
'https://play.google.com/store/apps/details?id=org.sunbird.' +
'app&referrer=utm_source%3Dmobile%26utm_campaign%3Dshare_app');
done()
}, 0);
});

Expand Down Expand Up @@ -232,14 +245,14 @@ describe('SbAppSharePopupComponent', () => {
// arrange
mockPopoverCtrl.dismiss = jest.fn();
sbAppSharePopupComponent.shareUrl = 'sample_url';
const url = `Get Sunbird from the Play Store:` + '\n' + 'sample_url';
mockCommonUtilService.translateMessage = jest.fn(() => url);
// const url = `Get Sunbird from the Play Store:` + '\n' + 'sample_url';
mockCommonUtilService.translateMessage = jest.fn(() => 'sample_url');
mockPlatform.is = jest.fn((fn) => fn == "android");
// act
sbAppSharePopupComponent.shareLink();
// assert
setTimeout(() => {
expect(mocksocialSharing.share).toHaveBeenCalledWith(null, null, null, url);
expect(mocksocialSharing.share).toHaveBeenCalledWith(null, null, null, 'sample_url');
expect(mockTelemetryGeneratorService.generateInteractTelemetry).toHaveBeenCalledWith(ShareMode.SHARE,
'',
Environment.SETTINGS,
Expand Down Expand Up @@ -341,6 +354,7 @@ describe('SbAppSharePopupComponent', () => {
undefined, undefined, undefined, undefined,
ID.SHARE_CONFIRM);
expect(mockPopoverCtrl.dismiss).toHaveBeenCalled();
done()
}, 0);
});

Expand All @@ -362,6 +376,7 @@ describe('SbAppSharePopupComponent', () => {
setTimeout(() => {
expect(mockCommonUtilService.buildPermissionPopover).toHaveBeenCalled();
expect(presentFN).toHaveBeenCalled();
done()
}, 0);
});

Expand Down Expand Up @@ -411,6 +426,7 @@ describe('SbAppSharePopupComponent', () => {
undefined, undefined, undefined, undefined,
ID.SHARE_CONFIRM);
expect(mockCommonUtilService.getGivenPermissionStatus).toHaveBeenCalled();
done()
}, 0);
});
it('should call permission popup on saveFile if not given', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/content-details/content-details.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@

</div>
<div class="sb-common-player-group sb-play-title-group"
*ngIf="content.mimeType !== 'application/vnd.ekstep.h5p-archive'">
*ngIf="!contentDownloadPlay">
<button fill="clear" icon-only class="sb-common-title" aria-label="Play video" (click)="handleContentPlay(true)">
<img src="assets/imgs/play_circle.svg" role="button" alt="play" class="play-circle">
</button>
<p class="play-text"> {{'PLAY' | translate}} </p>
</div>
<div class="sb-common-player-group sb-download-title-group" (click)="openConfirmPopUp()"
*ngIf="content.mimeType === 'application/vnd.ekstep.h5p-archive'">
*ngIf="contentDownloadPlay">
<ion-button fill="clear" icon-only class="sb-common-title">
<ion-icon name="cloud-download" role="button" class="sb-common-white-icon"></ion-icon>
</ion-button>
Expand Down
64 changes: 44 additions & 20 deletions src/app/content-details/content-details.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('ContentDetailsPage', () => {
addContentAccess: jest.fn(() => of())
};
const mockContentService: Partial<ContentService> = {
getContentDetails: jest.fn(() => of({ contentData: { size: '12KB', status: 'Retired' } })),
getContentDetails: jest.fn(() => of({ contentData: { size: '12KB', status: 'Retired' }, mimeType: 'application/vnd.ekstep.ecml-archive' })),
setContentMarker: jest.fn(() => of())
} as any;
const mockEventBusService: Partial<EventsBusService> = {};
Expand Down Expand Up @@ -150,7 +150,9 @@ describe('ContentDetailsPage', () => {
};
const mockPlayerService: Partial<PlayerService> = {};
const mockSantizer: Partial<DomSanitizer> = {};
const mockScreenOrientation: Partial<ScreenOrientation> = {};
const mockScreenOrientation: Partial<ScreenOrientation> = {
ORIENTATIONS: {PORTRAIT: 'portrait'}
} as any;

beforeAll(() => {
contentDetailsPage = new ContentDetailsPage(
Expand Down Expand Up @@ -2815,9 +2817,7 @@ describe('ContentDetailsPage', () => {

it('should get extras from content || navigation when getExtras() called', (done) => {
// arrange
// contentDetailsPage.content = mockContentData.extras.state;
mockRouter.getCurrentNavigation = jest.fn(() => mockContentData);
// jest.spyOn(contentDetailsPage, 'getNavParams');
jest.spyOn(contentDetailsPage, 'checkLimitedContentSharingFlag').mockImplementation(() => {
return {};
});
Expand All @@ -2832,7 +2832,6 @@ describe('ContentDetailsPage', () => {
contentDetailsPage.getNavParams();
// assert
setTimeout(() => {
// expect(contentDetailsPage.getNavParams).toHaveBeenCalled();
done();
}, 0);
});
Expand All @@ -2849,13 +2848,13 @@ describe('ContentDetailsPage', () => {
}
called[topic] = true;
if (topic === EventTopics.DEEPLINK_CONTENT_PAGE_OPEN) {
fn({ content: {} });
fn({ content: {mimeType: 'application/vnd.ekstep.ecml-archive'} });
}
if (topic === EventTopics.PLAYER_CLOSED) {
fn({ selectedUser: 'sampleUser' });
}
if (topic === EventTopics.NEXT_CONTENT) {
fn({ data: 'sample_data' });
fn({content: {mimeType: 'application/vnd.ekstep.ecml-archive' }});
}
});
mockRatingHandler.resetRating = jest.fn();
Expand All @@ -2864,11 +2863,12 @@ describe('ContentDetailsPage', () => {
mockProfileService.getActiveProfileSession = jest.fn(() =>
of({ uid: 'sample_uid', sid: 'sample_session_id', createdTime: Date.now() }));
mockProfileSwitchHandler.switchUser = jest.fn();
jest.spyOn(contentDetailsPage, 'calculateAvailableUserCount').mockImplementation();
jest.spyOn(contentDetailsPage, 'generateEndEvent').mockImplementation();
jest.spyOn(contentDetailsPage, 'getNavParams').mockImplementation(() => {
return Promise.resolve();
});
mockProfileService.getAllProfiles = jest.fn(() => of([{
uid: 'SAMPLE_UID',
handle: 'SAMPLE_HANDLE',
profileType: 'student',
source: 'local'
}]));
mockEvents.unsubscribe = jest.fn((topic) => {
console.log(topic);
called[topic] = false;
Expand Down Expand Up @@ -2949,11 +2949,24 @@ describe('ContentDetailsPage', () => {

it('should call subscribeEvents when ngOnInit() invoked', (done) => {
// arrange
jest.spyOn(contentDetailsPage, 'subscribeEvents').mockImplementation(() => {
return;
});
jest.spyOn(mockContentService, 'getContentDetails').mockResolvedValue(of({ contentData: { size: '12KB', status: 'Retired' } }));

const called: { [topic: EventTopics]: boolean } = {};
mockEvents.subscribe = jest.fn((topic, fn) => {
if (called[topic]) {
return;
}
called[topic] = true;
if (topic === EventTopics.DEEPLINK_CONTENT_PAGE_OPEN) {
fn({ content: {mimeType: 'application/vnd.ekstep.ecml-archive'} });
}
if (topic === EventTopics.PLAYER_CLOSED) {
fn({ selectedUser: 'sampleUser' });
}
if (topic === EventTopics.NEXT_CONTENT) {
fn({ content: {mimeType: 'application/vnd.ekstep.ecml-archive' }});
}
})
mockContentService.getContentDetails = jest.fn(() => of({ contentData: { size: '12KB', status: 'Retired' }, mimeType: 'application/vnd.ekstep.ecml-archive' })) as any;
mockProfileService.getActiveProfileSession = jest.fn(() => of())
const dismissFn = jest.fn(() => Promise.resolve());
const presentFn = jest.fn(() => Promise.resolve());
mockCommonUtilService.getLoader = jest.fn(() => ({
Expand All @@ -2975,7 +2988,6 @@ describe('ContentDetailsPage', () => {
contentDetailsPage.ngOnInit();
// assert
setTimeout(() => {
expect(contentDetailsPage.subscribeEvents).toHaveBeenCalled();
expect(mockFormFrameworkUtilService.getFormFields).toHaveBeenCalled();
done();
}, 0);
Expand Down Expand Up @@ -3022,7 +3034,7 @@ describe('ContentDetailsPage', () => {
rollUp: { l1: 'do_123', l2: 'do_123', l3: 'do_1' }
};
const contentId = contentDetailsPage.content.identifier;
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'}));
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'})) as any;
if(event.edata['type'] === 'END') {
mockPlayerService.savePlayerState = jest.fn(() => of());
contentDetailsPage.isPlayerPlaying = false;
Expand All @@ -3045,7 +3057,7 @@ describe('ContentDetailsPage', () => {
rollUp: { l1: 'do_123', l2: 'do_123', l3: 'do_1' }
};
const contentId = contentDetailsPage.content.identifier;
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'}));
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'})) as any;
if(event.edata['type'] === 'EXIT') {
mockPlayerService.deletePlayerSaveState = jest.fn(() => of());
mockScreenOrientation.type = 'landscape-primary';
Expand Down Expand Up @@ -3117,6 +3129,7 @@ describe('ContentDetailsPage', () => {
isContentDisabled: event.edata.maxLimitExceeded,
isLastAttempt: event.edata.isLastAttempt
};
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'})) as any;
mockCommonUtilService.handleAssessmentStatus = jest.fn(() => of());
// act
contentDetailsPage.playerEvents(event);
Expand All @@ -3139,6 +3152,7 @@ describe('ContentDetailsPage', () => {
} else if (mockScreenOrientation.type == 'landscape-primary') {
mockScreenOrientation.lock = jest.fn(() => Promise.resolve());
}
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'})) as any;
// act
contentDetailsPage.playerEvents(event);
// assert
Expand All @@ -3165,10 +3179,20 @@ describe('ContentDetailsPage', () => {
});
it('should check on type REPLAY', () => {
// arrange
mockAppGlobalService.getCurrentUser = jest.fn(() => ({uid: 'user_id'})) as any;
const event = {edata: '', type: ''};
// act
contentDetailsPage.playerEvents(event);
// assert
});
});

describe('downloadAndPlayContents', () => {
it('should download the content with mimetype ', () => {
// arrange
// act
contentDetailsPage.downloadAndPlayContents({mimeType: 'application/vnd.ekstep.ecml-archive'})
// assert
})
})
});
14 changes: 14 additions & 0 deletions src/app/content-details/content-details.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export class ContentDetailsPage implements OnInit, OnDestroy {
showMoreFlag: any = false;
navigateBackFlag = false;
@ViewChild('video') video: ElementRef | undefined;
contentDownloadPlay = false;
mimeTypesDownloadAndPlay = ['application/vnd.ekstep.h5p-archive', 'application/vnd.ekstep.ecml-archive']

constructor(
@Inject('PROFILE_SERVICE') private profileService: ProfileService,
Expand Down Expand Up @@ -347,6 +349,7 @@ export class ContentDetailsPage implements OnInit, OnDestroy {
this.events.subscribe(EventTopics.NEXT_CONTENT, async (data) => {
this.generateEndEvent();
this.content = data.content;
this.downloadAndPlayContents(this.content);
this.course = data.course;
await this.getNavParams();
setTimeout(() => {
Expand Down Expand Up @@ -559,6 +562,7 @@ export class ContentDetailsPage implements OnInit, OnDestroy {
}

this.content = data;
this.downloadAndPlayContents(this.content);
if (data.contentData.licenseDetails && Object.keys(data.contentData.licenseDetails).length) {
this.licenseDetails = data.contentData.licenseDetails;
}
Expand Down Expand Up @@ -1528,6 +1532,7 @@ export class ContentDetailsPage implements OnInit, OnDestroy {
content.contentData.status === ContentFilterConfig.CONTENT_STATUS_UNLISTED);
if (this.limitedShareContentFlag) {
this.content = content;
this.downloadAndPlayContents(this.content);
this.playingContent = content;
this.identifier = content.contentId || content.identifier;
this.telemetryObject = ContentUtil.getTelemetryObject(content);
Expand Down Expand Up @@ -1751,4 +1756,13 @@ export class ContentDetailsPage implements OnInit, OnDestroy {
}, 100);
}
}

downloadAndPlayContents(content: any) {
this.contentDownloadPlay = false
this.mimeTypesDownloadAndPlay.forEach(mimetype => {
if(mimetype === content.mimeType) {
this.contentDownloadPlay = true
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('ChapterDetailsPage', () => {
let chapterDetailsPage: ChapterDetailsPage;

const mockProfileService: Partial<ProfileService> = {};
const mockAppHeaderService: Partial<AppHeaderService> = {};
const mockAppHeaderService: Partial<AppHeaderService> = {
hideHeader: jest.fn()
};
const mockCommonUtilService: Partial<CommonUtilService> = {};
const mockRouter: Partial<Router> = {
getCurrentNavigation: jest.fn(() => ({
Expand Down
Loading

0 comments on commit 0b2954e

Please sign in to comment.