2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2020-03-19 19:27:02 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2022-08-21 23:25:00 +08:00
|
|
|
import { render, sleep, fireEvent } from '../../../tests/utils';
|
2022-06-22 14:57:09 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
|
|
|
import Wave from '../wave';
|
2020-03-19 19:27:02 +08:00
|
|
|
|
|
|
|
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';
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
expect(container.querySelector('button')?.className).toBe('');
|
|
|
|
|
|
|
|
container.querySelector('button')?.click();
|
|
|
|
|
2020-05-12 12:44:49 +08:00
|
|
|
expect(
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('button')?.hasAttribute('ant-click-animating-without-extra-node'),
|
|
|
|
).toBeFalsy();
|
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
process.env.NODE_ENV = TEST_NODE_ENV;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('isHidden is mocked', () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
expect(container.querySelector('button')?.className).toBe('');
|
|
|
|
container.querySelector('button')?.click();
|
2020-05-12 12:44:49 +08:00
|
|
|
expect(
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('button')?.getAttribute('ant-click-animating-without-extra-node'),
|
2020-05-12 12:44:49 +08:00
|
|
|
).toBe('false');
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('wave color is grey', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
2022-06-28 15:20:09 +08:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
style={{ borderColor: 'rgb(0, 0, 0)', backgroundColor: 'transparent' }}
|
|
|
|
>
|
2020-05-12 12:44:49 +08:00
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('button')?.click();
|
2020-03-19 19:27:02 +08:00
|
|
|
await sleep(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement
|
|
|
|
).getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles.length).toBe(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('wave color is not grey', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button" style={{ borderColor: 'red' }}>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('button')?.click();
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(200);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement
|
|
|
|
).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;');
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('read wave color from border-top-color', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<div style={{ borderTopColor: 'blue' }}>button</div>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('div')?.click();
|
2020-03-19 19:27:02 +08:00
|
|
|
await sleep(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('div')?.getRootNode() as HTMLDivElement
|
|
|
|
).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;');
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('read wave color from background color', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<div style={{ backgroundColor: 'green' }}>button</div>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('div')?.click();
|
2020-03-19 19:27:02 +08:00
|
|
|
await sleep(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('div')?.getRootNode() as HTMLDivElement
|
|
|
|
).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;');
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('read wave color from border firstly', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<div style={{ borderColor: 'yellow', backgroundColor: 'green' }}>button</div>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('div')?.click();
|
2020-03-19 19:27:02 +08:00
|
|
|
await sleep(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('div')?.getRootNode() as HTMLDivElement
|
|
|
|
).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;');
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('hidden element with -leave className', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-05-12 12:44:49 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button" className="xx-leave">
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('button')?.click();
|
2020-03-19 19:27:02 +08:00
|
|
|
await sleep(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement
|
|
|
|
).getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles.length).toBe(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ConfigProvider csp', async () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container, unmount } = render(
|
2020-03-19 19:27:02 +08:00
|
|
|
<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>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
container.querySelector('button')?.click();
|
2020-03-19 19:27:02 +08:00
|
|
|
await sleep(0);
|
2022-08-21 23:25:00 +08:00
|
|
|
const styles = (
|
|
|
|
container.querySelector('button')?.getRootNode() as HTMLButtonElement
|
|
|
|
).getElementsByTagName('style');
|
2020-03-19 19:27:02 +08:00
|
|
|
expect(styles[0].getAttribute('nonce')).toBe('YourNonceCode');
|
2022-08-21 23:25:00 +08:00
|
|
|
unmount();
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|
2022-06-27 16:57:34 +08:00
|
|
|
|
|
|
|
it('bindAnimationEvent should return when node is null', () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const ref = React.createRef<any>();
|
2022-06-27 16:57:34 +08:00
|
|
|
render(
|
|
|
|
<Wave ref={ref}>
|
|
|
|
<button type="button" disabled>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
|
|
|
expect(ref.current?.bindAnimationEvent()).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bindAnimationEvent.onClick should return when children is hidden', () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const ref = React.createRef<any>();
|
2022-06-27 16:57:34 +08:00
|
|
|
render(
|
|
|
|
<Wave ref={ref}>
|
|
|
|
<button type="button" style={{ display: 'none' }}>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
|
|
|
expect(ref.current?.bindAnimationEvent()).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bindAnimationEvent.onClick should return when children is input', () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const ref = React.createRef<any>();
|
2022-06-27 16:57:34 +08:00
|
|
|
render(
|
|
|
|
<Wave ref={ref}>
|
|
|
|
<input />
|
|
|
|
</Wave>,
|
|
|
|
);
|
|
|
|
expect(ref.current?.bindAnimationEvent()).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not throw when click it', () => {
|
|
|
|
expect(() => {
|
2022-08-21 23:25:00 +08:00
|
|
|
const { container } = render(
|
2022-06-27 16:57:34 +08:00
|
|
|
<Wave>
|
|
|
|
<div />
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-21 23:25:00 +08:00
|
|
|
fireEvent.click(container);
|
2022-06-27 16:57:34 +08:00
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not throw when no children', () => {
|
2022-08-21 23:25:00 +08:00
|
|
|
expect(() => render(<Wave />)).not.toThrow();
|
2022-06-27 16:57:34 +08:00
|
|
|
});
|
2022-06-28 15:20:09 +08:00
|
|
|
|
|
|
|
it('wave color should inferred if border is transparent and background is not', async () => {
|
2022-08-23 18:00:20 +08:00
|
|
|
const { container, unmount } = render(
|
2022-06-28 15:20:09 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button" style={{ borderColor: 'transparent', background: 'red' }}>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-23 18:00:20 +08:00
|
|
|
fireEvent.click(container.querySelector('button')!);
|
2022-06-28 15:20:09 +08:00
|
|
|
await sleep(200);
|
2022-08-23 18:00:20 +08:00
|
|
|
const styles = (container.querySelector('button')!.getRootNode() as any).getElementsByTagName(
|
|
|
|
'style',
|
|
|
|
);
|
2022-06-28 15:20:09 +08:00
|
|
|
expect(styles.length).toBe(1);
|
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: red;');
|
2022-08-23 18:00:20 +08:00
|
|
|
unmount();
|
2022-06-28 15:20:09 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('wave color should inferred if borderTopColor is transparent and borderColor is not', async () => {
|
2022-08-23 18:00:20 +08:00
|
|
|
const { container, unmount } = render(
|
2022-06-28 15:20:09 +08:00
|
|
|
<Wave>
|
|
|
|
<button type="button" style={{ borderColor: 'red', borderTopColor: 'transparent' }}>
|
|
|
|
button
|
|
|
|
</button>
|
|
|
|
</Wave>,
|
|
|
|
);
|
2022-08-23 18:00:20 +08:00
|
|
|
fireEvent.click(container.querySelector('button')!);
|
2022-06-28 15:20:09 +08:00
|
|
|
await sleep(200);
|
2022-08-23 18:00:20 +08:00
|
|
|
const styles = (container.querySelector('button')!.getRootNode() as any).getElementsByTagName(
|
|
|
|
'style',
|
|
|
|
);
|
2022-06-28 15:20:09 +08:00
|
|
|
expect(styles.length).toBe(1);
|
|
|
|
expect(styles[0].innerHTML).toContain('--antd-wave-shadow-color: red;');
|
2022-08-23 18:00:20 +08:00
|
|
|
unmount();
|
2022-06-28 15:20:09 +08:00
|
|
|
});
|
2020-03-19 19:27:02 +08:00
|
|
|
});
|