button.test.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Button from '../index';
  2. import { mount } from 'enzyme';
  3. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  4. import { IconEdit } from '@douyinfe/semi-icons';
  5. describe('Button', () => {
  6. it('button with custom className & style', () => {
  7. const wrapper = mount(<Button className="test" style={{ color: 'red' }} />);
  8. expect(wrapper.hasClass('test')).toEqual(true);
  9. });
  10. it(`button with icon`, () => {
  11. const iconType = `${BASE_CLASS_PREFIX}-icon-edit`;
  12. const elem2 = mount(<Button icon={<IconEdit />} />);
  13. expect(elem2.find(`.${iconType}`).length).toBe(1);
  14. });
  15. it(`test horizontal padding`, () => {
  16. const elem = mount(<Button icon={<IconEdit />} noHorizontalPadding />);
  17. expect(elem.find('button').getDOMNode().style.paddingLeft).toBe('0px');
  18. expect(elem.find(`button`).getDOMNode().style.paddingRight).toBe('0px');
  19. const elem2 = mount(<Button icon={<IconEdit />} noHorizontalPadding={['left', 'right']} />);
  20. expect(elem2.find('button').getDOMNode().style.paddingLeft).toBe('0px');
  21. expect(elem2.find(`button`).getDOMNode().style.paddingRight).toBe('0px');
  22. });
  23. it(`test loading`, () => {
  24. const elem = mount(<Button icon={<IconEdit />} loading />);
  25. expect(elem.find(`#Artboard`).length).toBe(1);
  26. });
  27. it('test button type',()=>{
  28. const testType=(type)=>{
  29. const elem=mount(<Button htmlType={type}/>);
  30. expect(elem.find('button').getDOMNode().type).toBe(type);
  31. }
  32. testType('button');
  33. testType('reset');
  34. testType('submit');
  35. });
  36. it(`test position`, () => {
  37. const elem = mount(<Button icon={<IconEdit />} children={'text'} iconPosition={'right'} />);
  38. expect(elem.find(`.${BASE_CLASS_PREFIX}-button-content-left`).length).toBe(1);
  39. expect(elem.find(`.${BASE_CLASS_PREFIX}-button-content-right`).length).toBe(0);
  40. });
  41. });