-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * fix(ImageBaseOverlay): fix nested Tappable (#7006) * fix(ImageBaseOverlay): fix nested Tappable * fix(ImageBaseOverlay): add non interactive wrapper * chore: clean up Co-authored-by: Andrey Medvedev <[email protected]> * chore: fix prettier * fix: review notes * fix merge * fix: remove tests * fix: revert DisableClickableLockStateContext adding --------- Co-authored-by: Andrey Medvedev <[email protected]> * fix: run prettier * CHORE: Update screenshots * fix: delete e2e test --------- Co-authored-by: Andrey Medvedev <[email protected]> Co-authored-by: GitHub Action <[email protected]>
- Loading branch information
1 parent
b073303
commit 5019c30
Showing
9 changed files
with
302 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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 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
3 changes: 0 additions & 3 deletions
3
...age_snapshots__/customselect-scroll-to-option-android-chromium-light-1-snap.png
This file was deleted.
Oops, something went wrong.
This file contains 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 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
111 changes: 111 additions & 0 deletions
111
packages/vkui/src/components/ImageBase/ImageBaseOverlay/ImageBaseOverlay.test.tsx
This file contains 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,111 @@ | ||
import { act } from 'react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { Icon12Add } from '@vkontakte/icons'; | ||
import { Button } from '../../../components/Button/Button'; | ||
import { baselineComponent, userEvent } from '../../../testing/utils'; | ||
import { ImageBaseOverlay, ImageBaseOverlayProps } from './ImageBaseOverlay'; | ||
import styles from './ImageBaseOverlay.module.css'; | ||
|
||
const ImageBaseOverlayClickableTest = (props: Omit<ImageBaseOverlayProps, 'children'>) => ( | ||
<ImageBaseOverlay | ||
data-testid="overlay" | ||
aria-label="Интерактивная Кнопка" | ||
{...props} | ||
disableInteractive={false} | ||
> | ||
<Icon12Add /> | ||
</ImageBaseOverlay> | ||
); | ||
|
||
const ImageBaseOverlayNonClickableTest = ( | ||
props: Omit<ImageBaseOverlayProps, 'children' | 'onClick'>, | ||
) => ( | ||
<ImageBaseOverlay data-testid="overlay" {...props} disableInteractive> | ||
<Button data-testid="button1">Button</Button> | ||
<Button data-testid="button2">Button</Button> | ||
</ImageBaseOverlay> | ||
); | ||
|
||
describe(ImageBaseOverlay, () => { | ||
baselineComponent(ImageBaseOverlayClickableTest); | ||
|
||
it('focus event works as expected without noInteractive', async () => { | ||
render(<ImageBaseOverlayClickableTest />); | ||
const element = screen.getByTestId('overlay'); | ||
|
||
await userEvent.tab(); | ||
expect(element).toHaveFocus(); | ||
act(jest.runAllTimers); | ||
await userEvent.tab(); | ||
expect(document.querySelector(`.${styles['ImageBaseOverlay--visible']}`)).toBeNull(); | ||
}); | ||
|
||
it('focus event works as expected with noInteractive', async () => { | ||
render(<ImageBaseOverlayNonClickableTest />); | ||
const button1 = screen.getByTestId('button1'); | ||
const button2 = screen.getByTestId('button2'); | ||
|
||
await userEvent.tab(); | ||
expect(button1).toHaveFocus(); | ||
act(jest.runAllTimers); | ||
expect(document.querySelector(`.${styles['ImageBaseOverlay--visible']}`)).not.toBeNull(); | ||
await userEvent.tab(); | ||
expect(button2).toHaveFocus(); | ||
act(jest.runAllTimers); | ||
expect(document.querySelector(`.${styles['ImageBaseOverlay--visible']}`)).not.toBeNull(); | ||
await userEvent.tab(); | ||
act(jest.runAllTimers); | ||
expect(document.querySelector(`.${styles['ImageBaseOverlay--visible']}`)).toBeNull(); | ||
}); | ||
|
||
describe('works as clickable element', () => { | ||
it('appears as clickable element', () => { | ||
render(<ImageBaseOverlayClickableTest />); | ||
|
||
const element = screen.getByTestId('overlay'); | ||
|
||
expect(element.tagName.toLowerCase()).toMatch('div'); | ||
expect(element).toHaveAttribute('role', 'button'); | ||
expect(element).toHaveAttribute('tabindex', '0'); | ||
expect(document.querySelector(`.${styles['ImageBaseOverlay--clickable']}`)).not.toBeNull(); | ||
}); | ||
|
||
it('handles onClick prop', () => { | ||
const handleClick = jest.fn(); | ||
render( | ||
<ImageBaseOverlayClickableTest onClick={handleClick} disableInteractive={undefined} />, | ||
); | ||
|
||
fireEvent.click(screen.getByTestId('overlay')); | ||
expect(handleClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('handles onClick prop by keyboard Enter & Space event', () => { | ||
const handleClick = jest.fn(); | ||
render(<ImageBaseOverlayClickableTest onClick={handleClick} />); | ||
|
||
const element = screen.getByTestId('overlay'); | ||
|
||
act(() => element.focus()); | ||
|
||
// onClick gets called on Enter and Space | ||
fireEvent.keyDown(element, { key: 'Enter', code: 'Enter' }); | ||
expect(handleClick).toHaveBeenCalledTimes(1); | ||
|
||
fireEvent.keyDown(element, { key: ' ', code: 'Space' }); | ||
expect(handleClick).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
|
||
describe('works as wrapper for clickable elements', () => { | ||
it('appears as non clickable element', () => { | ||
render(<ImageBaseOverlayNonClickableTest />); | ||
const element = screen.getByTestId('overlay'); | ||
|
||
expect(element.tagName.toLowerCase()).toMatch('div'); | ||
expect(element).not.toHaveAttribute('role', 'button'); | ||
expect(element).not.toHaveAttribute('tabindex', '0'); | ||
expect(document.querySelector(`.${styles['ImageBaseOverlay--clickable']}`)).toBeNull(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.