Skip to content

Add a "flipbook" story for testing multiple Perseus items#3680

Open
benchristel wants to merge 21 commits into
mainfrom
benc/item-flipbook
Open

Add a "flipbook" story for testing multiple Perseus items#3680
benchristel wants to merge 21 commits into
mainfrom
benc/item-flipbook

Conversation

@benchristel
Copy link
Copy Markdown
Member

Summary:

We have an upcoming playtest for the input-number widget. Because input-number
widgets are deprecated and somewhat rare / hard to find on khanacademy.org, we
want an easier way to manually test them (including rendering, user
interaction, and scoring).

This flipbook story lets you paste in a bunch of newline-separated Perseus
items and page through them one at a time.

Issue: none

Test plan:

pnpm storybook
open http://localhost:6006/?path=/story/perseus-item-flipbook--flipbook

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

Size Change: 0 B

Total Size: 506 kB

ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.6 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 6.32 kB
packages/math-input/dist/es/index.js 98.5 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 12.1 kB
packages/perseus-core/dist/es/index.js 26.1 kB
packages/perseus-editor/dist/es/index.js 105 kB
packages/perseus-linter/dist/es/index.js 9.41 kB
packages/perseus-score/dist/es/index.js 10.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 199 kB
packages/perseus/dist/es/strings.js 8.55 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The "model" pattern is somewhat unusual for us, but it's a lot less code than the equivalent reducer + actions would be.

The downside is that if you forget to call this.observer() in a mutating method, the view doesn't update.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR3680

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR3680

If you are working in Khan Academy's webapp, you can run the below command.

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

Comment on lines +52 to +55
if (this.clampItemIndex(requestedIndex) === requestedIndex) {
this.targetItemIndex = requestedIndex;
this.observer();
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Perhaps if the requested index is too low or too high, we should update targetItemIndex to the clamped value.

The only time we really don't want to set targetItemIndex is if parseInt returns NaN.

model.requestItemNumber("3");

expect(model.present().selectedItemNumber.value).toBe("3");
expect(observer).toHaveBeenCalledTimes(2);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't love that the number of observer calls is coupled to the test setup. Maybe I should rethink the design of these tests. If we could clear observer calls before the act section, this assertion could be changed to expect a single call.

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.

1 participant