From 19c21ac1b2bf80e173449a8a4f961c3d1d57a3b1 Mon Sep 17 00:00:00 2001 From: "snehar-ndgit config --global user.name snehar-ndgit config --global user.name snehar-nd" Date: Fri, 3 Mar 2023 16:23:40 +0530 Subject: [PATCH] Issue #IQ-298 fix: QuML Player with configurable score and shuffle the Questions --- projects/quml-demo-app/src/app/app.component.ts | 4 ++-- .../lib/main-player/main-player.component.ts | 2 +- .../section-player.component.spec.data.ts | 3 +++ .../section-player.component.spec.ts | 10 +++++++++- .../section-player/section-player.component.ts | 17 ++++++++++++----- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/projects/quml-demo-app/src/app/app.component.ts b/projects/quml-demo-app/src/app/app.component.ts index fae64717..8ae97bac 100644 --- a/projects/quml-demo-app/src/app/app.component.ts +++ b/projects/quml-demo-app/src/app/app.component.ts @@ -8,7 +8,7 @@ import { DataService } from './services/data.service'; styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { - contentId = 'do_2137436878771650561181'; + contentId = 'do_213742720428564480164'; playerConfig: any; constructor(private dataService: DataService) { } @@ -31,7 +31,7 @@ export class AppComponent implements OnInit { config: config ? config : samplePlayerConfig.config, metadata, data: {} - }; + }; } getPlayerEvents(event) { diff --git a/projects/quml-library/src/lib/main-player/main-player.component.ts b/projects/quml-library/src/lib/main-player/main-player.component.ts index ffd421e9..0dffb042 100644 --- a/projects/quml-library/src/lib/main-player/main-player.component.ts +++ b/projects/quml-library/src/lib/main-player/main-player.component.ts @@ -483,7 +483,7 @@ export class MainPlayerComponent implements OnInit, OnChanges { this.outcomeLabel = this.finalScore.toString(); switch (_.get(this.playerConfig, 'metadata.summaryType')) { case 'Complete': { - this.outcomeLabel = this.totalScore ? `${this.finalScore} / ${this.totalScore}` : this.outcomeLabel; + this.outcomeLabel = this.totalScore ? `${this.finalScore} / ${this.totalScore}` : this.outcomeLabel; break; } case 'Duration': { diff --git a/projects/quml-library/src/lib/section-player/section-player.component.spec.data.ts b/projects/quml-library/src/lib/section-player/section-player.component.spec.data.ts index f447148e..f00189dd 100644 --- a/projects/quml-library/src/lib/section-player/section-player.component.spec.data.ts +++ b/projects/quml-library/src/lib/section-player/section-player.component.spec.data.ts @@ -603,6 +603,9 @@ export const mockSectionPlayerConfig = { }, showFeedback: true, showLegend: true, + metadata:{ + shuffleScore: 3 + } }, changes: { attempts: { diff --git a/projects/quml-library/src/lib/section-player/section-player.component.spec.ts b/projects/quml-library/src/lib/section-player/section-player.component.spec.ts index ab550e62..0395225a 100644 --- a/projects/quml-library/src/lib/section-player/section-player.component.spec.ts +++ b/projects/quml-library/src/lib/section-player/section-player.component.spec.ts @@ -92,8 +92,9 @@ describe('SectionPlayerComponent', () => { expect(component['setConfig']).toHaveBeenCalled(); }); + xit('should subscribeToEvents', () => { - spyOn(viewerService, 'qumlPlayerEvent').and.returnValue(of({})); + spyOn(viewerService, 'qumlPlayerEvent').and.returnValue(of({})); spyOn(component.playerEvent, 'emit'); spyOn(viewerService, 'qumlQuestionEvent').and.returnValue(of({})) component['subscribeToEvents'](); @@ -137,6 +138,13 @@ describe('SectionPlayerComponent', () => { flush(); })); + it('should return success on shuffle score available', fakeAsync(() =>{ + component.parentConfig = mockParentConfig; + spyOn(component,'ngInit').and.callThrough(); + component.ngInit() + expect(component.parentConfig.metadata['shuffleScore']).toBe(3) +})) + it('should remove the attribute from the html element', fakeAsync(() => { const element = document.createElement('div'); spyOn(document, 'querySelector').and.returnValue(element); diff --git a/projects/quml-library/src/lib/section-player/section-player.component.ts b/projects/quml-library/src/lib/section-player/section-player.component.ts index 6d91b72f..bf6492ca 100644 --- a/projects/quml-library/src/lib/section-player/section-player.component.ts +++ b/projects/quml-library/src/lib/section-player/section-player.component.ts @@ -9,7 +9,7 @@ import { ViewerService } from '../services/viewer-service/viewer-service'; import { eventName, pageId, TelemetryType } from '../telemetry-constants'; import { UtilService } from '../util-service'; -const DEFAULT_SCORE: number = 1; +// let this.default_score: number = 1; @Component({ selector: 'quml-section-player', @@ -90,6 +90,7 @@ export class SectionPlayerComponent implements OnChanges, AfterViewInit { isAssessEventRaised = false; isShuffleQuestions = false; shuffleOptions: boolean; + default_score: number = 1; constructor( public viewerService: ViewerService, @@ -98,7 +99,12 @@ export class SectionPlayerComponent implements OnChanges, AfterViewInit { public errorService: ErrorService ) { } - ngOnChanges(changes: SimpleChanges): void { + ngInit(){ + if(this.parentConfig.metadata?.shuffleScore) + this.default_score = this.parentConfig.metadata.shuffleScore + } + + ngOnChanges(changes: SimpleChanges): void { /* istanbul ignore else */ if (changes && Object.values(changes)[0].firstChange) { this.subscribeToEvents(); @@ -155,7 +161,7 @@ export class SectionPlayerComponent implements OnChanges, AfterViewInit { } if (this.currentSlideIndex === 0) { - if (this.showStartPage) { + if (this.showStartPage) { this.active = this.sectionIndex === 0; } else { setTimeout(() => { this.nextSlide(); }); @@ -435,7 +441,7 @@ export class SectionPlayerComponent implements OnChanges, AfterViewInit { const currentIndex = this.myCarousel.getCurrentSlideIndex() - 1; if (this.isShuffleQuestions) { - this.updateScoreBoard(currentIndex, 'correct', undefined, DEFAULT_SCORE); + this.updateScoreBoard(currentIndex, 'correct', undefined, this.default_score); } } @@ -903,9 +909,10 @@ export class SectionPlayerComponent implements OnChanges, AfterViewInit { getScore(currentIndex, key, isCorrectAnswer, selectedOption?) { /* istanbul ignore else */ + if (isCorrectAnswer) { if (this.isShuffleQuestions) { - return DEFAULT_SCORE; + return this.default_score; } return this.questions[currentIndex].responseDeclaration[key].correctResponse.outcomes.SCORE ? this.questions[currentIndex].responseDeclaration[key].correctResponse.outcomes.SCORE :