You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.9 KiB

feat: Float Button (#37520) * feat: add FloatButton * feat: add FloatButton * feat: FloatButton * feat: FloatButton * fix: fix * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * fix: add groupShape * feat: mergeShape * fix: fix * fix: fix style * fix: style fix * fix: fix * fix: style fix * fix: fix * fix: fix * fix: fix * fix: fix style * fix: fix style * fix: fix style * fix: style fix * feat: back-top * fix: style bug fix * fix: fix erroe * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * feat: add useMemo * docs: add docs * fix: bugFix * fix: bugFix * fix: bugfix * fix: style fix * fix: bugfix * test: add test case * fix: style fix * fix: style fix * fix: fix style * fix: fix style * fix: fix trigger action * fix: fix style * feat: add demo * fix: add demo * feat: add docs * fix: style ifx * feat: update maxSize of bundlesize * feat: add animation for group * fix: fix * fix: fix style * fix: fix test case * fix: fix test case * fix: fix type * fix: fix type * fix: update bundlesize * fix: fix * fix: fix style * fix: fix style * fix: updata snap * fix: fix CI * fix: fix style * fix: rename float button motion * fix: fix style * fix: bugFix * fix: fix style * fix: bugFix * fix: update docs * refactor: float button trigger * test: fix test case & update snapshot * fix: delete rest * docs: update demo * test: update snapshot * fix: fix eslint error * test: update snapshot * style: update icon fontSize to 18 * fix: fix style * fix: style fix * fix: test case fix * test: add test case * fix: style fix * test: update snap * fix: style fix * fix: style fix * fix: style fix * docs: demo update * fix: style fix * docs: update demo * test: update snapshot Co-authored-by: 黑雨 <wangning4567@163.com> Co-authored-by: MadCcc <1075746765@qq.com>
2 years ago
import React from 'react';
import FloatButton from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
feat: Float Button (#37520) * feat: add FloatButton * feat: add FloatButton * feat: FloatButton * feat: FloatButton * fix: fix * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * fix: add groupShape * feat: mergeShape * fix: fix * fix: fix style * fix: style fix * fix: fix * fix: style fix * fix: fix * fix: fix * fix: fix * fix: fix style * fix: fix style * fix: fix style * fix: style fix * feat: back-top * fix: style bug fix * fix: fix erroe * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * feat: add useMemo * docs: add docs * fix: bugFix * fix: bugFix * fix: bugfix * fix: style fix * fix: bugfix * test: add test case * fix: style fix * fix: style fix * fix: fix style * fix: fix style * fix: fix trigger action * fix: fix style * feat: add demo * fix: add demo * feat: add docs * fix: style ifx * feat: update maxSize of bundlesize * feat: add animation for group * fix: fix * fix: fix style * fix: fix test case * fix: fix test case * fix: fix type * fix: fix type * fix: update bundlesize * fix: fix * fix: fix style * fix: fix style * fix: updata snap * fix: fix CI * fix: fix style * fix: rename float button motion * fix: fix style * fix: bugFix * fix: fix style * fix: bugFix * fix: update docs * refactor: float button trigger * test: fix test case & update snapshot * fix: delete rest * docs: update demo * test: update snapshot * fix: fix eslint error * test: update snapshot * style: update icon fontSize to 18 * fix: fix style * fix: style fix * fix: test case fix * test: add test case * fix: style fix * test: update snap * fix: style fix * fix: style fix * fix: style fix * docs: demo update * fix: style fix * docs: update demo * test: update snapshot Co-authored-by: 黑雨 <wangning4567@163.com> Co-authored-by: MadCcc <1075746765@qq.com>
2 years ago
describe('FloatButton', () => {
mountTest(FloatButton);
rtlTest(FloatButton);
it('should correct render', () => {
const { container } = render(<FloatButton />);
expect(container.firstChild).toMatchSnapshot();
});
it('should render <button> when harf not exist', () => {
const { container } = render(<FloatButton href={undefined} />);
expect(container.querySelector('button')).toBeTruthy();
});
it('should render <a> when harf exist', () => {
const url = 'https://ant.design/index-cn';
const target = '_blank';
const { container } = render(<FloatButton href={url} target={target} />);
expect(container.querySelector('a')).toBeTruthy();
expect(container.querySelector('a')?.href).toBe(url);
expect(container.querySelector('a')?.target).toBe(target);
});
it('support type', () => {
const [defaultType, primaryType] = ['default', 'primary'] as const;
const { container, rerender } = render(<FloatButton type={defaultType} />);
expect(container.querySelector(`.ant-float-btn-${defaultType}`)).toBeTruthy();
rerender(<FloatButton type={primaryType} />);
expect(container.querySelector(`.ant-float-btn-${primaryType}`)).toBeTruthy();
});
it('support shape', () => {
const [defaultShape, squareShape] = ['circle', 'square'] as const;
const { container, rerender } = render(<FloatButton shape={defaultShape} />);
expect(container.querySelector(`.ant-float-btn-${defaultShape}`)).toBeTruthy();
rerender(<FloatButton shape={squareShape} />);
expect(container.querySelector(`.ant-float-btn-${squareShape}`)).toBeTruthy();
});
it('support onClick', () => {
const onClick = jest.fn();
const { container } = render(<FloatButton onClick={onClick} />);
fireEvent.click(container.querySelector('.ant-float-btn')!);
expect(onClick).toHaveBeenCalled();
});
it('should console Error', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<FloatButton description="test" shape="circle" />);
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: FloatButton] supported only when `shape` is `square`. Due to narrow space for text, short sentence is recommended.',
);
errSpy.mockRestore();
});
it('tooltip should support number `0`', async () => {
jest.useFakeTimers();
const { container } = render(<FloatButton tooltip={0} />);
fireEvent.mouseEnter(container.querySelector<HTMLDivElement>('.ant-float-btn-body')!);
await waitFakeTimer();
const element = container.querySelector('.ant-tooltip')?.querySelector('.ant-tooltip-inner');
expect(element?.textContent).toBe('0');
jest.clearAllTimers();
jest.useRealTimers();
});
feat: Float Button (#37520) * feat: add FloatButton * feat: add FloatButton * feat: FloatButton * feat: FloatButton * fix: fix * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * fix: add groupShape * feat: mergeShape * fix: fix * fix: fix style * fix: style fix * fix: fix * fix: style fix * fix: fix * fix: fix * fix: fix * fix: fix style * fix: fix style * fix: fix style * fix: style fix * feat: back-top * fix: style bug fix * fix: fix erroe * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * feat: add useMemo * docs: add docs * fix: bugFix * fix: bugFix * fix: bugfix * fix: style fix * fix: bugfix * test: add test case * fix: style fix * fix: style fix * fix: fix style * fix: fix style * fix: fix trigger action * fix: fix style * feat: add demo * fix: add demo * feat: add docs * fix: style ifx * feat: update maxSize of bundlesize * feat: add animation for group * fix: fix * fix: fix style * fix: fix test case * fix: fix test case * fix: fix type * fix: fix type * fix: update bundlesize * fix: fix * fix: fix style * fix: fix style * fix: updata snap * fix: fix CI * fix: fix style * fix: rename float button motion * fix: fix style * fix: bugFix * fix: fix style * fix: bugFix * fix: update docs * refactor: float button trigger * test: fix test case &amp; update snapshot * fix: delete rest * docs: update demo * test: update snapshot * fix: fix eslint error * test: update snapshot * style: update icon fontSize to 18 * fix: fix style * fix: style fix * fix: test case fix * test: add test case * fix: style fix * test: update snap * fix: style fix * fix: style fix * fix: style fix * docs: demo update * fix: style fix * docs: update demo * test: update snapshot Co-authored-by: 黑雨 &lt;wangning4567@163.com&gt; Co-authored-by: MadCcc &lt;1075746765@qq.com&gt;
2 years ago
});