import { h } from 'preact';
import { render, fireEvent } from '@testing-library/preact';
import { axe } from 'jest-axe';
import { Button } from '@crayons';
describe(' component', () => {
it('should have no a11y violations when rendered', async () => {
const { container } = render();
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('should render a primary button when using default values', () => {
const { container } = render();
expect(container.innerHTML).toMatchSnapshot();
});
it('should render with a tabIndex', () => {
const { container } = render();
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a secondary button when using the variant "secondary"', () => {
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should render an outlined button when using the variant "outlined"', () => {
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a danger button when using the variant "danger"', () => {
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should render an enabled button when using default values', () => {
const { container } = render();
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a disabled button when disabled is true', () => {
const { container } = render();
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a button with addtional CSS classes when className is set', () => {
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a button with with an icon when an icon is set and there is button text', () => {
const Icon = () => (
);
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a button with with an icon when an icon is set and there is no button text', () => {
const Icon = () => (
);
const { container } = render();
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a button as an anchor element if "tagName" is set to "a"', () => {
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should render a button as a specific button type (HTML type attribute) when buttonType is set.', () => {
const { container } = render(
,
);
expect(container.innerHTML).toMatchSnapshot();
});
it('should fire the onClick event when the button is clicked.', () => {
const someEvent = jest.fn();
const { getByText } = render(
,
);
const button = getByText('Hello world!');
button.click();
expect(someEvent).toHaveBeenCalledTimes(1);
});
it('should fire the onMouseOver event when the button is moused over.', () => {
const someEvent = jest.fn();
const { getByText } = render(
,
);
const button = getByText('Hello world!');
fireEvent.mouseOver(button);
expect(someEvent).toHaveBeenCalledTimes(1);
});
it('should fire the onMouseOut event when the button is moused out.', () => {
const someEvent = jest.fn();
const { getByText } = render(
,
);
const button = getByText('Hello world!');
fireEvent.mouseOut(button);
expect(someEvent).toHaveBeenCalledTimes(1);
});
it('should fire the onFocus event when the button is given focus.', () => {
const someEvent = jest.fn();
const { getByText } = render(
,
);
const button = getByText('Hello world!');
button.focus();
expect(someEvent).toHaveBeenCalledTimes(1);
});
it('should fire the onBlur event when the button loses focus.', () => {
const someEvent = jest.fn();
const { getByText } = render(
,
);
const button = getByText('Hello world!');
button.focus();
button.blur();
expect(someEvent).toHaveBeenCalledTimes(1);
});
});