-
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(Feedback Rule): New myChoiceChosen token (#1410)
- Loading branch information
1 parent
5a98b9e
commit c6c1d64
Showing
28 changed files
with
406 additions
and
205 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
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
11 changes: 4 additions & 7 deletions
11
src/assets/wise5/components/common/cRater/CRaterResponse.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
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
14 changes: 14 additions & 0 deletions
14
src/assets/wise5/components/common/feedbackRule/Response.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,14 @@ | ||
export class Response { | ||
submitCounter: number; | ||
constructor(jsonObject: any = {}) { | ||
this.populateFields(jsonObject); | ||
} | ||
|
||
protected populateFields(jsonObject: any = {}): void { | ||
for (const key of Object.keys(jsonObject)) { | ||
if (jsonObject[key] != null) { | ||
this[key] = jsonObject[key]; | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ts/wise5/components/common/feedbackRule/TermEvaluator/MyChoiceChosenTermEvaluator.spec.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,38 @@ | ||
import { Component } from '../../../../common/Component'; | ||
import { ComponentContent } from '../../../../common/ComponentContent'; | ||
import { ConstraintService } from '../../../../services/constraintService'; | ||
import { CRaterResponse } from '../../cRater/CRaterResponse'; | ||
import { MyChoiceChosenTermEvaluator } from './MyChoiceChosenTermEvaluator'; | ||
|
||
class ConstraintServiceStub { | ||
evaluateCriteria(criteria: any): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
describe('MyChoiceChosenTermEvaluator', () => { | ||
let evaluator1, mockConstraintService; | ||
beforeEach(() => { | ||
evaluator1 = new MyChoiceChosenTermEvaluator('myChoiceChosen("choice1")'); | ||
evaluator1.setReferenceComponent( | ||
new Component({ id: 'componentA' } as ComponentContent, 'node1') | ||
); | ||
mockConstraintService = new ConstraintServiceStub(); | ||
evaluator1.setConstraintService(mockConstraintService as ConstraintService); | ||
}); | ||
describe('evaluate()', () => { | ||
[ | ||
{ description: 'choice is chosen', choiceChosen: true, expected: true }, | ||
{ description: 'choice is not chosen', choiceChosen: false, expected: false } | ||
].forEach(({ description, choiceChosen, expected }) => { | ||
describe(description, () => { | ||
beforeEach(() => { | ||
spyOn(mockConstraintService, 'evaluateCriteria').and.returnValue(choiceChosen); | ||
}); | ||
it(`returns ${expected}`, () => { | ||
expect(evaluator1.evaluate(new CRaterResponse())).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/assets/wise5/components/common/feedbackRule/TermEvaluator/MyChoiceChosenTermEvaluator.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,22 @@ | ||
import { Response } from '../Response'; | ||
import { TermEvaluator } from './TermEvaluator'; | ||
|
||
export class MyChoiceChosenTermEvaluator extends TermEvaluator { | ||
private choiceId: string; | ||
|
||
constructor(term: string) { | ||
super(term); | ||
this.choiceId = term.match(/myChoiceChosen\("(\w+)"\)/)[1]; | ||
} | ||
|
||
evaluate(response: Response | Response[]): boolean { | ||
return this.constraintService.evaluateCriteria({ | ||
name: 'choiceChosen', | ||
params: { | ||
nodeId: this.referenceComponent.nodeId, | ||
componentId: this.referenceComponent.id, | ||
choiceIds: this.choiceId | ||
} | ||
}); | ||
} | ||
} |
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
7 changes: 6 additions & 1 deletion
7
src/assets/wise5/components/common/feedbackRule/TermEvaluator/TermEvaluatorFactory.spec.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
Oops, something went wrong.