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 #IQ-298 fix: QuML Player with configurable score and shuffle th… #12

Open
wants to merge 1 commit into
base: bootcamp
Choose a base branch
from
Open
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 projects/quml-demo-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand All @@ -31,7 +31,7 @@ export class AppComponent implements OnInit {
config: config ? config : samplePlayerConfig.config,
metadata,
data: {}
};
};
}

getPlayerEvents(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ export const mockSectionPlayerConfig = {
},
showFeedback: true,
showLegend: true,
metadata:{
shuffleScore: 3
}
},
changes: {
attempts: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -90,6 +90,7 @@ export class SectionPlayerComponent implements OnChanges, AfterViewInit {
isAssessEventRaised = false;
isShuffleQuestions = false;
shuffleOptions: boolean;
default_score: number = 1;

constructor(
public viewerService: ViewerService,
Expand All @@ -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();
Expand Down Expand Up @@ -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(); });
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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 :
Expand Down