import React from 'react';
import FloatButton from '..';
import { fireEvent, render } from '../../../tests/utils';
describe('FloatButtonGroup', () => {
it('should correct render', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
it('support shape', () => {
const [defaultShape, squareShape] = ['circle', 'square'] as const;
const { container, rerender } = render(
,
);
expect(container.querySelectorAll(`.ant-float-btn-${defaultShape}`)).toHaveLength(3);
rerender(
,
);
expect(container.querySelectorAll(`.ant-float-btn-${squareShape}`)).toHaveLength(3);
});
it('support onOpenChange for click', () => {
const onOpenChange = jest.fn();
const { container } = render(
,
);
fireEvent.click(container.querySelector('.ant-float-btn')!);
expect(onOpenChange).toHaveBeenCalled();
});
it('support onOpenChange for hover', () => {
const onOpenChange = jest.fn();
const { container } = render(
,
);
fireEvent.mouseEnter(container.querySelector('.ant-float-btn-group')!);
fireEvent.mouseLeave(container.querySelector('.ant-float-btn-group')!);
expect(onOpenChange).toHaveBeenCalled();
});
it('support click floatButtonGroup not close', () => {
const onOpenChange = jest.fn();
const { container } = render(
,
);
fireEvent.click(container.querySelector('.ant-float-btn')!);
fireEvent.click(container.querySelector('.ant-float-btn-group')!);
expect(onOpenChange).toHaveBeenCalledTimes(1);
});
it('support click out auto close', () => {
const onOpenChange = jest.fn();
const { container } = render(
,
);
fireEvent.click(container.querySelector('.ant-float-btn')!);
fireEvent.click(container);
expect(onOpenChange).toHaveBeenCalledTimes(2);
});
it('warning if set `open` but not set `trigger`', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(
,
);
expect(warnSpy).not.toHaveBeenCalled();
render(
,
);
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [antd: FloatButton.Group] `open` need to be used together with `trigger`',
);
warnSpy.mockRestore();
});
it('menu should support badge', () => {
const { container } = render(
,
);
expect(container.querySelector('.ant-badge')).toBeTruthy();
});
it('FloatButton.Group should support placement', () => {
(['bottom', 'left', 'right', 'top'] as const).forEach((placement) => {
const { container } = render(
,
);
const element = container.querySelector('.ant-float-btn-group');
expect(element).toHaveClass(`ant-float-btn-group-${placement}`);
});
});
});