Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rm-input-number] 2 - Fix renderer-related tests #431

Draft
wants to merge 5 commits into
base: rm-input-number.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hungry-llamas-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

Configure Perseus to render numeric-input widgets in place of input-number
44 changes: 17 additions & 27 deletions packages/perseus-editor/src/widgets/input-number-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/sort-comp */
import {components, Util, InputNumber} from "@khanacademy/perseus";
import {components, Util} from "@khanacademy/perseus";
import * as React from "react";
import ReactDOM from "react-dom";
import _ from "underscore";
Expand Down Expand Up @@ -47,30 +47,20 @@ const answerTypes = {

type Props = {
value: number;
simplify: JSX.LibraryManagedAttributes<
typeof InputNumber.widget,
React.ComponentProps<typeof InputNumber.widget>
>["simplify"];
size: JSX.LibraryManagedAttributes<
typeof InputNumber.widget,
React.ComponentProps<typeof InputNumber.widget>
>["size"];
inexact: JSX.LibraryManagedAttributes<
typeof InputNumber.widget,
React.ComponentProps<typeof InputNumber.widget>
>["reviewModeRubric"]["inexact"];
maxError: JSX.LibraryManagedAttributes<
typeof InputNumber.widget,
React.ComponentProps<typeof InputNumber.widget>
>["reviewModeRubric"]["maxError"];
answerType: JSX.LibraryManagedAttributes<
typeof InputNumber.widget,
React.ComponentProps<typeof InputNumber.widget>
>["answerType"];
rightAlign: JSX.LibraryManagedAttributes<
typeof InputNumber.widget,
React.ComponentProps<typeof InputNumber.widget>
>["rightAlign"];
simplify: "required" | "optional" | "enforced";
size: "normal" | "small";
inexact: boolean;
maxError: number | string;
answerType:
| "number"
| "decimal"
| "integer"
| "rational"
| "improper"
| "mixed"
| "percent"
| "pi";
rightAlign: boolean;
onChange: (arg1: {
value?: ParsedValue | 0;
simplify?: Props["simplify"];
Expand Down Expand Up @@ -144,7 +134,7 @@ class InputNumberEditor extends React.Component<Props> {
value={this.props.simplify}
onChange={(e) => {
this.props.onChange({
// @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type '"optional" | "required" | "enforced" | undefined'.
// @ts-expect-error TS2322 - Type 'string' is not assignable to type '"required" | "optional" | "enforced" | undefined'.
simplify: e.target.value,
});
}}
Expand Down Expand Up @@ -218,7 +208,7 @@ class InputNumberEditor extends React.Component<Props> {
<select
value={this.props.answerType}
onChange={(e) => {
// @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type '"number" | "integer" | "mixed" | "decimal" | "improper" | "percent" | "pi" | "rational" | undefined'.
// @ts-expect-error TS2322 - Type 'string' is not assignable to type '"number" | "decimal" | "integer" | "pi" | "rational" | "improper" | "mixed" | "percent" | undefined'
this.props.onChange({answerType: e.target.value});
}}
>
Expand Down
35 changes: 25 additions & 10 deletions packages/perseus/src/__testdata__/renderer.testdata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
DropdownWidget,
ImageWidget,
InputNumberWidget,
NumericInputWidget,
PerseusRenderer,
} from "../perseus-types";

Expand Down Expand Up @@ -46,21 +46,36 @@ export const imageWidget: ImageWidget = {
version: {major: 0, minor: 0},
};

export const inputNumberWidget: InputNumberWidget = {
export const numericInputWidget: NumericInputWidget = {
version: {
major: 0,
minor: 0,
},
type: "input-number",
type: "numeric-input",
graded: true,
alignment: "default",
options: {
maxError: 0.1,
inexact: false,
value: 0.3333333333333333,
simplify: "optional",
answerType: "rational",
answers: [
{
message: "That's correct!",
value: 0.3333333333333333,
status: "correct",
answerForms: ["integer", "proper", "improper", "mixed"],
strict: true,
maxError: 0.1,
simplify: "optional",
},
],
answerForms: [
{name: "integer", simplify: "required"},
{name: "proper", simplify: "required"},
{name: "improper", simplify: "required"},
{name: "mixed", simplify: "required"},
],
size: "normal",
coefficient: false,
static: false,
labelText: "Enter the decimal value of 1/3",
},
};

Expand All @@ -73,15 +88,15 @@ export const question1: PerseusRenderer = {

export const question2: PerseusRenderer = {
content:
"Denis baked a peach pie and cut it into $3$ equal-sized pieces. Denis's dad eats $1$ section of the pie. \n\n**What fraction of the pie did Denis's dad eat?** \n![](https://ka-perseus-graphie.s3.amazonaws.com/74a2b7583a2c26ebfb3ad714e29867541253fc97.png) \n[[\u2603 input-number 1]] \n\n\n\n",
"Denis baked a peach pie and cut it into $3$ equal-sized pieces. Denis's dad eats $1$ section of the pie. \n\n**What fraction of the pie did Denis's dad eat?** \n![](https://ka-perseus-graphie.s3.amazonaws.com/74a2b7583a2c26ebfb3ad714e29867541253fc97.png) \n[[\u2603 numeric-input 1]] \n\n\n\n",
images: {
"https://ka-perseus-graphie.s3.amazonaws.com/74a2b7583a2c26ebfb3ad714e29867541253fc97.png":
{
width: 200,
height: 200,
},
},
widgets: {"input-number 1": inputNumberWidget},
widgets: {"numeric-input 1": numericInputWidget},
};

// Note that if this item is used, you _must_ first register the MockWidget
Expand Down
Loading