Skip to content

Conversation

@benchristel
Copy link
Member

Summary:

This PR adds tests for the answerless case, and updates the types to reflect
what actually constitutes valid input.

The numDivisions prop is now required to be a number. The code for NumericInput is written in an (overly) clever way that treats 0 and null the same, but this is brittle and TypeScript doesn't like it. To clarify the code, we default numDivisions to 0 in the parser.

Issue: LEMS-2976

Test plan:

TODO

@github-actions
Copy link
Contributor

github-actions bot commented Apr 24, 2025

Size Change: 0 B

Total Size: 466 kB

ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.7 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 98.6 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.js 18.5 kB
packages/perseus-editor/dist/es/index.js 88.4 kB
packages/perseus-linter/dist/es/index.js 7.05 kB
packages/perseus-score/dist/es/index.js 9.04 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 199 kB
packages/perseus/dist/es/strings.js 7.49 kB
packages/pure-markdown/dist/es/index.js 1.22 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Apr 24, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (3b1d3ec) and published it to npm. You
can install it using the tag PR2424.

Example:

pnpm add @khanacademy/perseus@PR2424

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.js -t PR2424

Copy link
Contributor

@handeyeco handeyeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, fairly small PR and I feel like I learned a lot.

Comment on lines +214 to +218
describe.each([
["answerless", getAnswerlessItem("number-line", numberLineOptions)],
["answerful", getAnswerfulItem("number-line", numberLineOptions)],
])("given %s options", (_, {question}) => {
it("can be answered correctly", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is better than I was doing. I know you suggested to me but I didn't quite know how.

Comment on lines +220 to +222
const apiOptions: APIOptions = {
isMobile: false,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, did you find that you needed this?

const {renderer} = renderQuestion(question, apiOptions);

// Act
const [numberLine] = renderer.findWidgets("number-line 1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not know about findWidgets

const [numberLine] = renderer.findWidgets("number-line 1");
act(() => numberLine.movePosition(-2.5));
const score = scorePerseusItemTesting(
question1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you want to use question1 here

const [numberLine] = renderer.findWidgets("number-line 1");
act(() => numberLine.movePosition(3.5));
const score = scorePerseusItemTesting(
question1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

);

// Assert
expect(score).toHaveBeenAnsweredIncorrectly();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an invalid state we need to test? Or is it just correct/incorrect?

type Props = ChangeableProps & {
range: [number, number];
type Props = {
range: number[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought [number, number] was preferred when there was a fixed number of elements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data-schema types have range: number[], and the parser (which is derived from data-schema) does too. Since we apparently don't guarantee that there will always be two elements, I opted to change this type to be compatible with data-schema rather than vice-versa.

onChange: (arg1: any, arg2?: () => void | null | undefined) => void;
apiOptions: APIOptions;
keypadElement: HTMLElement | null | undefined;
keypadElement?: HTMLElement | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This couldn't be:

Suggested change
keypadElement?: HTMLElement | undefined;
keypadElement?: HTMLElement;

@benchristel
Copy link
Member Author

@handeyeco turns out this change breaks the Storybook examples. I'm going to rework this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants