-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary: So this focuses on `numCorrect` which originally derived from the answers but now is its own widget option. I'm sure there's an argument that this also shouldn't be sent to the FE, but it's conditionally used to render help text: `Select 2 answers`. I don't know, I don't think it's that big of a deal to have it but I also made it optional so we can remove it from questions that don't need it: `needsNumCorrect = options.multipleSelect === true && options.countChoices === true`. The important thing is that we can render, answer, and score a Radio widget that's been stripped of answers. As far as I can tell, this supports all behavior pre-scoring. Issue: LEMS-2849 ## Test plan: Radio should continue to be renderable, answerable, and scorable. Author: handeyeco Reviewers: handeyeco, benchristel, jeremywiebe, Myranae Required Reviewers: Approved By: benchristel, jeremywiebe Checks: ✅ 8 checks were successful Pull Request URL: #2233
- Loading branch information
Showing
23 changed files
with
895 additions
and
250 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,7 @@ | ||
--- | ||
"@khanacademy/perseus": major | ||
"@khanacademy/perseus-core": major | ||
"@khanacademy/perseus-editor": patch | ||
--- | ||
|
||
RadioWidget v2 in support of answerless Radio |
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
81 changes: 81 additions & 0 deletions
81
packages/perseus-core/src/parse-perseus-json/perseus-parsers/radio-widget.test.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,81 @@ | ||
import {parse} from "../parse"; | ||
import {failure, success} from "../result"; | ||
|
||
import {parseRadioWidget} from "./radio-widget"; | ||
|
||
describe("parseRadioWidget", () => { | ||
it("migrates v1 options to v2", () => { | ||
const widget = { | ||
type: "radio", | ||
graded: true, | ||
options: { | ||
choices: [ | ||
{ | ||
content: "Correct 1", | ||
correct: true, | ||
}, | ||
{ | ||
content: "Correct 2", | ||
correct: true, | ||
}, | ||
{ | ||
content: "Incorrect", | ||
correct: false, | ||
}, | ||
], | ||
}, | ||
version: { | ||
major: 1, | ||
minor: 0, | ||
}, | ||
}; | ||
|
||
expect(parse(widget, parseRadioWidget)).toEqual( | ||
success({ | ||
type: "radio", | ||
graded: true, | ||
options: { | ||
choices: [ | ||
{ | ||
content: "Correct 1", | ||
correct: true, | ||
}, | ||
{ | ||
content: "Correct 2", | ||
correct: true, | ||
}, | ||
{ | ||
content: "Incorrect", | ||
correct: false, | ||
}, | ||
], | ||
numCorrect: 2, | ||
}, | ||
version: { | ||
major: 2, | ||
minor: 0, | ||
}, | ||
}), | ||
); | ||
}); | ||
|
||
it("rejects a widget with unrecognized version", () => { | ||
const widget = { | ||
type: "radio", | ||
version: { | ||
major: -1, | ||
minor: 0, | ||
}, | ||
graded: true, | ||
options: {}, | ||
}; | ||
|
||
expect(parse(widget, parseRadioWidget)).toEqual( | ||
failure( | ||
expect.stringContaining( | ||
"At (root) -- expected widget options with a known version number", | ||
), | ||
), | ||
); | ||
}); | ||
}); |
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.