Skip to content
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

test(AutoComplete): add e2e tests #5417

Merged
merged 32 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0a05161
test(AutoComplete): add e2e tests
francinelucca Dec 11, 2024
dcab809
test(vrt): update snapshots
francinelucca Dec 11, 2024
44f93b0
Merge branch 'main' into francinelucca/e2e-tests/autocomplete
francinelucca Dec 11, 2024
14b8035
Merge branch 'main' into francinelucca/e2e-tests/autocomplete
francinelucca Dec 12, 2024
328c4ac
Merge branch 'main' of github.com:primer/react into francinelucca/e2e…
francinelucca Dec 13, 2024
d886b2c
fix(Autocomplete): wait for full render before e2e testing
francinelucca Dec 13, 2024
a92ebf0
Merge branch 'main' into francinelucca/e2e-tests/autocomplete
francinelucca Dec 13, 2024
b48bd0a
test(vrt): update snapshots
francinelucca Dec 13, 2024
8797722
Merge branch 'main' into francinelucca/e2e-tests/autocomplete
randall-krauskopf Dec 16, 2024
06121c0
fix dev storybook accessibility
randall-krauskopf Dec 16, 2024
a9b653a
fix lint
randall-krauskopf Dec 16, 2024
3cf65ba
fix theme related a11y errors
randall-krauskopf Dec 16, 2024
e0aec57
test(vrt): update snapshots
randall-krauskopf Dec 16, 2024
1297e36
ignore color-contrast rule
randall-krauskopf Dec 16, 2024
184d90f
Merge branch 'francinelucca/e2e-tests/autocomplete' of https://github…
randall-krauskopf Dec 16, 2024
4251993
add aria-label to dialog
langermank Dec 16, 2024
165a1ba
fix tests maybe?
langermank Dec 16, 2024
563aafb
remove playground snaps
langermank Dec 16, 2024
18391a7
Merge branch 'main' into francinelucca/e2e-tests/autocomplete
langermank Dec 16, 2024
afb924f
test(vrt): update snapshots
langermank Dec 16, 2024
fd88234
retry mask
langermank Dec 16, 2024
ab50cc7
fix contrast failure
langermank Dec 17, 2024
481acc9
try to disable flaky test
langermank Dec 17, 2024
665b7e3
test(vrt): update snapshots
langermank Dec 17, 2024
8da03a6
Merge branch 'main' of https://github.com/primer/react into francinel…
hussam-i-am Dec 17, 2024
5c946ca
remove rule
hussam-i-am Dec 17, 2024
df522f1
fix vrt test
hussam-i-am Dec 17, 2024
87ee34e
format fix
hussam-i-am Dec 17, 2024
da224fb
update assertion
hussam-i-am Dec 17, 2024
1eacab3
test(vrt): update snapshots
hussam-i-am Dec 17, 2024
66bdec9
disable aria rule
hussam-i-am Dec 17, 2024
43ebdc1
add label
hussam-i-am Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 154 additions & 0 deletions e2e/components/Autocomplete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import {test, expect, type Page} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

const stories: Array<{title: string; id: string; setup: (page: Page) => void}> = [
{
title: 'Default',
id: 'components-autocomplete--default',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'Add New Item',
id: 'components-autocomplete-features--add-new-item',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'Async Loading Of Items',
id: 'components-autocomplete-features--async-loading-of-items',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'Custom Overlay Menu Anchor',
id: 'components-autocomplete-features--custom-overlay-menu-anchor',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'Custom Search Filter Fn',
id: 'components-autocomplete-features--custom-search-filter-fn',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'Custom Sort After Menu Close',
id: 'components-autocomplete-features--custom-sort-after-menu-close',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'In A Dialog',
id: 'components-autocomplete-features--in-a-dialog',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('Enter')
await expect(page.getByRole('dialog')).toBeVisible()
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'In Overlay With Custom Scroll Container Ref',
id: 'components-autocomplete-features--in-overlay-with-custom-scroll-container-ref',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('Enter')
await page.keyboard.press('D')
},
},
{
title: 'Rendering The Menu Outside An Overlay',
id: 'components-autocomplete-features--rendering-the-menu-outside-an-overlay',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'With Callback When Overlay Open State Changes',
id: 'components-autocomplete-features--with-callback-when-overlay-open-state-changes',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'With Token Input',
id: 'components-autocomplete-features--with-token-input',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
{
title: 'Sx Prop',
id: 'components-autocomplete-dev--sx-prop',
setup: async page => {
await page.keyboard.press('Tab')
await page.keyboard.press('D')
},
},
]

test.describe('Autocomplete', () => {
for (const story of stories) {
test.describe(story.title, () => {
for (const theme of themes) {
test.describe(theme, () => {
test('@vrt', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})

story.setup(page)

await expect(page).toHaveScreenshot(`Autocomplete.${story.title}.${theme}.png`, {animations: 'disabled'})
})

test('@aat', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})

story.setup(page)

await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled:
theme !== 'dark_colorblind' &&
theme !== 'dark_dimmed' &&
theme !== 'light' &&
theme !== 'light_colorblind' &&
theme !== 'light_tritanopia',
},
'aria-valid-attr-value': {enabled: false},
},
})
})
})
}
})
}
})
46 changes: 46 additions & 0 deletions packages/react/src/Autocomplete/Autocomplete.dev.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import type {Meta} from '@storybook/react'

import Autocomplete from './Autocomplete'
import FormControl from '../FormControl'

const autocompleteStoryMeta: Meta = {
title: 'Components/Autocomplete/Dev',
} as Meta

export const SxProp = () => {
return (
<form>
<FormControl required={true}>
<FormControl.Label id="autocompleteLabel">Label</FormControl.Label>
<Autocomplete>
<Autocomplete.Input
sx={{
width: '100%',
marginRight: '10px',
borderColor: 'deeppink',
}}
size="medium"
/>
<Autocomplete.Overlay
className="testCustomClassnameBorder"
visibility="visible"
sx={{
maxHeight: 'min(50vh, 280px)',
overflowY: 'scroll',
' div': {
flexDirection: 'column',
whiteSpace: 'pre-wrap',
},
outline: '1px solid deeppink',
}}
>
<Autocomplete.Menu items={[]} selectedItemIds={[]} aria-labelledby="autocompleteLabel" />
</Autocomplete.Overlay>
</Autocomplete>
</FormControl>
</form>
)
}

export default autocompleteStoryMeta
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const autocompleteStoryMeta: Meta = {
<ThemeProvider>
<BaseStyles>
<Box onKeyDownCapture={reportKey}>
<Box position="absolute" right={5} top={2}>
<Box as="p" position="absolute" right={5} top={2} id="key-press-label">
Last key pressed: {lastKey}
</Box>
<Box paddingTop={5}>
Expand Down Expand Up @@ -567,6 +567,7 @@ export const InOverlayWithCustomScrollContainerRef = () => {
},
}}
block
aria-label="Search"
/>
</Box>
<Box
Expand Down Expand Up @@ -606,7 +607,12 @@ export const InADialog = () => {
return (
<>
<Button onClick={() => setIsDialogOpen(true)}>Show dialog</Button>
<Dialog id="dialog-with-autocomplete" isOpen={isDialogOpen} onDismiss={() => setIsDialogOpen(false)}>
<Dialog
aria-label="Dialog with autocomplete"
id="dialog-with-autocomplete"
isOpen={isDialogOpen}
onDismiss={() => setIsDialogOpen(false)}
>
<div ref={outerContainerRef}>
<Box as="form" sx={{p: 3}}>
{mounted ? (
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Autocomplete/Autocomplete.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const autocompleteStoryMeta: Meta = {
<ThemeProvider>
<BaseStyles>
<Box onKeyDownCapture={reportKey}>
<Box position="absolute" right={5} top={2}>
<Box as="p" position="absolute" right={5} top={2} id="key-press-label">
Last key pressed: {lastKey}
</Box>
<Box paddingTop={5}>
Expand Down
67 changes: 67 additions & 0 deletions packages/react/src/__tests__/Autocomplete.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BaseStyles from '../BaseStyles'
import theme from '../theme'
import {ThemeProvider} from '../ThemeProvider'
import {render} from '../utils/testing'
import {FeatureFlags} from '../FeatureFlags'

const mockItems = [
{text: 'zero', id: '0'},
Expand Down Expand Up @@ -218,6 +219,29 @@ describe('Autocomplete', () => {

expect(getByDisplayValue('0')).toBeDefined()
})

it('should support `className` on the outermost element', () => {
const Element = () => (
<Autocomplete>
<Autocomplete.Input className={'test-class-name'} />
</Autocomplete>
)
const FeatureFlagElement = () => {
return (
<FeatureFlags
flags={{
primer_react_css_modules_team: true,
primer_react_css_modules_staff: true,
primer_react_css_modules_ga: true,
}}
>
<Element />
</FeatureFlags>
)
}
expect(HTMLRender(<Element />).container.firstChild).toHaveClass('test-class-name')
expect(HTMLRender(<FeatureFlagElement />).container.firstChild).toHaveClass('test-class-name')
})
})

describe('Autocomplete.Menu', () => {
Expand Down Expand Up @@ -439,6 +463,49 @@ describe('Autocomplete', () => {
})
})

describe('Autocomplete.Overlay', () => {
it('should support `className` on the outermost element', async () => {
const Element = ({className}: {className: string}) => (
<ThemeProvider>
<Autocomplete id="autocompleteId">
<Autocomplete.Input />
<Autocomplete.Overlay className={className} visibility="visible">
hi
</Autocomplete.Overlay>
</Autocomplete>
</ThemeProvider>
)
const FeatureFlagElement = () => {
return (
<FeatureFlags
flags={{
primer_react_css_modules_team: true,
primer_react_css_modules_staff: true,
primer_react_css_modules_ga: true,
}}
>
<Element className="test-class-name-2" />
</FeatureFlags>
)
}
const {container: elementContainer, getByRole, rerender} = HTMLRender(<Element className="test-class-name" />)
let inputNode = getByRole('combobox')
await userEvent.click(inputNode)
await userEvent.keyboard('{ArrowDown}')
// overlay is a sibling of elementContainer
expect(elementContainer.parentElement?.querySelectorAll('.test-class-name')).toHaveLength(1)

rerender(<FeatureFlagElement />)
expect(elementContainer.parentElement?.querySelectorAll('.test-class-name')).toHaveLength(0)
inputNode = getByRole('combobox')
await userEvent.click(inputNode)
await userEvent.keyboard('{ArrowDown}')

// overlay is a sibling of ffContainer
expect(elementContainer.parentElement?.querySelectorAll('.test-class-name-2')).toHaveLength(1)
})
})

describe('null context', () => {
it('throws errors when Autocomplete context is null', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
Expand Down
Loading