2020-03-19 19:27:02 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Wave from '../wave';
|
|
|
|
import ConfigProvider from '../../config-provider';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
import { sleep } from '../../../tests/utils';
|
|
|
|
|
|
|
|
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';
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(wrapper.find('button').getDOMNode().className).toBe('');
|
|
|
|
wrapper.find('button').getDOMNode().click();
|
2020-05-12 12:44:49 +08:00
|
|
|
expect(
|
2020-05-13 16:16:16 +08:00
|
|
|
wrapper.find('button').getDOMNode().hasAttribute('ant-click-animating-without-extra-node'),
|
2020-05-12 12:44:49 +08:00
|
|
|
).toBe(false);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.unmount();
|
|
|
|
process.env.NODE_ENV = TEST_NODE_ENV;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('isHidden is mocked', () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(wrapper.find('button').getDOMNode().className).toBe('');
|
|
|
|
wrapper.find('button').getDOMNode().click();
|
2020-05-12 12:44:49 +08:00
|
|
|
expect(
|
2020-05-13 16:16:16 +08:00
|
|
|
wrapper.find('button').getDOMNode().getAttribute('ant-click-animating-without-extra-node'),
|
2020-05-12 12:44:49 +08:00
|
|
|
).toBe('false');
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('wave color is grey', async () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<button type="button" style={{ borderColor: 'rgb(0, 0, 0)' }}>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.find('button').getDOMNode().click();
|
|
|
|
await sleep(0);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles.length).toBe(0);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('wave color is not grey', async () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<button type="button" style={{ borderColor: 'red' }}>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.find('button').getDOMNode().click();
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(200);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
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 () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<div style={{ borderTopColor: 'blue' }}>button</div>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.find('div').getDOMNode().click();
|
|
|
|
await sleep(0);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
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 () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<div style={{ backgroundColor: 'green' }}>button</div>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.find('div').getDOMNode().click();
|
|
|
|
await sleep(0);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
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 () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<div style={{ borderColor: 'yellow', backgroundColor: 'green' }}>button</div>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.find('div').getDOMNode().click();
|
|
|
|
await sleep(0);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('div').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles.length).toBe(1);
|
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: yellow;');
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hidden element with -leave className', async () => {
|
2020-05-12 12:44:49 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Wave>
|
|
|
|
<button type="button" className="xx-leave">
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2020-03-19 19:27:02 +08:00
|
|
|
wrapper.find('button').getDOMNode().click();
|
|
|
|
await sleep(0);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles.length).toBe(0);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ConfigProvider csp', async () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider csp={{ nonce: 'YourNonceCode' }}>
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Wave>
|
2020-03-19 19:27:02 +08:00
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
wrapper.find('button').getDOMNode().click();
|
|
|
|
await sleep(0);
|
2021-03-25 11:57:49 +08:00
|
|
|
const styles = wrapper.find('button').getDOMNode().getRootNode().getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles[0].getAttribute('nonce')).toBe('YourNonceCode');
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
});
|