Skip to content

Commit 304c071

Browse files
authored
Default the correct prop to graph in the interactive graph editor if its type is wrong (#3264)
## Summary: See the linked issue for context. Issue: https://khanacademy.atlassian.net/browse/LEMS-3903 Test plan: Upgrade Perseus in frontend. Confirm in the AX editor that the bug is fixed. Verify that you can change the type of the graph and the editor and preview update accordingly. Author: benchristel Reviewers: nishasy, daniellewhyte Required Reviewers: Approved By: nishasy Checks: ⏭️ 1 check has been skipped, ✅ 10 checks were successful Pull Request URL: #3264
1 parent 2d5364d commit 304c071

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.changeset/four-wolves-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus-editor": patch
3+
---
4+
5+
Ensure the `correct` prop of interactive graphs matches the type of the `graph` prop. This works around a bug in the AX editor.

packages/perseus-editor/src/widgets/__tests__/interactive-graph-editor.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,29 @@ describe("InteractiveGraphEditor", () => {
815815
expect(screen.getByRole("option", {name: "None"})).toBeInTheDocument();
816816
});
817817

818+
test("fixes a `correct` prop with the wrong graph type, defaulting it to `graph`", () => {
819+
// This behavior is a workaround for the AX editor, which passes
820+
// answerless data to the editor in question stems. The value of
821+
// `correct` always defaults to `{type: "linear"}` when answerless
822+
// data is used. This caused a bug where a movable line was
823+
// incorrectly displayed on none-type graphs in the editor.
824+
// See: https://khanacademy.atlassian.net/browse/LEMS-3903
825+
render(
826+
<InteractiveGraphEditor
827+
{...baseProps}
828+
graph={{type: "none"}}
829+
correct={{type: "linear"}}
830+
/>,
831+
{
832+
wrapper: RenderStateRoot,
833+
},
834+
);
835+
836+
// Assert:
837+
// A none-type graph should render; there should be no movable points.
838+
expect(screen.queryByLabelText(/point/i)).not.toBeInTheDocument();
839+
});
840+
818841
test.each`
819842
graphType | expectedNumber | correctAnswer
820843
${"linear"} | ${1} | ${"y = 5.000"}

packages/perseus-editor/src/widgets/interactive-graph-editor/interactive-graph-editor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,13 @@ class InteractiveGraphEditor extends React.Component<Props> {
288288
const sizeClass = containerSizeClass.SMALL;
289289

290290
if (this.props.valid === true) {
291-
const correct = this.props.correct;
291+
// Default `correct` to `graph` if the type is wrong. This works
292+
// around a bug in the AX editor.
293+
// See: https://khanacademy.atlassian.net/browse/LEMS-3903
294+
const correct =
295+
this.props.correct.type === this.props.graph?.type
296+
? this.props.correct
297+
: this.props.graph;
292298

293299
const graphProps = {
294300
ref: "graph",

0 commit comments

Comments
 (0)