2022-07-10 00:03:21 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2021-08-16 18:38:25 +03:00
|
|
|
import { QrFormatDropdown } from '../../../../src/short-urls/helpers/qr-codes/QrFormatDropdown';
|
2023-02-18 13:11:01 +03:00
|
|
|
import type { QrCodeFormat } from '../../../../src/utils/helpers/qrCodes';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../../../__helpers__/setUpTest';
|
2021-08-16 18:38:25 +03:00
|
|
|
|
|
|
|
describe('<QrFormatDropdown />', () => {
|
|
|
|
const initialFormat: QrCodeFormat = 'svg';
|
|
|
|
const setFormat = jest.fn();
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = () => renderWithEvents(<QrFormatDropdown format={initialFormat} setFormat={setFormat} />);
|
2021-08-16 18:38:25 +03:00
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
|
2022-06-13 22:38:39 +03:00
|
|
|
it('renders initial state', async () => {
|
|
|
|
const { user } = setUp();
|
|
|
|
const btn = screen.getByRole('button');
|
|
|
|
|
|
|
|
expect(btn).toHaveTextContent('Format (svg');
|
|
|
|
await user.click(btn);
|
|
|
|
const items = screen.getAllByRole('menuitem');
|
2021-08-16 18:38:25 +03:00
|
|
|
|
2022-06-13 22:38:39 +03:00
|
|
|
expect(items[0]).not.toHaveClass('active');
|
|
|
|
expect(items[1]).toHaveClass('active');
|
2021-08-16 18:38:25 +03:00
|
|
|
});
|
|
|
|
|
2022-06-13 22:38:39 +03:00
|
|
|
it('invokes callback when items are clicked', async () => {
|
|
|
|
const { user } = setUp();
|
|
|
|
const clickItem = async (name: string) => {
|
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
await user.click(screen.getByRole('menuitem', { name }));
|
|
|
|
};
|
2021-08-16 18:38:25 +03:00
|
|
|
|
|
|
|
expect(setFormat).not.toHaveBeenCalled();
|
|
|
|
|
2022-06-13 22:38:39 +03:00
|
|
|
await clickItem('PNG');
|
2021-08-16 18:38:25 +03:00
|
|
|
expect(setFormat).toHaveBeenCalledWith('png');
|
|
|
|
|
2022-06-13 22:38:39 +03:00
|
|
|
await clickItem('SVG');
|
2021-08-16 18:38:25 +03:00
|
|
|
expect(setFormat).toHaveBeenCalledWith('svg');
|
|
|
|
});
|
|
|
|
});
|