mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-26 12:10:06 +08:00
c34caad24c
* test: js => ts * test: add test * fix: fix eslint error * test: add test case * fix: fix test error * fix: fix eslint error * fix: fix eslint error * fix: eslint error fix * fix: fallback eslint config & add test case * test: add all test case * fix: bugfix * fix: bugFix * fix: bugFix * fix: bugFix * fix: lint * fix: add React.createRef * fix: add breadcrumbName in Routes * fix: any commit for restart ci/cd * fix: remove type * fix: test fix * fix: test fix * fix: add ts-ignore for id * test: add Icon test case * test: remove ts-ignore * test: add Icon test case
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import React from 'react';
|
|
import BackTop from '..';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
import { fireEvent, render, sleep } from '../../../tests/utils';
|
|
|
|
describe('BackTop', () => {
|
|
mountTest(BackTop);
|
|
rtlTest(BackTop);
|
|
|
|
it('should scroll to top after click it', async () => {
|
|
const { container } = render(<BackTop visibilityHeight={-1} />);
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((_, y) => {
|
|
window.scrollY = y;
|
|
window.pageYOffset = y;
|
|
document.documentElement.scrollTop = y;
|
|
});
|
|
window.scrollTo(0, 400);
|
|
expect(document.documentElement.scrollTop).toBe(400);
|
|
fireEvent.click(container.querySelector('.ant-back-top')!);
|
|
await sleep(500);
|
|
expect(document.documentElement.scrollTop).toBe(0);
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
|
|
it('support onClick', async () => {
|
|
const onClick = jest.fn();
|
|
const { container } = render(<BackTop onClick={onClick} visibilityHeight={-1} />);
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((_, y) => {
|
|
window.scrollY = y;
|
|
window.pageYOffset = y;
|
|
});
|
|
document.dispatchEvent(new Event('scroll'));
|
|
window.scrollTo(0, 400);
|
|
fireEvent.click(container.querySelector('.ant-back-top')!);
|
|
expect(onClick).toHaveBeenCalled();
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
|
|
it('invalid target', async () => {
|
|
const onClick = jest.fn();
|
|
const { container } = render(<BackTop onClick={onClick} visible target={undefined} />);
|
|
fireEvent.click(container.querySelector('.ant-back-top')!);
|
|
expect(onClick).toHaveBeenCalled();
|
|
});
|
|
});
|