import { render, screen, userEvent } from '../test-utils';
import ActionButton from '.';
describe('ActionButton', () => {
const props = {
children: 'Personal profile',
onClick: jest.fn(),
};
describe('by default', () => {
beforeEach(() => {
render();
});
it('renders the text', () => {
expect(screen.getByText('Personal profile')).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();
expect(screen.getByRole('button')).toHaveClass('catsarethebest');
});
});
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);
});
});
describe('deprecated', () => {
it('text prop', () => {
const copy = 'Text prop';
const onClick = jest.fn();
render();
expect(screen.getByText(copy)).toBeInTheDocument();
});
});
describe('priority', () => {
it('is rendered for primary', () => {
render();
expect(screen.getByRole('button')).toHaveClass('btn-priority-1');
});
it('is rendered for secondary', () => {
render();
expect(screen.getByRole('button')).toHaveClass('btn-priority-2');
});
it('is backwards compatible if nothing is passed in', () => {
render();
expect(screen.getByRole('button')).toHaveClass('btn-priority-1');
});
});
});