-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 [#4524] Tweak implementation details
Attempted to make the code a bit easier/simpler, and clean up the test helpers to use accessible queries.
- Loading branch information
1 parent
b3530cb
commit 3937b7e
Showing
5 changed files
with
139 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import {within} from '@storybook/test'; | ||
|
||
const getReactSelectInput = SelectElement => { | ||
return SelectElement.closest('.admin-react-select').querySelector('input[type="hidden"]'); | ||
}; | ||
|
||
const getReactSelectOptions = SelectElement => { | ||
return within(SelectElement.closest('.admin-react-select')).getAllByRole('option'); | ||
/** | ||
* From the input field (retrieved by accessible queries), find the react-select container. | ||
* | ||
* Equivalent of https://github.com/romgain/react-select-event/blob/8619e8b3da349eadfa7321ea4aa2b7eee7209f9f/src/index.ts#L14, | ||
* however instead of relying on the DOM structure we can leverage class names that are | ||
* guaranteed to be set by us. | ||
* | ||
* Usage: | ||
* | ||
* const dropdown = canvas.getByLabelText('My dropdown'); | ||
* const container = getReactSelectContainer(dropdown); | ||
* const options = within(container).queryByRole('option'); | ||
*/ | ||
const getReactSelectContainer = comboboxInput => { | ||
const container = comboboxInput.closest('.admin-react-select'); | ||
return container; | ||
}; | ||
|
||
export {getReactSelectInput, getReactSelectOptions}; | ||
export {getReactSelectContainer}; |