|
|
@ -1,7 +1,6 @@ |
|
|
|
import { mount } from 'enzyme'; |
|
|
|
import React from 'react'; |
|
|
|
import mountTest from '../../../tests/shared/mountTest'; |
|
|
|
import { render, sleep } from '../../../tests/utils'; |
|
|
|
import { render, sleep, fireEvent } from '../../../tests/utils'; |
|
|
|
import ConfigProvider from '../../config-provider'; |
|
|
|
import Wave from '../wave'; |
|
|
|
|
|
|
@ -18,139 +17,155 @@ describe('Wave component', () => { |
|
|
|
it('isHidden works', () => { |
|
|
|
const TEST_NODE_ENV = process.env.NODE_ENV; |
|
|
|
process.env.NODE_ENV = 'development'; |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<button type="button">button</button> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
expect(wrapper.find('button').getDOMNode().className).toBe(''); |
|
|
|
wrapper.find('button').getDOMNode().click(); |
|
|
|
expect(container.querySelector('button')?.className).toBe(''); |
|
|
|
|
|
|
|
container.querySelector('button')?.click(); |
|
|
|
|
|
|
|
expect( |
|
|
|
wrapper.find('button').getDOMNode().hasAttribute('ant-click-animating-without-extra-node'), |
|
|
|
).toBe(false); |
|
|
|
wrapper.unmount(); |
|
|
|
container.querySelector('button')?.hasAttribute('ant-click-animating-without-extra-node'), |
|
|
|
).toBeFalsy(); |
|
|
|
unmount(); |
|
|
|
process.env.NODE_ENV = TEST_NODE_ENV; |
|
|
|
}); |
|
|
|
|
|
|
|
it('isHidden is mocked', () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<button type="button">button</button> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
expect(wrapper.find('button').getDOMNode().className).toBe(''); |
|
|
|
wrapper.find('button').getDOMNode().click(); |
|
|
|
expect(container.querySelector('button')?.className).toBe(''); |
|
|
|
container.querySelector('button')?.click(); |
|
|
|
expect( |
|
|
|
wrapper.find('button').getDOMNode().getAttribute('ant-click-animating-without-extra-node'), |
|
|
|
container.querySelector('button')?.getAttribute('ant-click-animating-without-extra-node'), |
|
|
|
).toBe('false'); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('wave color is grey', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<button type="button" style={{ borderColor: 'rgb(0, 0, 0)' }}> |
|
|
|
button |
|
|
|
</button> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.find('button').getDOMNode().click(); |
|
|
|
container.querySelector('button')?.click(); |
|
|
|
await sleep(0); |
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles.length).toBe(0); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('wave color is not grey', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<button type="button" style={{ borderColor: 'red' }}> |
|
|
|
button |
|
|
|
</button> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.find('button').getDOMNode().click(); |
|
|
|
container.querySelector('button')?.click(); |
|
|
|
await sleep(200); |
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles.length).toBe(1); |
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: red;'); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('read wave color from border-top-color', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<div style={{ borderTopColor: 'blue' }}>button</div> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.find('div').getDOMNode().click(); |
|
|
|
container.querySelector('div')?.click(); |
|
|
|
await sleep(0); |
|
|
|
const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('div')?.getRootNode() as HTMLDivElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles.length).toBe(1); |
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: blue;'); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('read wave color from background color', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<div style={{ backgroundColor: 'green' }}>button</div> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.find('div').getDOMNode().click(); |
|
|
|
container.querySelector('div')?.click(); |
|
|
|
await sleep(0); |
|
|
|
const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('div')?.getRootNode() as HTMLDivElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles.length).toBe(1); |
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: green;'); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('read wave color from border firstly', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<div style={{ borderColor: 'yellow', backgroundColor: 'green' }}>button</div> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.find('div').getDOMNode().click(); |
|
|
|
container.querySelector('div')?.click(); |
|
|
|
await sleep(0); |
|
|
|
const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('div')?.getRootNode() as HTMLDivElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles.length).toBe(1); |
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: yellow;'); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('hidden element with -leave className', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<Wave> |
|
|
|
<button type="button" className="xx-leave"> |
|
|
|
button |
|
|
|
</button> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.find('button').getDOMNode().click(); |
|
|
|
container.querySelector('button')?.click(); |
|
|
|
await sleep(0); |
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles.length).toBe(0); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('ConfigProvider csp', async () => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container, unmount } = render( |
|
|
|
<ConfigProvider csp={{ nonce: 'YourNonceCode' }}> |
|
|
|
<Wave> |
|
|
|
<button type="button">button</button> |
|
|
|
</Wave> |
|
|
|
</ConfigProvider>, |
|
|
|
); |
|
|
|
wrapper.find('button').getDOMNode().click(); |
|
|
|
container.querySelector('button')?.click(); |
|
|
|
await sleep(0); |
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style'); |
|
|
|
const styles = ( |
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement |
|
|
|
).getElementsByTagName('style'); |
|
|
|
expect(styles[0].getAttribute('nonce')).toBe('YourNonceCode'); |
|
|
|
wrapper.unmount(); |
|
|
|
unmount(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('bindAnimationEvent should return when node is null', () => { |
|
|
|
const ref = React.createRef(); |
|
|
|
const ref = React.createRef<any>(); |
|
|
|
render( |
|
|
|
<Wave ref={ref}> |
|
|
|
<button type="button" disabled> |
|
|
@ -162,7 +177,7 @@ describe('Wave component', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
it('bindAnimationEvent.onClick should return when children is hidden', () => { |
|
|
|
const ref = React.createRef(); |
|
|
|
const ref = React.createRef<any>(); |
|
|
|
render( |
|
|
|
<Wave ref={ref}> |
|
|
|
<button type="button" style={{ display: 'none' }}> |
|
|
@ -174,7 +189,7 @@ describe('Wave component', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
it('bindAnimationEvent.onClick should return when children is input', () => { |
|
|
|
const ref = React.createRef(); |
|
|
|
const ref = React.createRef<any>(); |
|
|
|
render( |
|
|
|
<Wave ref={ref}> |
|
|
|
<input /> |
|
|
@ -185,16 +200,16 @@ describe('Wave component', () => { |
|
|
|
|
|
|
|
it('should not throw when click it', () => { |
|
|
|
expect(() => { |
|
|
|
const wrapper = mount( |
|
|
|
const { container } = render( |
|
|
|
<Wave> |
|
|
|
<div /> |
|
|
|
</Wave>, |
|
|
|
); |
|
|
|
wrapper.simulate('click'); |
|
|
|
fireEvent.click(container); |
|
|
|
}).not.toThrow(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should not throw when no children', () => { |
|
|
|
expect(() => mount(<Wave />)).not.toThrow(); |
|
|
|
expect(() => render(<Wave />)).not.toThrow(); |
|
|
|
}); |
|
|
|
}); |