Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
langermank committed Sep 25, 2024
1 parent fa1c4f3 commit 41bfb14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
12 changes: 3 additions & 9 deletions packages/react/src/Details/__tests__/Details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ describe('Details', () => {
const {getDetailsProps, open} = useDetails({closeOnOutsideClick: true})
return (
<Details {...getDetailsProps()} data-testid="details">
<Button as="summary" data-testid="summary">
{open ? 'Open' : 'Closed'}
</Button>
<summary data-testid="summary">{open ? 'Open' : 'Closed'}</summary>
</Details>
)
}
Expand All @@ -63,9 +61,7 @@ describe('Details', () => {
const {getDetailsProps, setOpen, open} = useDetails({closeOnOutsideClick: true, defaultOpen: true})
return (
<Details {...getDetailsProps()} data-testid="details">
<Button as="summary" data-testid="summary">
{open ? 'Open' : 'Closed'}
</Button>
<summary data-testid="summary">{open ? 'Open' : 'Closed'}</summary>
<CloseButton onClick={() => setOpen(false)}>Close</CloseButton>
</Details>
)
Expand All @@ -85,9 +81,7 @@ describe('Details', () => {
const {getDetailsProps, open} = useDetails({closeOnOutsideClick: true, defaultOpen: true})
return (
<Details {...getDetailsProps()}>
<Button as="summary" data-testid="summary">
{open ? 'Open' : 'Closed'}
</Button>
<summary data-testid="summary">{open ? 'Open' : 'Closed'}</summary>
<Box>
<Button variant="primary">test</Button>
</Box>
Expand Down
16 changes: 8 additions & 8 deletions packages/react/src/Overlay/Overlay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ describe('Overlay', () => {

it('should focus element passed into function', async () => {
const user = userEvent.setup()
const {getByText} = render(<TestComponent initialFocus="button" />)
await user.click(getByText('open overlay'))
await waitFor(() => getByText('Confirm'))
const confirmButton = getByText('Confirm')
const {getByRole} = render(<TestComponent initialFocus="button" />)
await user.click(getByRole('button', {name: 'open overlay'}))
await waitFor(() => getByRole('button', {name: 'Confirm'}))
const confirmButton = getByRole('button', {name: 'Confirm'})
expect(document.activeElement).toEqual(confirmButton)
})

it('should focus first element when nothing is passed', async () => {
const user = userEvent.setup()
const {getByText} = render(<TestComponent />)
await user.click(getByText('open overlay'))
await waitFor(() => getByText('Cancel'))
const cancelButton = getByText('Cancel')
const {getByRole} = render(<TestComponent />)
await user.click(getByRole('button', {name: 'open overlay'}))
await waitFor(() => getByRole('button', {name: 'Cancel'}))
const cancelButton = getByRole('button', {name: 'Cancel'})
expect(document.activeElement).toEqual(cancelButton)
})

Expand Down

0 comments on commit 41bfb14

Please sign in to comment.