-
Notifications
You must be signed in to change notification settings - Fork 352
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
base: main
Are you sure you want to change the base?
Conversation
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.
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (f71abc4) and published it to npm. You 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 |
Size Change: +191 B (+0.01%) Total Size: 1.29 MB
ℹ️ View Unchanged
|
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
const spokenLabelPromises = labels.map(async (label) => { | ||
return await generateSpokenMathDetails(label.text); | ||
}); |
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this comment.
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"?
// Mock this so that each label's text says "joint" before it. | |
// Mock this so that each label's text says "spoken" before it. |
packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/util.ts
Outdated
Show resolved
Hide resolved
return Promise.resolve(`Spoken math details for ${input}`); | ||
}, | ||
joinLabelsAsSpokenMath: (input) => | ||
mockedJoinLabelsAsSpokenMathForTests(input), |
There was a problem hiding this comment.
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?
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(see other PR)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
Summary:
I received a couple suggestions in PR #1854.
I'm implmementing them here:
duplicate that code for every single locked figure.
generateSpokenMathDetails()
on the whole aria stringfor 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.
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
and the other having "$1" as the label.
Also confirm that the dollar signs show up normally.