Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #ED-0000 fix: ecml player download and play and updated test case #3646

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 20 additions & 8 deletions src/app/profile/categories-edit/categories-edit.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { CategoriesEditPage } from './categories-edit.page';
import {
FrameworkService,
FrameworkUtilService,
ProfileService
ProfileService,
CachedItemRequestSourceFrom,
Framework, FrameworkCategoryCodesGroup,
GetSuggestedFrameworksRequest, SharedPreferences,
UpdateServerProfileInfoRequest
} from '@project-sunbird/sunbird-sdk';
import { TranslateService } from '@ngx-translate/core';
import { Platform } from '@ionic/angular';
import { Events } from '../../../util/events';
import { Router, ActivatedRoute, NavigationExtras } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import {
AppGlobalService,
CommonUtilService,
Expand All @@ -23,8 +27,7 @@ import { ProfileHandler } from '../../services/profile-handler';
import { SbProgressLoader } from '../../../services/sb-progress-loader.service';
import { ExternalIdVerificationService } from '../../services/externalid-verification.service';
import { TncUpdateHandlerService } from '../../services/handlers/tnc-update-handler.service';
import { of, throwError } from 'rxjs';
import { CachedItemRequestSourceFrom, Framework, FrameworkCategoryCodesGroup, GetSuggestedFrameworksRequest, SharedPreferences, UpdateServerProfileInfoRequest } from '@project-sunbird/sunbird-sdk';
import { of } from 'rxjs';
import { PreferenceKey, ProfileConstants, RouterLinks } from '../../app.constant';
import { SegmentationTagService } from '../../../services/segmentation-tag/segmentation-tag.service';
import { CategoriesEditService } from './categories-edit.service';
Expand Down Expand Up @@ -1275,6 +1278,7 @@ describe('CategoryEditPage', () => {
boards: []
}
} as any;
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
categoryEditPage.isBoardAvailable = true;
categoryEditPage.showOnlyMandatoryFields = false;
mockCommonUtilService.showToast = jest.fn();
Expand All @@ -1294,6 +1298,7 @@ describe('CategoryEditPage', () => {
medium: []
}
} as any;
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
categoryEditPage.supportedProfileAttributes = { medium: 'sample-medium' };
categoryEditPage.showOnlyMandatoryFields = true;
const openFn = jest.fn(() => Promise.resolve());
Expand All @@ -1316,6 +1321,7 @@ describe('CategoryEditPage', () => {
medium: []
}
} as any;
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
categoryEditPage.supportedProfileAttributes = { medium: 'sample-medium' };
categoryEditPage.showOnlyMandatoryFields = false;
mockCommonUtilService.showToast = jest.fn();
Expand All @@ -1339,6 +1345,7 @@ describe('CategoryEditPage', () => {
grades: []
}
} as any;
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
categoryEditPage.supportedProfileAttributes = { gradeLevel: 'sample-gradeLevel' };
categoryEditPage.showOnlyMandatoryFields = true;
const openFn = jest.fn(() => Promise.resolve());
Expand Down Expand Up @@ -1380,11 +1387,13 @@ describe('CategoryEditPage', () => {
// arrange
categoryEditPage.profileEditForm = {
value: {
boards: ['cbsc'],
boards: ['ka'],
medium: ['english'],
grades: ['class 1']
grades: ['ka']
}
} as any;
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
mockProfileService.updateServerProfile = jest.fn(() => of())
// act
categoryEditPage.onSubmit();
// assert
Expand Down Expand Up @@ -1412,7 +1421,7 @@ describe('CategoryEditPage', () => {
// arrange
categoryEditPage.profileEditForm = {
value: {
boards: ['cbsc'],
boards: ['ka'],
medium: ['english'],
grades: ['class 1']
}
Expand Down Expand Up @@ -1461,6 +1470,7 @@ describe('CategoryEditPage', () => {
mockCommonUtilService.getLoader = jest.fn(() => Promise.resolve({
present: presentFn
}));
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
categoryEditPage.isBoardAvailable = false;
const req: UpdateServerProfileInfoRequest = { userId: 'sample_uid',
framework: {} }
Expand Down Expand Up @@ -1500,6 +1510,7 @@ describe('CategoryEditPage', () => {
categoryEditPage.isBoardAvailable = true;
const req: UpdateServerProfileInfoRequest = { userId: 'sample_uid',
framework: {} }
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
const formVal = { grades: [ 'class 1' ], subjects:['english'] };
mockProfileService.updateServerProfile = jest.fn(() => of({req} as any));
//act
Expand All @@ -1514,10 +1525,11 @@ describe('CategoryEditPage', () => {
mockCommonUtilService.getLoader = jest.fn(() => Promise.resolve({
present: presentFn
}));
categoryEditPage.mediumList = [{name: 'english', code:'english'}]
categoryEditPage.isBoardAvailable = true;
const req: UpdateServerProfileInfoRequest = { userId: 'sample_uid',
framework: {} }
const formVal = { syllabus: 'cbsc', boards:'board', medium: 'english', grades: 'class 1', subjects: 'english' };
const formVal = { syllabus: 'cbsc', boards:['ka'], medium: ['english'], grades: ['class 1'], subjects: ['english'] };
mockProfileService.updateServerProfile = jest.fn(() => of({req} as any));
//act
categoryEditPage.submitForm(formVal);
Expand Down
2 changes: 1 addition & 1 deletion src/app/qrcoderesult/qrcoderesult.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h6 class="name font-size-20">{{content?.contentData?.name}}</h6>
</button>
</ion-col>
<ion-col class="ion-no-padding"
*ngIf="content.contentData?.streamingUrl && !(content.mimeType === 'application/vnd.ekstep.h5p-archive')">
*ngIf="content.contentData?.streamingUrl && !(content.mimeType === 'application/vnd.ekstep.h5p-archive' || content.mimeType === 'application/vnd.ekstep.ecml-archive')">
<button class="custom-btn play qr-result-btn ion-no-padding" expand="block" (click)="playContent(content, true)">
<ion-icon name="play" style="margin-left: -1rem;"></ion-icon>&nbsp;<span class="play-btn-info">{{'PLAY' | translate}}</span>
</button>
Expand Down
1 change: 1 addition & 0 deletions src/services/download-pdf/download-pdf.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,4 @@ describe('DownloadPdfService', () => {
});
});
});
})