-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Dialog Guidance): Show different feedback for same FeedbackRule (#…
…581) * feat(Dialog Guidance): Show different feedback for same FeedbackRule Add check for version in content. V2 assumes that each feedback rule has an id, and uses the id to determine if student hit the same FeedbackRule before, and which feedback within that rule to show next (use mod). #578 * fix(Dialog Guidance): Properly handle default feedback in version 2 #578 Co-authored-by: Geoffrey Kwan <geoffreykwan@gmail.com>
- Loading branch information
1 parent
c8ebb8a
commit ccac2bf
Showing
9 changed files
with
155 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { DialogGuidanceStudentComponent } from '../../assets/wise5/components/dialogGuidance/dialog-guidance-student/dialog-guidance-student.component'; | ||
import { FeedbackRule } from '../../assets/wise5/components/dialogGuidance/FeedbackRule'; | ||
import { DialogGuidanceFeedbackService } from '../../assets/wise5/services/dialogGuidanceFeedbackService'; | ||
import { StudentDataService } from '../../assets/wise5/services/studentDataService'; | ||
|
||
let service: DialogGuidanceFeedbackService; | ||
let studentDataService: StudentDataService; | ||
let component: DialogGuidanceStudentComponent; | ||
let feedbackRuleV1: FeedbackRule; | ||
let feedbackRuleV2_1: FeedbackRule; | ||
|
||
class StudentDataServiceMock { | ||
getLatestSubmitComponentState() {} | ||
} | ||
|
||
class DialogGuidanceStudentComponentMock { | ||
nodeId = 'node1'; | ||
componentId = 'componentA'; | ||
isVersion1() {} | ||
isVersion2() {} | ||
} | ||
|
||
describe('DialogGuidanceFeedbackService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
providers: [ | ||
DialogGuidanceFeedbackService, | ||
{ provide: StudentDataService, useClass: StudentDataServiceMock }, | ||
{ provide: DialogGuidanceStudentComponent, useClass: DialogGuidanceStudentComponentMock } | ||
] | ||
}); | ||
component = TestBed.inject(DialogGuidanceStudentComponent); | ||
service = TestBed.inject(DialogGuidanceFeedbackService); | ||
studentDataService = TestBed.inject(StudentDataService); | ||
feedbackRuleV1 = new FeedbackRule(); | ||
feedbackRuleV1.feedback = 'feedbackRuleV1'; | ||
feedbackRuleV2_1 = new FeedbackRule(); | ||
feedbackRuleV2_1.id = 'feedbackRuleV2_1'; | ||
feedbackRuleV2_1.feedback = ['feedbackRuleV2_1 1', 'feedbackRuleV2_1 2']; | ||
}); | ||
getFeedbackTextV1(); | ||
getFeedbackTextV2(); | ||
}); | ||
|
||
function getFeedbackTextV1() { | ||
describe('getFeedbackText() in version 1 one feedbacks per each idea', () => { | ||
beforeEach(() => { | ||
spyOn(component, 'isVersion1').and.returnValue(true); | ||
}); | ||
it('should return feedback in the feedback rule', () => { | ||
expect(service.getFeedbackText(component, feedbackRuleV1)).toEqual('feedbackRuleV1'); | ||
}); | ||
}); | ||
} | ||
|
||
function getFeedbackTextV2() { | ||
describe('getFeedbackText() in version 2 (multiple feedbacks per same idea)', () => { | ||
beforeEach(() => { | ||
spyOn(component, 'isVersion1').and.returnValue(false); | ||
}); | ||
it('should return first feedback the first time', () => { | ||
spyOn(studentDataService, 'getLatestSubmitComponentState').and.returnValue({ | ||
studentData: { responses: [] } | ||
}); | ||
expect(service.getFeedbackText(component, feedbackRuleV2_1)).toEqual('feedbackRuleV2_1 1'); | ||
}); | ||
it('should return second feedback the second time', () => { | ||
spyOn(studentDataService, 'getLatestSubmitComponentState').and.returnValue({ | ||
studentData: { responses: [{ feedbackRuleId: 'feedbackRuleV2_1' }] } | ||
}); | ||
expect(service.getFeedbackText(component, feedbackRuleV2_1)).toEqual('feedbackRuleV2_1 2'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/assets/wise5/services/dialogGuidanceFeedbackService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { DialogGuidanceStudentComponent } from '../components/dialogGuidance/dialog-guidance-student/dialog-guidance-student.component'; | ||
import { FeedbackRule } from '../components/dialogGuidance/FeedbackRule'; | ||
import { StudentDataService } from './studentDataService'; | ||
|
||
@Injectable() | ||
export class DialogGuidanceFeedbackService { | ||
constructor(private studentDataService: StudentDataService) {} | ||
|
||
getFeedbackText(component: DialogGuidanceStudentComponent, feedbackRule: FeedbackRule): string { | ||
return component.isVersion1() | ||
? <string>feedbackRule.feedback | ||
: this.getFeedbackTextVersion2(component, feedbackRule); | ||
} | ||
|
||
private getFeedbackTextVersion2( | ||
component: DialogGuidanceStudentComponent, | ||
feedbackRule: FeedbackRule | ||
) { | ||
const latestSubmitComponentState = this.studentDataService.getLatestSubmitComponentState( | ||
component.nodeId, | ||
component.componentId | ||
); | ||
return feedbackRule.feedback[ | ||
this.getCountFeedbackRuleShown(latestSubmitComponentState, feedbackRule) % | ||
feedbackRule.feedback.length | ||
]; | ||
} | ||
|
||
private getCountFeedbackRuleShown( | ||
latestSubmitComponentState: any, | ||
feedbackRule: FeedbackRule | ||
): number { | ||
return latestSubmitComponentState == null | ||
? 0 | ||
: latestSubmitComponentState.studentData.responses.filter( | ||
(response) => response.feedbackRuleId === feedbackRule.id | ||
).length; | ||
} | ||
} |