|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import {Dialog} from '@gravity-ui/uikit'; |
| 4 | +import {describe, expect, it} from 'vitest'; |
| 5 | +import {userEvent} from 'vitest/browser'; |
| 6 | + |
| 7 | +import {render} from '#test-utils/utils'; |
| 8 | + |
| 9 | +import {RelativeRangeDatePicker} from '../RelativeRangeDatePicker'; |
| 10 | + |
| 11 | +function TestRelativeRangeDatePicker() { |
| 12 | + const [open, setOpen] = React.useState(true); |
| 13 | + |
| 14 | + return ( |
| 15 | + <Dialog open={open} onClose={() => setOpen(false)}> |
| 16 | + <Dialog.Body> |
| 17 | + <div>Dialog content</div> |
| 18 | + <RelativeRangeDatePicker label="Range" /> |
| 19 | + </Dialog.Body> |
| 20 | + </Dialog> |
| 21 | + ); |
| 22 | +} |
| 23 | + |
| 24 | +describe('RelativeRangeDatePicker', () => { |
| 25 | + it('closes its popup on Escape from the group inside Dialog', async () => { |
| 26 | + const screen = await render(<TestRelativeRangeDatePicker />); |
| 27 | + |
| 28 | + const combobox = screen.getByLabelText('Range', {exact: true}); |
| 29 | + const calendarButton = screen.getByLabelText('Range date picker'); |
| 30 | + |
| 31 | + expect(combobox).toBeInTheDocument(); |
| 32 | + expect(calendarButton).toBeInTheDocument(); |
| 33 | + |
| 34 | + combobox.element().focus(); |
| 35 | + await userEvent.keyboard('{Alt>}{ArrowDown}{/Alt}'); |
| 36 | + expect(combobox).toHaveAttribute('aria-expanded', 'true'); |
| 37 | + combobox.element().focus(); |
| 38 | + await userEvent.keyboard('{Escape}'); |
| 39 | + |
| 40 | + expect(combobox).toHaveAttribute('aria-expanded', 'false'); |
| 41 | + expect(screen.getByText('Dialog content')).toBeInTheDocument(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments