-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and pass one regression test for radio widget parser (#1871)
This PR is a "pilot" demonstrating how regression testing for the PerseusItem parser will work. The regression test uses production data found by running the [exhaustive test tool][1]. [1]: #1864 Issue: LEMS-2582 ## Test plan: `yarn test` Author: benchristel Reviewers: benchristel, mark-fitzgerald, jeremywiebe, anakaren-rojas, catandthemachines, nishasy Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1871
- Loading branch information
1 parent
7ca5bbf
commit 5003151
Showing
4 changed files
with
74 additions
and
1 deletion.
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,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Internal: Add regression tests for PerseusItem parser |
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
48 changes: 48 additions & 0 deletions
48
...rseus/src/util/parse-perseus-json/regression-tests/data/radio-missing-noneOfTheAbove.json
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,48 @@ | ||
{ | ||
"question": { | ||
"content": "$\\begin{align} \nA &= \\{x: x \\text{ is a rectangle in the plane P} \\} \\\\\\\\\nB &= \\{x: x \\text{ is a square in the plane P} \\}\n\\end{align}$\n\n**Is $A \\subset B$ ?**\n\n[[☃ radio 1]]\n", | ||
"images": {}, | ||
"widgets": { | ||
"radio 1": { | ||
"type": "radio", | ||
"alignment": "default", | ||
"static": false, | ||
"graded": true, | ||
"options": { | ||
"choices": [ | ||
{ | ||
"content": "Yes", | ||
"correct": false | ||
}, | ||
{ | ||
"content": "No", | ||
"correct": true | ||
} | ||
], | ||
"randomize": false, | ||
"multipleSelect": false, | ||
"countChoices": false, | ||
"displayCount": null, | ||
"hasNoneOfTheAbove": false, | ||
"deselectEnabled": false | ||
}, | ||
"version": { | ||
"major": 1, | ||
"minor": 0 | ||
} | ||
} | ||
} | ||
}, | ||
"answerArea": { | ||
"calculator": false, | ||
"chi2Table": false, | ||
"periodicTable": false, | ||
"tTable": false, | ||
"zTable": false | ||
}, | ||
"itemDataVersion": { | ||
"major": 0, | ||
"minor": 1 | ||
}, | ||
"hints": [] | ||
} |
20 changes: 20 additions & 0 deletions
20
...erseus/src/util/parse-perseus-json/regression-tests/parse-perseus-json-regression.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,20 @@ | ||
import * as fs from "fs"; | ||
import {join} from "path"; | ||
|
||
import {parseAndTypecheckPerseusItem} from "../index"; | ||
|
||
const dataFiles = fs.readdirSync(join(__dirname, "data")); | ||
|
||
describe("parseAndTypecheckPerseusItem", () => { | ||
it.each(dataFiles)("accepts data/%s", (filename) => { | ||
const json = fs.readFileSync( | ||
join(__dirname, "data", filename), | ||
"utf-8", | ||
); | ||
const result = parseAndTypecheckPerseusItem(json); | ||
|
||
// This strange-looking assertion style results in the failure message | ||
// being printed if parsing fails, so the test is easier to debug. | ||
expect(result).toEqual(expect.objectContaining({type: "success"})); | ||
}); | ||
}); |