2022-07-01 11:55:03 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Switch from '..';
|
2022-10-31 10:22:38 +08:00
|
|
|
import { waitFakeTimer, render, fireEvent } from '../../../tests/utils';
|
2022-07-01 11:55:03 +08:00
|
|
|
|
|
|
|
describe('click wave effect', () => {
|
|
|
|
async function click(container: HTMLElement) {
|
|
|
|
fireEvent.click(container.querySelector('.ant-switch')!);
|
|
|
|
container.querySelector('.ant-switch')!.dispatchEvent(new Event('transitionstart'));
|
2022-10-31 10:22:38 +08:00
|
|
|
await waitFakeTimer();
|
2022-07-01 11:55:03 +08:00
|
|
|
container.querySelector('.ant-switch')!.dispatchEvent(new Event('animationend'));
|
2022-10-31 10:22:38 +08:00
|
|
|
await waitFakeTimer();
|
2022-07-01 11:55:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should have click wave effect', async () => {
|
2022-10-31 10:22:38 +08:00
|
|
|
jest.useFakeTimers();
|
2022-07-01 11:55:03 +08:00
|
|
|
const { container } = render(<Switch />);
|
|
|
|
await click(container);
|
|
|
|
await click(container);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
container.querySelector('.ant-switch')!.getAttribute('ant-switch-click-animating'),
|
|
|
|
).toBeFalsy();
|
|
|
|
|
|
|
|
const event = new Event('animationend');
|
|
|
|
Object.assign(event, { animationName: 'fadeEffect' });
|
|
|
|
container.querySelector('.ant-switch')!.dispatchEvent(event);
|
2022-10-31 10:22:38 +08:00
|
|
|
jest.clearAllTimers();
|
|
|
|
jest.useRealTimers();
|
2022-07-01 11:55:03 +08:00
|
|
|
});
|
|
|
|
});
|