Skip to content

Commit

Permalink
update tests to handle interaction scenario for escape to close
Browse files Browse the repository at this point in the history
  • Loading branch information
mcwinter07 committed Jan 23, 2025
1 parent 99348c4 commit 5b56c59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/components/src/__rc__/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { render, screen, waitFor, within } from '@testing-library/react'
import { render, screen, waitFor, waitForElementToBeRemoved, within } from '@testing-library/react'

Check failure on line 2 in packages/components/src/__rc__/Select/Select.spec.tsx

View workflow job for this annotation

GitHub Actions / eslint

'waitForElementToBeRemoved' is defined but never used. Allowed unused vars must match /(^_|^React$)/u
import userEvent from '@testing-library/user-event'
import { vi } from 'vitest'
import { Select, type SelectProps } from './Select'
Expand Down Expand Up @@ -188,14 +188,24 @@ describe('<Select />', () => {
})
})
it('is closed when hits the escape key', async () => {
const { getByRole } = render(<SelectWrapper defaultOpen />)
const menu = getByRole('listbox')
const { getByRole, queryByRole } = render(<SelectWrapper />)
const trigger = getByRole('combobox', {
name: 'Mock Label',
})
await user.tab()
await waitFor(() => {
expect(trigger).toHaveFocus()
})
await user.keyboard('{Enter}')

await waitFor(() => {
expect(menu).toBeVisible()
expect(queryByRole('listbox')).toBeVisible()
})

await user.keyboard('{Escape}')

await waitFor(() => {
expect(menu).not.toBeInTheDocument()
expect(queryByRole('listbox')).toBe(null)
})
})
})
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/__rc__/Select/_docs/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export const Playground: Story = {
},
}

export const defaultOpen: Story = {

Check warning on line 53 in packages/components/src/__rc__/Select/_docs/Select.stories.tsx

View workflow job for this annotation

GitHub Actions / eslint

The story should use PascalCase notation: defaultOpen
parameters: {
docs: {
canvas: {
sourceState: 'shown',
},
},
},
args: {
defaultOpen: true,
},
}

export const SingleItems: Story = {
args: {
items: singleMockItems,
Expand Down

0 comments on commit 5b56c59

Please sign in to comment.