shlink-web-client/test/utils/dates/DateIntervalSelector.test.tsx

26 lines
1,010 B
TypeScript
Raw Normal View History

import { screen, waitFor } from '@testing-library/react';
import { DateInterval, rangeOrIntervalToString } from '../../../src/utils/helpers/dateIntervals';
2021-03-06 19:21:23 +03:00
import { DateIntervalSelector } from '../../../src/utils/dates/DateIntervalSelector';
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';
const onChange = jest.fn();
const setUp = () => renderWithEvents(
<DateIntervalSelector allText="All text" active={activeInterval} onChange={onChange} />,
);
2021-03-06 19:21:23 +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
expect(btn).toHaveTextContent(rangeOrIntervalToString(activeInterval) ?? '');
expect(items).toHaveLength(8);
2021-03-06 19:21:23 +03:00
});
});