import { Plus } from '@transferwise/icons';
import { ControlType, Priority } from '../common';
import { render, screen, userEvent, mockMatchMedia } from '../test-utils';
import CircularButton from './CircularButton';
mockMatchMedia();
const { ACCENT, POSITIVE, NEGATIVE } = ControlType;
const { PRIMARY, SECONDARY } = Priority;
describe('CircularButton', () => {
const props = {
children: 'Add money',
icon: ,
onClick: jest.fn(),
};
describe('defaults', () => {
beforeEach(() => {
render();
});
it('renders the text', () => {
expect(screen.getByText('Add money')).toBeInTheDocument();
});
it('renders the provided icon', () => {
const icon = document.querySelector('.tw-icon');
expect(icon).toBeInTheDocument();
});
it('is not disabled', () => {
expect(screen.getByRole('button')).toBeEnabled();
});
});
describe('button attributes', () => {
it('disables the button if disabled', () => {
render();
expect(screen.getByRole('button')).toBeDisabled();
});
it('passes through custom classes if set', () => {
render();
const label = document.querySelector('label');
expect(label).toHaveClass('have-a-nice-day-:)');
});
});
describe('onClick', () => {
it('calls onClick when clicked', async () => {
const onClick = jest.fn();
render();
await userEvent.click(screen.getByRole('button'));
expect(onClick).toHaveBeenCalledTimes(1);
});
it('does not call onClick when clicked if disabled', async () => {
const onClick = jest.fn();
render();
await userEvent.click(screen.getByRole('button'));
expect(onClick).toHaveBeenCalledTimes(0);
});
});
});