Skip to content

Commit

Permalink
Add and pass one regression test for radio widget parser (#1871)
Browse files Browse the repository at this point in the history
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
benchristel authored Nov 19, 2024
1 parent 7ca5bbf commit 5003151
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/mean-pens-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: Add regression tests for PerseusItem parser
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export const parseRadioWidget: Parser<RadioWidget> = parseWidget(
displayCount: optional(any),
// v0 props
// `noneOfTheAbove` is still in use (but only set to `false`).
noneOfTheAbove: constant(false),
noneOfTheAbove: optional(constant(false)),
}),
);
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": []
}
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"}));
});
});

0 comments on commit 5003151

Please sign in to comment.