-
Notifications
You must be signed in to change notification settings - Fork 30
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
Classifier: Refactor survey task tests #3933
Conversation
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
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.
Is there a reason that you’re not using screen
to run queries?
Buttons and other labelled elements should use getByLabelText
rather than getByText
.
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
A couple of other thoughts:
|
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.
Don’t use ARIA labels to duplicate button labels.
.../components/components/Chooser/components/CharacteristicsFilter/ClearFilters/ClearFilters.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/components/Choice/Choice.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/components/Choice/Choice.js
Outdated
Show resolved
Hide resolved
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 has the Identify button label been changed to 'Identify Aardark', 'Identify Fire' etc? It should be 'Identify' for any choice.
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/plugins/tasks/survey/components/SurveyTask.spec.js
Outdated
Show resolved
Hide resolved
lib-react-components and Grommet buttons (Primary, Button, etc.) that define the label as a property on the component are not found with Components that are found with Components with defined labels that aren't found with
|
Is that because you're looking for eg. |
No wait, the docs say this:
https://testing-library.com/docs/queries/bylabeltext#name So those buttons could be failing because they use HTML markup in their labels. ChoiceButton here, for example, has markup in its label, because it uses images.
<button>Text label</button> or an ARIA label: <button aria-label="Text label"><img /></button> but never both together. To be honest, in that second case the button label should be image alt text. <button><img alt="Text label" /></button> |
For buttons with HTML markup in the labels, preventing use of |
This query will find all menu item checkboxes inside the first menu on the page. It should be fast too. querySelector([role=“menu”]).querySelectorAll([role=“menuitemcheckbox”]) If the checkboxes have values, you can further refine the query with Stepping back from specific tests, is the run time being spent rendering the survey task, or running queries? If it’s rendering excessively, you can cache rendered nodes in variables, as snapshots of the DOM state, and reuse them. eg. const choicesMenu = document.querySelector([role=“menu”])
const choiceButtons = choiceMenu.querySelectorAll([role=“menuitemcheckbox”])
/*
Reuse choiceMenu and choiceButtons
to save time later.
*/
const aardvarkButton = Array.from(choiceButtons).find(button => button.textContent === ‘Aardvark’) Have a look at the |
Reading the source code, label text queries ignore buttons. |
Also noting here that |
667d4f1
to
747242a
Compare
Co-authored-by: Jim O'Donnell <[email protected]>
747242a
to
dbb1864
Compare
This is running a lot faster now on my laptop, though the excessive rendering is still making it quite slow. I've rebased and added a commit that renders a story once, in a I also fixed a bug in the 'Clear FIlters' button, which had the wrong label text. Your tests had caught the bug, but you'd updated the tests to pass by using the broken label, rather than fixing the button so that it passed with the expected label. |
CI isn't timing out, so I'm happy for this to be merged as-is. |
dbb1864
to
5b489fc
Compare
- Render once, then test rendered output in individual `it()` blocks. - Fix alt text for Clear Filters button.
5b489fc
to
8ce1935
Compare
I still can't figure out how to remove a filter, in the storybook, using only the keyboard. Definitely check that the user interactions in the keyboard tests match what a real volunteer would be expected to do. I have a feeling we're baking bad UX into the tests, which means they'll fail when the UX failure is fixed. |
Thank you @eatyourgreens ! I'll merge this shortly. For SurveyTask.spec.js,
Adding data-testid to the identify button and reducing the tabs to select a required choice question answer cut the related longest running test from 1661ms to 513ms for me locally. The filters can be removed by tabbing to the close/remove button within the filter and pressing space or enter. I can record a video and share on Slack if it'd be helpful. Regardless, I think the filters need a substantive refactor as noted in #3919. I'm about to add a comment in that issue to further discuss. |
This is a bug. See #3919. Tab on each radio button should take you out of the radio button group and on to the next focusable element on the page. |
FWIW, I'm toggling the selected radio button with the cursor keys, then trying Space or Enter to clear the selected value. |
Package
Describe your changes
getByRole
for related component) tests withgetByText
instead ofgetByRole
SurveyTask.spec.js
tests runtime by approximately 4 secondsHow to Review
Helpful explanations that will make your reviewer happy:
Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expectedRefactoring