-
Notifications
You must be signed in to change notification settings - Fork 5
test: add Playwright coverage and test ids for radio group #830
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
fateeand
wants to merge
2
commits into
master
Choose a base branch
from
799-cover-radio-component-with-playwright-tests
base: master
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
playwright/cps-ui-kit/components/cps-radio-group.spec.ts
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,109 @@ | ||
| import { test, expect, type Page, type Locator } from '@playwright/test'; | ||
|
|
||
| function example(page: Page, testId: string): Locator { | ||
| return page.getByTestId(testId); | ||
| } | ||
|
|
||
| function radioGroup(page: Page, testId: string): Locator { | ||
| return example(page, testId).getByRole('radiogroup'); | ||
| } | ||
|
|
||
| test.describe('cps-radio-group', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/radio-group'); | ||
| }); | ||
|
|
||
| test.describe('Real native keyboard navigation skips disabled radios', () => { | ||
| test('ArrowDown from an enabled radio real-skips a disabled one via native grouping', async ({ | ||
| page | ||
| }) => { | ||
| const group = example(page, 'partially-disabled-radio-group'); | ||
| const option2 = group.getByRole('radio', { name: 'Option 2' }); | ||
| const option4 = group.getByRole('radio', { name: 'Option 4' }); | ||
|
|
||
| await option2.focus(); | ||
| await page.keyboard.press('ArrowDown'); | ||
|
|
||
| await expect(option4).toBeFocused(); | ||
| await expect(option4).toBeChecked(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real form validation shows and clears a real error', () => { | ||
| test('selecting the wrong option shows a real error; selecting the right one clears it', async ({ | ||
| page | ||
| }) => { | ||
| const group = radioGroup(page, 'required-radio-group'); | ||
| const errorEl = group.getByTestId('cps-radio-group-error'); | ||
|
|
||
| const option1 = group.getByRole('radio', { name: 'Option 1' }); | ||
| await option1.focus(); | ||
| await page.keyboard.press('Space'); | ||
| await page.evaluate(() => | ||
| (document.activeElement as HTMLElement)?.blur() | ||
| ); | ||
|
|
||
| await expect(errorEl).toBeVisible(); | ||
| await expect(errorEl).toHaveText('Only third option must be selected'); | ||
| await expect(group).toHaveAttribute( | ||
| 'aria-describedby', | ||
| (await errorEl.getAttribute('id')) ?? '' | ||
| ); | ||
|
|
||
| const option3 = group.getByRole('radio', { name: 'Option 3' }); | ||
| await option3.focus(); | ||
| await page.keyboard.press('Space'); | ||
| await page.evaluate(() => | ||
| (document.activeElement as HTMLElement)?.blur() | ||
| ); | ||
|
|
||
| await expect(errorEl).toHaveCount(0); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real inert blocks focus on unselected custom content', () => { | ||
| test('the nested control real-refuses focus until its radio is selected', async ({ | ||
| page | ||
| }) => { | ||
| const group = example(page, 'custom-content-radio-group'); | ||
| const customRadio = group.getByRole('radio', { | ||
| name: 'Custom option with inline selectors' | ||
| }); | ||
| const nestedCombobox = group.getByRole('combobox', { | ||
| name: 'Select day' | ||
| }); | ||
|
|
||
| await expect(customRadio).not.toBeChecked(); | ||
|
|
||
| await nestedCombobox.focus(); | ||
| await expect(nestedCombobox).not.toBeFocused(); | ||
|
|
||
| await customRadio.click(); | ||
| await expect(customRadio).toBeChecked(); | ||
|
|
||
| await nestedCombobox.focus(); | ||
| await expect(nestedCombobox).toBeFocused(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real hideDetails suppresses both a real hint and a real validation error', () => { | ||
| test('a hint stays real-absent untouched, and a real error stays real-absent once invalid', async ({ | ||
| page | ||
| }) => { | ||
| const group = radioGroup(page, 'required-hidden-radio-group'); | ||
|
|
||
| await expect(group.getByTestId('cps-radio-group-hint')).toHaveCount(0); | ||
|
|
||
| const option1 = group.getByRole('radio', { name: 'Option 1' }); | ||
| await option1.focus(); | ||
| await page.keyboard.press('Space'); | ||
| await page.evaluate(() => | ||
| (document.activeElement as HTMLElement)?.blur() | ||
| ); | ||
|
|
||
| await expect(group).toHaveAttribute('aria-invalid', 'true'); | ||
| await expect(group).not.toHaveAttribute('aria-describedby', /.+/); | ||
| await expect(group.getByTestId('cps-radio-group-error')).toHaveCount(0); | ||
| }); | ||
| }); | ||
| }); |
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
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.