Skip to content

Commit

Permalink
Add snapshot tests for parseAndTypecheckPerseusItem (#1887)
Browse files Browse the repository at this point in the history
The other regression tests only assert that we can successfully parse each
assessmentItem in the regression dataset. However, a successful parse doesn't
necessarily mean we preserved all input data or migrated it correctly to the
latest format.

This PR adds snapshot tests to fix that gap in our coverage.

Issue: none

## Test plan:

`yarn test`

Author: benchristel

Reviewers: jeremywiebe, anakaren-rojas, nishasy

Required Reviewers:

Approved By: jeremywiebe

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1887
  • Loading branch information
benchristel authored Nov 20, 2024
1 parent 44933f8 commit 4c2db8d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-jobs-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: add snapshot tests for `parseAndTypecheckPerseusItem`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`parseAndTypecheckPerseusItem correctly parses data/radio-missing-noneOfTheAbove.json 1`] = `
{
"answer": undefined,
"answerArea": {
"calculator": false,
"chi2Table": false,
"periodicTable": false,
"tTable": false,
"zTable": false,
},
"hints": [],
"itemDataVersion": {
"major": 0,
"minor": 1,
},
"question": {
"content": "$\\begin{align}
A &= \\{x: x \\text{ is a rectangle in the plane P} \\} \\\\\\\\
B &= \\{x: x \\text{ is a square in the plane P} \\}
\\end{align}$
**Is $A \\subset B$ ?**
[[☃ radio 1]]
",
"images": {},
"metadata": undefined,
"widgets": {
"radio 1": {
"alignment": "default",
"graded": true,
"key": undefined,
"options": {
"choices": [
{
"clue": undefined,
"content": "Yes",
"correct": false,
"isNoneOfTheAbove": undefined,
"widgets": undefined,
},
{
"clue": undefined,
"content": "No",
"correct": true,
"isNoneOfTheAbove": undefined,
"widgets": undefined,
},
],
"countChoices": false,
"deselectEnabled": false,
"displayCount": null,
"hasNoneOfTheAbove": false,
"multipleSelect": false,
"noneOfTheAbove": undefined,
"onePerLine": undefined,
"randomize": false,
},
"static": false,
"type": "radio",
"version": {
"major": 1,
"minor": 0,
},
},
},
},
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as fs from "fs";
import {join} from "path";

import {parseAndTypecheckPerseusItem} from "../index";
import {assertSuccess} from "../result";

const dataFiles = fs.readdirSync(join(__dirname, "data"));

// If you change the parsers to migrate/convert data to a new format, you may
// have to regenerate these snapshots. That's expected and okay!

describe("parseAndTypecheckPerseusItem", () => {
it.each(dataFiles)("correctly parses data/%s", (filename) => {
const json = fs.readFileSync(
join(__dirname, "data", filename),
"utf-8",
);
const result = parseAndTypecheckPerseusItem(json);
assertSuccess(result);
expect(result.value).toMatchSnapshot();
});
});

0 comments on commit 4c2db8d

Please sign in to comment.