-
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 ChoseChoice token
- Loading branch information
1 parent
21d0fc6
commit 3d119a1
Showing
16 changed files
with
144 additions
and
29 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
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
33 changes: 33 additions & 0 deletions
33
...ssets/wise5/components/common/feedbackRule/TermEvaluator/ChoseChoiceTermEvaluator.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,33 @@ | ||
import { ConstraintService } from '../../../../services/constraintService'; | ||
import { CRaterResponse } from '../../cRater/CRaterResponse'; | ||
import { ChoseChoiceTermEvaluator } from './ChoseChoiceTermEvaluator'; | ||
|
||
class ConstraintServiceStub { | ||
evaluateCriteria(criteria: any): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
describe('ChoseChoiceTermEvaluator', () => { | ||
let evaluator1, mockConstraintService; | ||
beforeEach(() => { | ||
evaluator1 = new ChoseChoiceTermEvaluator('choseChoice("node1", "componentA", "choice1")'); | ||
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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/assets/wise5/components/common/feedbackRule/TermEvaluator/ChoseChoiceTermEvaluator.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,27 @@ | ||
import { CRaterResponse } from '../../cRater/CRaterResponse'; | ||
import { TermEvaluator } from './TermEvaluator'; | ||
|
||
export class ChoseChoiceTermEvaluator extends TermEvaluator { | ||
private nodeId: string; | ||
private componentId: string; | ||
private choiceId: string; | ||
|
||
constructor(term: string) { | ||
super(term); | ||
const matches = term.match(/choseChoice\("(\w+)",\s*"(\w+)",\s*"(\w+)"\)/); | ||
this.nodeId = matches[1]; | ||
this.componentId = matches[2]; | ||
this.choiceId = matches[3]; | ||
} | ||
|
||
evaluate(response: CRaterResponse | CRaterResponse[]): boolean { | ||
return this.constraintService.evaluateCriteria({ | ||
name: 'choiceChosen', | ||
params: { | ||
nodeId: this.nodeId, | ||
componentId: this.componentId, | ||
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
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
Oops, something went wrong.