-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs: Testing docs #9029
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
Open
LFDanLu
wants to merge
16
commits into
style_macro_docs
Choose a base branch
from
testing_docs
base: style_macro_docs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,324
−41
Open
docs: Testing docs #9029
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
68a66e0
initial react aria testing docs
LFDanLu 432f702
pare down content for readability
LFDanLu 78fb92b
adding S2 testing docs
LFDanLu 620ebd7
add sample subpage content
LFDanLu 6fdf671
add style for blockquote
LFDanLu c051a8c
add new test util docs to old website
LFDanLu 159e76b
add examples to new docs
LFDanLu 50c9e07
clean up old code, no more switcher
LFDanLu 5a10ff0
refactor test util content so it is in each page
LFDanLu 5b9fda5
debug why subpage why failing
LFDanLu 6db86ef
move to subpages
LFDanLu 73626ea
Merge branch 'style_macro_docs' of github.com:adobe/react-spectrum in…
LFDanLu e799a04
use isSubPage and update to detect parent link
LFDanLu f8ec2fb
export only the type
LFDanLu 6f69d9e
Merge branch 'style_macro_docs' of github.com:adobe/react-spectrum in…
LFDanLu cad6874
update subpage back button logic
LFDanLu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
packages/dev/s2-docs/pages/react-aria/CheckboxGroup/testing.mdx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import {Layout} from '../../../src/Layout'; | ||
| export default Layout; | ||
|
|
||
| import {InlineAlert, Heading, Content} from '@react-spectrum/s2'; | ||
| import testUtilDocs from 'docs:@react-aria/test-utils'; | ||
| import {InstallCommand} from '../../../src/InstallCommand'; | ||
| import {PatternTestingFAQ} from '../../../src/PatternTestingFAQ'; | ||
|
|
||
| export const isSubpage = true; | ||
| export const tags = ['testing', 'checkboxgroup', 'test-utils']; | ||
| export const description = 'Testing CheckboxGroup with React Aria test utils'; | ||
|
|
||
| # Testing CheckboxGroup | ||
|
|
||
| ## Test utils | ||
|
|
||
| `@react-aria/test-utils` offers common checkbox group interaction utilities which you may find helpful when writing tests. To install, simply | ||
| add it to your dev dependencies via your preferred package manager. | ||
|
|
||
| <InstallCommand pkg="@react-aria/test-utils" flags="--dev" /> | ||
|
|
||
| <InlineAlert variant="notice"> | ||
| <Heading>Requirements</Heading> | ||
| <Content>Please note that this library uses [@testing-library/react@16](https://www.npmjs.com/package/@testing-library/react) and [@testing-library/user-event@14](https://www.npmjs.com/package/@testing-library/user-event). This means that you need to be on React 18+ in order for these utilities to work.</Content> | ||
| </InlineAlert> | ||
|
|
||
| Once installed, you can access the `User` that `@react-aria/test-utils` provides in your test file as shown below. This user only needs to be initialized once and then can be used to generate | ||
| the `CheckboxGroup` tester in your test cases. This gives you access to `CheckboxGroup` specific utilities that you can then call within your test to query for specific subcomponents or simulate common interactions. | ||
| The example test case below shows how you might go about setting up the `CheckboxGroup` tester, use it to simulate checkbox selection, and verify the checkbox group's state after each interaction. | ||
|
|
||
| ```ts | ||
| // CheckboxGroup.test.ts | ||
| import {render} from '@testing-library/react'; | ||
| import {User} from '@react-aria/test-utils'; | ||
|
|
||
| let testUtilUser = new User({interactionType: 'mouse', advanceTimer: jest.advanceTimersByTime}); | ||
| // ... | ||
|
|
||
| it('CheckboxGroup can select multiple checkboxes', async function () { | ||
| // Render your test component/app and initialize the checkbox group tester | ||
| let {getByTestId} = render( | ||
| <CheckboxGroup data-testid="test-checkboxgroup"> | ||
| ... | ||
| </CheckboxGroup> | ||
| ); | ||
| let checkboxGroupTester = testUtilUser.createTester('CheckboxGroup', {root: getByTestId('test-checkboxgroup')}); | ||
| expect(checkboxGroupTester.selectedCheckboxes).toHaveLength(0); | ||
|
|
||
| await checkboxGroupTester.toggleCheckbox({checkbox: 0}); | ||
| expect(checkboxGroupTester.checkboxes[0]).toBeChecked(); | ||
| expect(checkboxGroupTester.selectedCheckboxes).toHaveLength(1); | ||
|
|
||
| await checkboxGroupTester.toggleCheckbox({checkbox: 4}); | ||
| expect(checkboxGroupTester.checkboxes[4]).toBeChecked(); | ||
| expect(checkboxGroupTester.selectedCheckboxes).toHaveLength(2); | ||
| }); | ||
| ``` | ||
|
|
||
| See below for the full definition of the `User` and the `CheckboxGroup` tester. | ||
|
|
||
| <ClassAPI links={testUtilDocs.links} class={testUtilDocs.exports.User} /> | ||
| <ClassAPI links={testUtilDocs.links} class={testUtilDocs.exports.CheckboxGroupTester} /> | ||
|
|
||
| ## Testing FAQ | ||
|
|
||
| <PatternTestingFAQ patternName="checkbox group" /> |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.