mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Created tests for new QR code dropdowns
This commit is contained in:
parent
5166340779
commit
c6be8bd96f
2 changed files with 84 additions and 0 deletions
|
@ -0,0 +1,47 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { QrErrorCorrection } from '../../../../src/utils/helpers/qrCodes';
|
||||
import { QrErrorCorrectionDropdown } from '../../../../src/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown';
|
||||
|
||||
describe('<QrErrorCorrectionDropdown />', () => {
|
||||
const initialErrorCorrection: QrErrorCorrection = 'Q';
|
||||
const setErrorCorrection = jest.fn();
|
||||
let wrapper: ShallowWrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(
|
||||
<QrErrorCorrectionDropdown errorCorrection={initialErrorCorrection} setErrorCorrection={setErrorCorrection} />,
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => wrapper?.unmount());
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
it('renders initial state', () => {
|
||||
const items = wrapper.find(DropdownItem);
|
||||
|
||||
expect(wrapper.prop('text')).toEqual('Error correction (Q)');
|
||||
expect(items.at(0).prop('active')).toEqual(false);
|
||||
expect(items.at(1).prop('active')).toEqual(false);
|
||||
expect(items.at(2).prop('active')).toEqual(true);
|
||||
expect(items.at(3).prop('active')).toEqual(false);
|
||||
});
|
||||
|
||||
it('invokes callback when items are clicked', () => {
|
||||
const items = wrapper.find(DropdownItem);
|
||||
|
||||
expect(setErrorCorrection).not.toHaveBeenCalled();
|
||||
|
||||
items.at(0).simulate('click');
|
||||
expect(setErrorCorrection).toHaveBeenCalledWith('L');
|
||||
|
||||
items.at(1).simulate('click');
|
||||
expect(setErrorCorrection).toHaveBeenCalledWith('M');
|
||||
|
||||
items.at(2).simulate('click');
|
||||
expect(setErrorCorrection).toHaveBeenCalledWith('Q');
|
||||
|
||||
items.at(3).simulate('click');
|
||||
expect(setErrorCorrection).toHaveBeenCalledWith('H');
|
||||
});
|
||||
});
|
37
test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx
Normal file
37
test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { QrCodeFormat } from '../../../../src/utils/helpers/qrCodes';
|
||||
import { QrFormatDropdown } from '../../../../src/short-urls/helpers/qr-codes/QrFormatDropdown';
|
||||
|
||||
describe('<QrFormatDropdown />', () => {
|
||||
const initialFormat: QrCodeFormat = 'svg';
|
||||
const setFormat = jest.fn();
|
||||
let wrapper: ShallowWrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<QrFormatDropdown format={initialFormat} setFormat={setFormat} />);
|
||||
});
|
||||
|
||||
afterEach(() => wrapper?.unmount());
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
it('renders initial state', () => {
|
||||
const items = wrapper.find(DropdownItem);
|
||||
|
||||
expect(wrapper.prop('text')).toEqual('Format (svg)');
|
||||
expect(items.at(0).prop('active')).toEqual(false);
|
||||
expect(items.at(1).prop('active')).toEqual(true);
|
||||
});
|
||||
|
||||
it('invokes callback when items are clicked', () => {
|
||||
const items = wrapper.find(DropdownItem);
|
||||
|
||||
expect(setFormat).not.toHaveBeenCalled();
|
||||
|
||||
items.at(0).simulate('click');
|
||||
expect(setFormat).toHaveBeenCalledWith('png');
|
||||
|
||||
items.at(1).simulate('click');
|
||||
expect(setFormat).toHaveBeenCalledWith('svg');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue