import * as React from 'react'; import sinon from 'sinon'; import { shallow } from 'enzyme'; import Button from '..'; const sandbox = sinon.sandbox.create(); describe('components/button/Button', () => { afterEach(() => { sandbox.verifyAndRestore(); }); test('should correctly render children in button', () => { const children = 'yooo'; const wrapper = shallow(); expect(wrapper.hasClass('btn')).toBe(true); expect(wrapper.find('.btn-content').length).toEqual(1); expect(wrapper.text()).toEqual(children); }); test('should correctly render loading indicator, disable button and hide button content if button is in loading state', () => { const wrapper = shallow(); expect(wrapper.find('.btn-loading-indicator').length).toEqual(1); expect(wrapper.hasClass('is-loading')).toBe(true); }); test('simulates click events', () => { const onClickHandler = sinon.spy(); const wrapper = shallow); expect(wrapper.prop('className')).toEqual('btn bdl-btn--large'); }); test('should render icon in icon container if icon prop is set', () => { const FakeIcon = (props: Record) => ; const wrapper = shallow(); const iconContainer = wrapper.find('.bdl-btn-icon'); const textContainer = wrapper.find('.btn-content'); const { width, height } = iconContainer.find('FakeIcon').props(); expect(iconContainer.length).toBe(1); expect(textContainer.length).toBe(1); expect(width).toEqual(height); expect(width).toEqual(16); expect(wrapper).toMatchSnapshot(); }); test('should set aria-disabled to true when isDisabled is true', () => { const wrapper = shallow(); expect(wrapper.find('RadarAnimation')).toMatchSnapshot(); }); test('should render a RadarAnimation if showRadar is true', () => { const wrapper = shallow(); expect(wrapper.find('RadarAnimation')).toMatchSnapshot(); }); });