Skip to content

Commit 56b4ee6

Browse files
authored
Enable interactive graphs to take answerless props (#2254)
To prevent cheating, we want to avoid sending exercise answers to the frontend before the learner submits their response. This PR ensures that interactive graphs can render without answers. The types prove that `props.correct` is not used unless the `static` prop is true. Static graphs are not answerable or interactable, and always display the data in the `correct` prop. Issue: LEMS-2853 ## Test plan: `yarn test` Author: benchristel Reviewers: benchristel, handeyeco Required Reviewers: Approved By: handeyeco Checks: ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ 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) Pull Request URL: #2254
1 parent 9dc2f02 commit 56b4ee6

File tree

8 files changed

+311
-274
lines changed

8 files changed

+311
-274
lines changed

.changeset/green-beers-fold.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
"@khanacademy/perseus-core": patch
4+
---
5+
6+
Internal: test that Interactive Graph widgets can render with answerless data

packages/perseus-core/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export {default as getCategorizerPublicWidgetOptions} from "./widgets/categorize
130130
export {default as getCSProgramPublicWidgetOptions} from "./widgets/cs-program/cs-program-util";
131131
export {default as getExpressionPublicWidgetOptions} from "./widgets/expression/expression-util";
132132
export {default as getGrapherPublicWidgetOptions} from "./widgets/grapher/grapher-util";
133-
export {default as getInteractiveGraphPublicWidgetOptions} from "./widgets/interactive-graph/interactive-graph-util";
133+
export {
134+
default as getInteractiveGraphPublicWidgetOptions,
135+
type InteractiveGraphPublicWidgetOptions,
136+
} from "./widgets/interactive-graph/interactive-graph-util";
134137
export {default as getLabelImagePublicWidgetOptions} from "./widgets/label-image/label-image-util";
135138
export {default as getSorterPublicWidgetOptions} from "./widgets/sorter/sorter-util";
136139
export {default as getDropdownPublicWidgetOptions} from "./widgets/dropdown/dropdown-util";

packages/perseus-core/src/widgets/interactive-graph/interactive-graph-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {PerseusInteractiveGraphWidgetOptions} from "@khanacademy/perseus-core";
22

3-
type InteractiveGraphPublicWidgetOptions = Pick<
3+
export type InteractiveGraphPublicWidgetOptions = Pick<
44
PerseusInteractiveGraphWidgetOptions,
55
| "step"
66
| "gridStep"

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
PerseusGraphTypeSegment,
3434
PerseusInteractiveGraphWidgetOptions,
3535
GraphRange,
36+
InteractiveGraphPublicWidgetOptions,
3637
LockedFigure,
3738
PerseusImageBackground,
3839
MarkingsType,
@@ -151,10 +152,12 @@ type RenderProps = {
151152
*/
152153
graph: PerseusGraphType;
153154
/**
154-
* The correct kind of graph, if being used to select function type
155+
* The correct answer for this widget. Will be undefined if the graph is
156+
* being provided answerless data (e.g. because the learner has not yet
157+
* submitted their guess).
155158
*/
156159
// TODO(LEMS-2344): make the type of `correct` more specific
157-
correct: PerseusGraphType;
160+
correct?: PerseusGraphType;
158161
/**
159162
* Shapes (points, chords, etc) displayed on the graph that cannot be moved
160163
* by the user.
@@ -193,6 +196,11 @@ type DefaultProps = {
193196
PerseusInteractiveGraphRubric
194197
> satisfies PropsFor<typeof InteractiveGraph>;
195198

199+
0 as any as WidgetProps<
200+
InteractiveGraphPublicWidgetOptions,
201+
PerseusInteractiveGraphRubric
202+
> satisfies PropsFor<typeof InteractiveGraph>;
203+
196204
// TODO: there's another, very similar getSinusoidCoefficients function
197205
// they should probably be merged
198206
function getSinusoidCoefficients(

packages/perseus/src/widgets/interactive-graphs/__snapshots__/interactive-graph.test.tsx.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Interactive Graph interactive-graph widget A none-type graph renders predictably: first render 1`] = `
3+
exports[`Interactive Graph A none-type graph renders predictably: first render 1`] = `
44
<div>
55
<div
66
class="perseus-renderer perseus-renderer-responsive"
@@ -1038,7 +1038,7 @@ exports[`Interactive Graph interactive-graph widget A none-type graph renders pr
10381038
</div>
10391039
`;
10401040

1041-
exports[`Interactive Graph interactive-graph widget question Should render predictably: after interaction 1`] = `
1041+
exports[`Interactive Graph question Should render predictably: after interaction 1`] = `
10421042
<div>
10431043
<div
10441044
class="perseus-renderer perseus-renderer-responsive"
@@ -1450,7 +1450,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
14501450
</div>
14511451
`;
14521452

1453-
exports[`Interactive Graph interactive-graph widget question Should render predictably: after interaction 2`] = `
1453+
exports[`Interactive Graph question Should render predictably: after interaction 2`] = `
14541454
<div>
14551455
<div
14561456
class="perseus-renderer perseus-renderer-responsive"
@@ -1846,7 +1846,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
18461846
</div>
18471847
`;
18481848

1849-
exports[`Interactive Graph interactive-graph widget question Should render predictably: after interaction 3`] = `
1849+
exports[`Interactive Graph question Should render predictably: after interaction 3`] = `
18501850
<div>
18511851
<div
18521852
class="perseus-renderer perseus-renderer-responsive"
@@ -2075,7 +2075,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
20752075
</div>
20762076
`;
20772077

2078-
exports[`Interactive Graph interactive-graph widget question Should render predictably: after interaction 4`] = `
2078+
exports[`Interactive Graph question Should render predictably: after interaction 4`] = `
20792079
<div>
20802080
<div
20812081
class="perseus-renderer perseus-renderer-responsive"
@@ -2352,7 +2352,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
23522352
</div>
23532353
`;
23542354

2355-
exports[`Interactive Graph interactive-graph widget question Should render predictably: first render 1`] = `
2355+
exports[`Interactive Graph question Should render predictably: first render 1`] = `
23562356
<div>
23572357
<div
23582358
class="perseus-renderer perseus-renderer-responsive"
@@ -2764,7 +2764,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
27642764
</div>
27652765
`;
27662766

2767-
exports[`Interactive Graph interactive-graph widget question Should render predictably: first render 2`] = `
2767+
exports[`Interactive Graph question Should render predictably: first render 2`] = `
27682768
<div>
27692769
<div
27702770
class="perseus-renderer perseus-renderer-responsive"
@@ -3160,7 +3160,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
31603160
</div>
31613161
`;
31623162

3163-
exports[`Interactive Graph interactive-graph widget question Should render predictably: first render 3`] = `
3163+
exports[`Interactive Graph question Should render predictably: first render 3`] = `
31643164
<div>
31653165
<div
31663166
class="perseus-renderer perseus-renderer-responsive"
@@ -3389,7 +3389,7 @@ exports[`Interactive Graph interactive-graph widget question Should render predi
33893389
</div>
33903390
`;
33913391

3392-
exports[`Interactive Graph interactive-graph widget question Should render predictably: first render 4`] = `
3392+
exports[`Interactive Graph question Should render predictably: first render 4`] = `
33933393
<div>
33943394
<div
33953395
class="perseus-renderer perseus-renderer-responsive"

packages/perseus/src/widgets/interactive-graphs/interactive-graph-regression.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {splitPerseusItem} from "@khanacademy/perseus-core";
12
import * as React from "react";
23

34
import {ApiOptions} from "../../perseus-api";
@@ -257,6 +258,12 @@ export const MafsWithPiTicks: Story = {
257258
},
258259
};
259260

261+
export const MafsWithAnswerlessData: Story = {
262+
args: {
263+
question: splitPerseusItem(interactiveGraphQuestionBuilder().build()),
264+
},
265+
};
266+
260267
function MafsQuestionRenderer(props: {question: PerseusRenderer}) {
261268
const {question} = props;
262269
return (

0 commit comments

Comments
 (0)