import React from 'react'; import { mount, render } from 'enzyme'; import { primary } from 'styles/colors'; import QuestionIcon from 'components/Icon/icons/alert/question'; import { render as rTLRender, screen } from '@testing-library/react'; import WalletIcon from 'components/Icon/icons/payments/wallet'; import Checkbox, { ButtonCheckbox } from './index'; import '@testing-library/jest-dom/extend-expect'; describe('Checkbox', () => { it('Should not throw', () => { expect(() => ).not.toThrow(); }); it('Should match snapshot', () => { expect(render()).toMatchSnapshot(); }); it('Should match snapshot - `checked`', () => { expect(render()).toMatchSnapshot(); }); it('Should match snapshot - highlight label', () => { expect(render()).toMatchSnapshot(); }); it('Should render icon when provided', () => { const wrapper = mount(} />); expect(wrapper.find('Memo(QuestionIcon)')).toHaveLength(1); }); it('Should update state when `checked` change', () => { const wrapper = mount(); expect(wrapper.find('input').prop('checked')).toBe(false); wrapper.setProps({ checked: true }); wrapper.update(); expect(wrapper.find('input').prop('checked')).toBe(true); }); it('Should call `onChange`', () => { const changeHandler = jest.fn(); const wrapper = mount(); wrapper.find('input').simulate('change'); expect(changeHandler).toHaveBeenCalledTimes(1); }); }); describe('ButtonCheckbox', () => { it('should render', () => { const { asFragment } = rTLRender( ); expect(asFragment()).toMatchSnapshot(); }); it('should have an orange selected background color when the button is checked', () => { rTLRender( ); const label = screen.getByTitle('A simple button checkbox'); expect(label).toHaveStyle(`background-color: ${primary['050']}`); }); });