mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-18 16:10:59 +08:00

Some checks are pending
Publish Any Commit / build (push) Waiting to run
✅ test v6 / lint (push) Waiting to run
✅ test v6 / test-react-legacy (18, 1/2) (push) Waiting to run
✅ test v6 / test-react-legacy (18, 2/2) (push) Waiting to run
✅ test v6 / test-node (push) Waiting to run
✅ test v6 / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test v6 / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test v6 / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test v6 / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test v6 / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test v6 / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test v6 / test-coverage (push) Blocked by required conditions
✅ test v6 / build (push) Waiting to run
✅ test v6 / test lib/es module (es, 1/2) (push) Waiting to run
✅ test v6 / test lib/es module (es, 2/2) (push) Waiting to run
✅ test v6 / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test v6 / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
* refactor: use @rc-component * chore: adjust compile * test: fix logic * chore: back of reset --------- Co-authored-by: 二货机器人 <smith3816@gmail.com>
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import Button from '..';
|
|
import { act, fireEvent, render } from '../../../tests/utils';
|
|
|
|
// TODO: Remove this. Mock for React 19
|
|
jest.mock('react-dom', () => {
|
|
const realReactDOM = jest.requireActual('react-dom');
|
|
|
|
if (realReactDOM.version.startsWith('19')) {
|
|
const realReactDOMClient = jest.requireActual('react-dom/client');
|
|
realReactDOM.createRoot = realReactDOMClient.createRoot;
|
|
}
|
|
|
|
return realReactDOM;
|
|
});
|
|
|
|
jest.mock('@rc-component/util/lib/Dom/isVisible', () => {
|
|
const mockFn = () => true;
|
|
return mockFn;
|
|
});
|
|
|
|
describe('click wave effect', () => {
|
|
beforeEach(() => {
|
|
jest.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.clearAllTimers();
|
|
jest.useRealTimers();
|
|
document.body.innerHTML = '';
|
|
});
|
|
|
|
async function clickButton(container: HTMLElement) {
|
|
const element = container.firstChild;
|
|
// https://github.com/testing-library/user-event/issues/833
|
|
await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).click(element as Element);
|
|
|
|
act(() => {
|
|
jest.advanceTimersByTime(100);
|
|
});
|
|
|
|
// Second time will render wave element
|
|
act(() => {
|
|
jest.advanceTimersByTime(100);
|
|
});
|
|
|
|
fireEvent(element!, new Event('transitionstart'));
|
|
fireEvent(element!, new Event('animationend'));
|
|
}
|
|
|
|
it('should have click wave effect for primary button', async () => {
|
|
const { container } = render(<Button type="primary">button</Button>);
|
|
await clickButton(container);
|
|
expect(document.querySelector('.ant-wave')).toBeTruthy();
|
|
});
|
|
|
|
it('should have click wave effect for default button', async () => {
|
|
const { container } = render(<Button>button</Button>);
|
|
await clickButton(container);
|
|
expect(document.querySelector('.ant-wave')).toBeTruthy();
|
|
});
|
|
|
|
it('should not have click wave effect for link type button', async () => {
|
|
const { container } = render(<Button type="link">button</Button>);
|
|
await clickButton(container);
|
|
expect(document.querySelector('.ant-wave')).toBeFalsy();
|
|
});
|
|
|
|
it('should not have click wave effect for text type button', async () => {
|
|
const { container } = render(<Button type="text">button</Button>);
|
|
await clickButton(container);
|
|
expect(document.querySelector('.ant-wave')).toBeFalsy();
|
|
});
|
|
});
|