|
| 1 | +import React from 'react' |
| 2 | +import { shallow } from 'enzyme' |
| 3 | +import { expect } from 'chai' |
| 4 | +import sinon from 'sinon' |
| 5 | + |
| 6 | +import CustomButton from './../../../../src/js/components/CustomButton' |
| 7 | + |
| 8 | +const pathJSX = ( |
| 9 | + <path d="m31.7 16.4q0-0.6-0.4-1l-2.1-2.1q-0.4-0.4-1-0.4t-1 0.4l-9.1 9.1-5-5q-0.5-0.4-1-0.4t-1 0.4l-2.1 2q-0.4 0.4-0.4 1 0 0.6 0.4 1l8.1 8.1q0.4 0.4 1 0.4 0.6 0 1-0.4l12.2-12.1q0.4-0.4 0.4-1z m5.6 3.6q0 4.7-2.3 8.6t-6.3 6.2-8.6 2.3-8.6-2.3-6.2-6.2-2.3-8.6 2.3-8.6 6.2-6.2 8.6-2.3 8.6 2.3 6.3 6.2 2.3 8.6z" /> |
| 10 | +); |
| 11 | + |
| 12 | +describe('<CustomButton />', function () { |
| 13 | + it('CustomButton component should exist', function () { |
| 14 | + const logSpy = sinon.spy(console, 'log') |
| 15 | + const wrapper = shallow( |
| 16 | + <CustomButton |
| 17 | + clickCallback={(element) => console.log('It works!')} |
| 18 | + path={pathJSX} |
| 19 | + viewBox='0 0 40 40' |
| 20 | + title='A title example' |
| 21 | + className='class-example' |
| 22 | + hidden={false} |
| 23 | + /> |
| 24 | + ) |
| 25 | + |
| 26 | + expect(wrapper.find('span')).to.have.length(1) |
| 27 | + try { |
| 28 | + wrapper.find('.class-example').simulate('click') |
| 29 | + expect(logSpy.calledWith('It works!')).to.be.true |
| 30 | + } finally { |
| 31 | + logSpy.restore() |
| 32 | + } |
| 33 | + expect( |
| 34 | + wrapper.find('svg').containsMatchingElement(pathJSX) |
| 35 | + ).to.be.true |
| 36 | + expect(wrapper.find('svg').prop('viewBox')).to.equal('0 0 40 40') |
| 37 | + expect(wrapper.find('.class-example').prop('title')).to.equal('A title example') |
| 38 | + expect(wrapper.find('.class-example').prop('className')).to.equal('class-example') |
| 39 | + }) |
| 40 | + |
| 41 | + it('CustomButton component should be hidden', function () { |
| 42 | + const wrapper = shallow( |
| 43 | + <CustomButton |
| 44 | + clickCallback={(element) => console.log('It works!')} |
| 45 | + path={pathJSX} |
| 46 | + viewBox='0 0 40 40' |
| 47 | + title='A title example' |
| 48 | + className='class-example' |
| 49 | + hidden |
| 50 | + /> |
| 51 | + ) |
| 52 | + |
| 53 | + expect(wrapper.find('span').prop('style')).to.have.property('display', 'none') |
| 54 | + }) |
| 55 | +}) |
0 commit comments