2022-07-10 00:03:21 +03:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2023-08-02 10:01:44 +03:00
|
|
|
import type { DateInterval } from '../../../src/utils/dates/DateIntervalSelector';
|
|
|
|
import { DateIntervalSelector, INTERVAL_TO_STRING_MAP } from '../../../src/utils/dates/DateIntervalSelector';
|
2023-09-30 11:45:52 +03:00
|
|
|
import { checkAccessibility } from '../../__helpers__/accessibility';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2021-03-06 19:21:23 +03:00
|
|
|
|
|
|
|
describe('<DateIntervalSelector />', () => {
|
|
|
|
const activeInterval: DateInterval = 'last7Days';
|
2023-05-27 12:57:26 +03:00
|
|
|
const onChange = vi.fn();
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = () => renderWithEvents(
|
|
|
|
<DateIntervalSelector allText="All text" active={activeInterval} onChange={onChange} />,
|
|
|
|
);
|
2021-03-06 19:21:23 +03:00
|
|
|
|
2023-09-30 11:45:52 +03:00
|
|
|
it('passes a11y checks', () => checkAccessibility(setUp()));
|
|
|
|
|
2022-07-08 16:11:51 +03:00
|
|
|
it('passes props down to nested DateIntervalDropdownItems', async () => {
|
|
|
|
const { user } = setUp();
|
|
|
|
const btn = screen.getByRole('button');
|
|
|
|
|
|
|
|
await user.click(btn);
|
|
|
|
await waitFor(() => expect(screen.getByRole('menu')).toBeInTheDocument());
|
|
|
|
|
|
|
|
const items = screen.getAllByRole('menuitem');
|
2021-03-06 19:21:23 +03:00
|
|
|
|
2023-08-02 10:01:44 +03:00
|
|
|
expect(btn).toHaveTextContent(INTERVAL_TO_STRING_MAP[activeInterval] ?? '');
|
2022-07-08 16:11:51 +03:00
|
|
|
expect(items).toHaveLength(8);
|
2021-03-06 19:21:23 +03:00
|
|
|
});
|
|
|
|
});
|