import { mount } from 'enzyme'; import React from 'react'; import mountTest from '../../../tests/shared/mountTest'; import { render, sleep } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; import Wave from '../wave'; describe('Wave component', () => { mountTest(Wave); afterEach(() => { const styles = document.getElementsByTagName('style'); for (let i = 0; i < styles.length; i += 1) { styles[i].remove(); } }); it('isHidden works', () => { const TEST_NODE_ENV = process.env.NODE_ENV; process.env.NODE_ENV = 'development'; const wrapper = mount( , ); expect(wrapper.find('button').getDOMNode().className).toBe(''); wrapper.find('button').getDOMNode().click(); expect( wrapper.find('button').getDOMNode().hasAttribute('ant-click-animating-without-extra-node'), ).toBe(false); wrapper.unmount(); process.env.NODE_ENV = TEST_NODE_ENV; }); it('isHidden is mocked', () => { const wrapper = mount( , ); expect(wrapper.find('button').getDOMNode().className).toBe(''); wrapper.find('button').getDOMNode().click(); expect( wrapper.find('button').getDOMNode().getAttribute('ant-click-animating-without-extra-node'), ).toBe('false'); wrapper.unmount(); }); it('wave color is grey', async () => { const wrapper = mount( , ); wrapper.find('button').getDOMNode().click(); await sleep(0); const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles.length).toBe(0); wrapper.unmount(); }); it('wave color is not grey', async () => { const wrapper = mount( , ); wrapper.find('button').getDOMNode().click(); await sleep(200); const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles.length).toBe(1); expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: red;'); wrapper.unmount(); }); it('read wave color from border-top-color', async () => { const wrapper = mount(
button
, ); wrapper.find('div').getDOMNode().click(); await sleep(0); const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles.length).toBe(1); expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: blue;'); wrapper.unmount(); }); it('read wave color from background color', async () => { const wrapper = mount(
button
, ); wrapper.find('div').getDOMNode().click(); await sleep(0); const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles.length).toBe(1); expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: green;'); wrapper.unmount(); }); it('read wave color from border firstly', async () => { const wrapper = mount(
button
, ); wrapper.find('div').getDOMNode().click(); await sleep(0); const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles.length).toBe(1); expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: yellow;'); wrapper.unmount(); }); it('hidden element with -leave className', async () => { const wrapper = mount( , ); wrapper.find('button').getDOMNode().click(); await sleep(0); const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles.length).toBe(0); wrapper.unmount(); }); it('ConfigProvider csp', async () => { const wrapper = mount( , ); wrapper.find('button').getDOMNode().click(); await sleep(0); const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); expect(styles[0].getAttribute('nonce')).toBe('YourNonceCode'); wrapper.unmount(); }); it('bindAnimationEvent should return when node is null', () => { const ref = React.createRef(); render( , ); expect(ref.current?.bindAnimationEvent()).toBe(undefined); }); it('bindAnimationEvent.onClick should return when children is hidden', () => { const ref = React.createRef(); render( , ); expect(ref.current?.bindAnimationEvent()).toBe(undefined); }); it('bindAnimationEvent.onClick should return when children is input', () => { const ref = React.createRef(); render( , ); expect(ref.current?.bindAnimationEvent()).toBe(undefined); }); it('should not throw when click it', () => { expect(() => { const wrapper = mount(
, ); wrapper.simulate('click'); }).not.toThrow(); }); it('should not throw when no children', () => { expect(() => mount()).not.toThrow(); }); });