2022-11-21 10:00:13 +08:00
|
|
|
import userEvent from '@testing-library/user-event';
|
2020-09-18 16:53:18 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Button from '..';
|
2023-01-03 16:08:20 +08:00
|
|
|
import { act, fireEvent, render } from '../../../tests/utils';
|
2022-06-06 17:33:42 +08:00
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.mock('rc-util/lib/Dom/isVisible', () => {
|
|
|
|
const mockFn = () => true;
|
|
|
|
return mockFn;
|
|
|
|
});
|
2020-09-18 16:53:18 +08:00
|
|
|
|
|
|
|
describe('click wave effect', () => {
|
2022-11-21 10:00:13 +08:00
|
|
|
beforeEach(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
2022-11-21 10:00:13 +08:00
|
|
|
});
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllTimers();
|
|
|
|
jest.useRealTimers();
|
2022-12-28 23:20:22 +08:00
|
|
|
document.body.innerHTML = '';
|
2022-11-21 10:00:13 +08:00
|
|
|
});
|
|
|
|
|
2022-12-28 23:20:22 +08:00
|
|
|
async function clickButton(container: HTMLElement) {
|
|
|
|
const element = container.firstChild;
|
2022-11-21 10:00:13 +08:00
|
|
|
// https://github.com/testing-library/user-event/issues/833
|
2023-06-07 21:59:21 +08:00
|
|
|
await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).click(element as Element);
|
2023-08-04 11:22:33 +08:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
jest.advanceTimersByTime(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Second time will render wave element
|
2023-01-03 16:08:20 +08:00
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.advanceTimersByTime(100);
|
2023-01-03 16:08:20 +08:00
|
|
|
});
|
|
|
|
|
2022-12-28 23:20:22 +08:00
|
|
|
fireEvent(element!, new Event('transitionstart'));
|
|
|
|
fireEvent(element!, new Event('animationend'));
|
2020-09-18 16:53:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should have click wave effect for primary button', async () => {
|
2022-12-28 23:20:22 +08:00
|
|
|
const { container } = render(<Button type="primary">button</Button>);
|
|
|
|
await clickButton(container);
|
|
|
|
expect(document.querySelector('.ant-wave')).toBeTruthy();
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have click wave effect for default button', async () => {
|
2022-12-28 23:20:22 +08:00
|
|
|
const { container } = render(<Button>button</Button>);
|
|
|
|
await clickButton(container);
|
|
|
|
expect(document.querySelector('.ant-wave')).toBeTruthy();
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not have click wave effect for link type button', async () => {
|
2022-12-28 23:20:22 +08:00
|
|
|
const { container } = render(<Button type="link">button</Button>);
|
|
|
|
await clickButton(container);
|
|
|
|
expect(document.querySelector('.ant-wave')).toBeFalsy();
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not have click wave effect for text type button', async () => {
|
2022-12-28 23:20:22 +08:00
|
|
|
const { container } = render(<Button type="text">button</Button>);
|
|
|
|
await clickButton(container);
|
|
|
|
expect(document.querySelector('.ant-wave')).toBeFalsy();
|
2020-09-21 18:32:24 +08:00
|
|
|
});
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|