From c6be8bd96f631a1646c7c6708292a15528f881e0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 16 Aug 2021 17:38:25 +0200 Subject: [PATCH] Created tests for new QR code dropdowns --- .../QrErrorCorrectionDropdown.test.tsx | 47 +++++++++++++++++++ .../qr-codes/QrFormatDropdown.test.tsx | 37 +++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx create mode 100644 test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx diff --git a/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx b/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx new file mode 100644 index 00000000..32db92f8 --- /dev/null +++ b/test/short-urls/helpers/qr-codes/QrErrorCorrectionDropdown.test.tsx @@ -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('', () => { + const initialErrorCorrection: QrErrorCorrection = 'Q'; + const setErrorCorrection = jest.fn(); + let wrapper: ShallowWrapper; + + beforeEach(() => { + wrapper = shallow( + , + ); + }); + + 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'); + }); +}); diff --git a/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx b/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx new file mode 100644 index 00000000..c40e05d0 --- /dev/null +++ b/test/short-urls/helpers/qr-codes/QrFormatDropdown.test.tsx @@ -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('', () => { + const initialFormat: QrCodeFormat = 'svg'; + const setFormat = jest.fn(); + let wrapper: ShallowWrapper; + + beforeEach(() => { + wrapper = shallow(); + }); + + 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'); + }); +});