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

[Locked Figure Aria] Fix $ edge cases for spoken math aria labels #1874

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Nov 16, 2024

Summary:

I received a couple suggestions in PR #1854.
I'm implmementing them here:

  • Wrote a helper function that joins labels together so that we don't have to
    duplicate that code for every single locked figure.
  • Stopped calling generateSpokenMathDetails() on the whole aria string
    for the locked figure. Instead, it's now being called within
    the new helper function so that the labels can individually be converted,
    and we don't have to worry about the edge case with two different labels
    having dollar signs and causing all the content in between to be counted
    as TeX when it shouldn't.
  • Handled the case with a lone unescaped dollar sign, which should not count
    as TeX.

Note: The lone unescaped dollar isn't handled for the TeX inside the
graph itself yet. This will be in the next PR.

Issue: https://khanacademy.atlassian.net/browse/LEMS-2548

Test plan:

yarn jest

Storybook

I received a couple suggestions in PR #1854.
I'm implmementing them here:

- Wrote a helper function that joins labels together so that we don't have to
  duplicate that code for every single locked figure.
- Stopped calling `generateSpokenMathDetails()` on the whole aria string
  for the locked figure. Instead, it's now being called within
  the new helper function so that the labels can individually be converted,
  and we don't have to worry about the edge case with two different labels
  having dollar signs and causing all the content in between to be counted
  as TeX when it shouldn't.
- Handled the case with a lone unescaped dollar sign, which should not count
  as TeX.

Note: The lone unescaped dollar isn't handled for the TeX inside the
graph itself yet. This will be in the next PR.

Issue: https://khanacademy.atlassian.net/browse/LEMS-2548

Test plan:
`yarn jest`

Storybook
- http://localhost:6006/?path=/story/perseuseditor-widgets-interactive-graph--mafs-with-locked-figure-labels-all-flags
- Add two visible labels to the point, with one having "$1 and" as the label
  and the other having "$1" as the label.
- Press the autogenerate button and confirm that the "and" is normal and not "a n d".
  Also confirm that the dollar signs show up normally.
- Add two TeX labels and confirm that the auto-generated text is as expected.
- Repeat for all the other locked figures.
Copy link
Contributor

github-actions bot commented Nov 16, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1874

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

./dev/tools/bump_perseus_version.sh -t PR1874

Copy link
Contributor

github-actions bot commented Nov 16, 2024

Size Change: +191 B (+0.01%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus-editor/dist/es/index.js 698 kB +191 B (+0.03%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/index.js 424 kB
packages/perseus/dist/es/strings.js 3.57 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@nishasy nishasy marked this pull request as ready for review November 16, 2024 01:35
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/kind-moose-lick.md, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-ellipse-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-ellipse-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-line-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-line-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-point-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-point-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-polygon-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-polygon-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-vector-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-vector-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/util.test.ts, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/util.ts

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Comment on lines 187 to 189
const spokenLabelPromises = labels.map(async (label) => {
return await generateSpokenMathDetails(label.text);
});
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I don't think you need async/await here. You can just return the promise.

Suggested change
const spokenLabelPromises = labels.map(async (label) => {
return await generateSpokenMathDetails(label.text);
});
const spokenLabelPromises = labels.map((label) => {
return generateSpokenMathDetails(label.text);
});

return Promise.resolve("");
}

// Mock this so that each label's text says "joint" before it.
Copy link
Member

Choose a reason for hiding this comment

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

Should this comment say "spoken"?

Suggested change
// Mock this so that each label's text says "joint" before it.
// Mock this so that each label's text says "spoken" before it.

return Promise.resolve(`Spoken math details for ${input}`);
},
joinLabelsAsSpokenMath: (input) =>
mockedJoinLabelsAsSpokenMathForTests(input),
Copy link
Member

Choose a reason for hiding this comment

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

I worry that this mocking makes the tests harder to understand, and will become tech debt once we enable our wrapped SpeechRuleEngine to read locale data from local files.

Can you add a TODO comment linked to https://khanacademy.atlassian.net/browse/LEMS-2616 so we remember to un-mock this?

@nishasy nishasy marked this pull request as draft November 18, 2024 20:00
@nishasy nishasy marked this pull request as ready for review November 20, 2024 19:06
@khan-actions-bot khan-actions-bot requested a review from a team November 20, 2024 19:06
Copy link
Member

@benchristel benchristel left a comment

Choose a reason for hiding this comment

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

This is looking great! I'm a little confused about why mathOnlyParser is defined in the perseus package when it seems like we only need it in the editor. I commented on that inline.

type LockedPolygonType,
type LockedVectorType,
type LockedLineStyle,
mathOnlyParser,
Copy link
Member

Choose a reason for hiding this comment

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

Why is the mathOnlyParser exported from @khanacademy/perseus? Could it live in perseus-editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need it in both! It's in Perseus for the visual TeX itself, and we need it in the editor for the aria label util.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(see other PR)

Copy link
Member

@catandthemachines catandthemachines left a comment

Choose a reason for hiding this comment

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

Approved!

return ` ${spokenLabels.join(", ")}`;
}

// TODO(LEMS-2616): Stop using this mock in tests. Mocking may make tests
Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate more on why this mocked function is such a concern? My previous place of work we have occasional async functions we would test and mock and there were any explicit concerns around tech debt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants