banner.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Banner } from '../../index';
  2. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  3. // function render(props) {
  4. // return mount(
  5. // <Banner
  6. // {...props}
  7. // />,
  8. // {
  9. // attachTo: document.getElementById('container')
  10. // }
  11. // );
  12. // }
  13. describe('Banner', () => {
  14. // beforeEach(() => {
  15. // // Avoid `attachTo: document.body` Warning
  16. // const div = document.createElement('div');
  17. // div.setAttribute('id', 'container');
  18. // document.body.appendChild(div);
  19. // });
  20. // afterEach(() => {
  21. // const div = document.getElementById('container');
  22. // if (div) {
  23. // document.body.removeChild(div);
  24. // }
  25. // });
  26. it('different type banner', () => {
  27. const defaultBanner = mount(<Banner />);
  28. const dangerBanner = mount(<Banner type='danger' />);
  29. const successBanner = mount(<Banner type='success' />);
  30. const warningBanner = mount(<Banner type='warning' />);
  31. expect(dangerBanner.exists(`.${BASE_CLASS_PREFIX}-banner-danger`)).toEqual(true);
  32. expect(defaultBanner.exists(`.${BASE_CLASS_PREFIX}-banner`)).toEqual(true);
  33. expect(successBanner.exists(`.${BASE_CLASS_PREFIX}-banner-success`)).toEqual(true);
  34. expect(warningBanner.exists(`.${BASE_CLASS_PREFIX}-banner-warning`)).toEqual(true);
  35. });
  36. it('custom className & style', () => {
  37. const wrapper = mount(<Banner className='test' style={{ color: 'red' }} />, { attachTo: document.getElementById('container') });
  38. expect(wrapper.find('div.test')).toHaveStyle('color', 'red');
  39. });
  40. it('call onClose', () => {
  41. const onClose = () => { };
  42. let spyOnClose = sinon.spy(onClose);
  43. const wrapper = mount(<Banner onClose={spyOnClose} />);
  44. wrapper.find(`.${BASE_CLASS_PREFIX}-button`).simulate('click', { target: { value: 'test' }});
  45. expect(spyOnClose.calledOnce).toBe(true);
  46. // 验证回调参数是否正确
  47. expect(spyOnClose.getCall(0).args[0].target.value).toEqual('test');
  48. });
  49. });