Skip to content

Commit ad871e0

Browse files
[numeric-no-underscore] PR Feedback
1 parent 1051dc3 commit ad871e0

File tree

3 files changed

+20
-44
lines changed

3 files changed

+20
-44
lines changed

packages/perseus-core/src/data-schema.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1164,17 +1164,15 @@ export type MathFormat =
11641164
| "pi";
11651165

11661166
export type PerseusNumericInputAnswerForm = {
1167-
simplify: PerseusNumericInputSimplify;
1167+
simplify: PerseusNumericInputSimplify | null | undefined;
11681168
name: MathFormat;
11691169
};
11701170

11711171
export type PerseusNumericInputSimplify =
11721172
| "required"
11731173
| "correct"
11741174
| "enforced"
1175-
| "optional"
1176-
| null
1177-
| undefined;
1175+
| "optional";
11781176

11791177
export type PerseusNumericInputWidgetOptions = {
11801178
// A list of all the possible correct and incorrect answers
@@ -1212,7 +1210,7 @@ export type PerseusNumericInputAnswer = {
12121210
// NOTE: perseus_data.go says this is non-nullable even though we handle null values.
12131211
maxError: number | null | undefined;
12141212
// Unsimplified answers are Ungraded, Accepted, or Wrong. Options: "required", "correct", or "enforced"
1215-
simplify: PerseusNumericInputSimplify;
1213+
simplify: PerseusNumericInputSimplify | null | undefined;
12161214
};
12171215

12181216
export type PerseusNumberLineWidgetOptions = {

packages/perseus/src/widgets/numeric-input/numeric-input.class.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ type RenderProps = {
169169
const propsTransform = function (
170170
widgetOptions: PerseusNumericInputWidgetOptions,
171171
): RenderProps {
172-
const rendererProps: RenderProps & {answers?: any} = {
172+
// Omit the answers from the widget options since they are
173+
// not needed for rendering the widget.
174+
const {answers: _, ...rendererProps} = {
173175
...widgetOptions,
174176
answerForms: unionAnswerForms(
175177
widgetOptions.answers.map((answer) => {
@@ -183,7 +185,6 @@ const propsTransform = function (
183185
),
184186
};
185187

186-
delete rendererProps.answers;
187188
return rendererProps;
188189
};
189190

packages/perseus/src/widgets/numeric-input/utils.test.ts

+14-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import {mockStrings} from "../../strings";
2+
13
import {generateExamples, shouldShowExamples, unionAnswerForms} from "./utils";
24

3-
import type {PerseusStrings} from "../../strings";
45
import type {PerseusNumericInputAnswerForm} from "@khanacademy/perseus-core";
56

67
describe("generateExamples", () => {
@@ -16,23 +17,15 @@ describe("generateExamples", () => {
1617
simplify: "required",
1718
},
1819
];
19-
const fakePerseusStrings: Partial<PerseusStrings> = {
20-
yourAnswer: "Your answer",
21-
integerExample: "Integer example",
22-
properExample: "Proper example",
23-
simplifiedProperExample: "Simplified proper example",
24-
};
20+
2521
const expected = [
26-
"Your answer",
27-
"Integer example",
28-
"Simplified proper example",
22+
"**Your answer should be** ",
23+
"an integer, like $6$",
24+
"a *simplified proper* fraction, like $3/5$",
2925
];
3026

3127
// Act
32-
const result = generateExamples(
33-
answerForms,
34-
fakePerseusStrings as PerseusStrings,
35-
);
28+
const result = generateExamples(answerForms, mockStrings);
3629

3730
// Assert
3831
expect(result).toEqual(expected);
@@ -54,23 +47,15 @@ describe("generateExamples", () => {
5447
simplify: "required",
5548
},
5649
];
57-
const fakePerseusStrings: Partial<PerseusStrings> = {
58-
yourAnswer: "Your answer",
59-
integerExample: "Integer example",
60-
properExample: "Proper example",
61-
simplifiedProperExample: "Simplified proper example",
62-
};
50+
6351
const expected = [
64-
"Your answer",
65-
"Integer example",
66-
"Simplified proper example",
52+
"**Your answer should be** ",
53+
"an integer, like $6$",
54+
"a *simplified proper* fraction, like $3/5$",
6755
];
6856

6957
// Act
70-
const result = generateExamples(
71-
answerForms,
72-
fakePerseusStrings as PerseusStrings,
73-
);
58+
const result = generateExamples(answerForms, mockStrings);
7459

7560
// Assert
7661
expect(result).toEqual(expected);
@@ -79,19 +64,11 @@ describe("generateExamples", () => {
7964
it("returns an empty array if no answer forms are provided", () => {
8065
// Arrange
8166
const answerForms: readonly PerseusNumericInputAnswerForm[] = [];
82-
const fakePerseusStrings: Partial<PerseusStrings> = {
83-
yourAnswer: "Your answer",
84-
integerExample: "Integer example",
85-
properExample: "Proper example",
86-
simplifiedProperExample: "Simplified proper example",
87-
};
67+
8868
const expected = [];
8969

9070
// Act
91-
const result = generateExamples(
92-
answerForms,
93-
fakePerseusStrings as PerseusStrings,
94-
);
71+
const result = generateExamples(answerForms, mockStrings);
9572

9673
// Assert
9774
expect(result).toEqual(expected);

0 commit comments

Comments
 (0)