/* eslint-disable jest/require-top-level-describe */
import { render } from '@testing-library/react';
import React from 'react';
import { IconName } from '..';
import { BUTTON_SIZES, BUTTON_VARIANT } from './button.constants';
import { Button } from './button';
describe('Button', () => {
it('should render button element correctly', () => {
const { getByTestId, getByText, container } = render(
,
);
expect(getByText('Button')).toBeDefined();
expect(container.querySelector('button')).toBeDefined();
expect(getByTestId('button')).toHaveClass('mm-button-base');
expect(container).toMatchSnapshot();
});
it('should render anchor element correctly', () => {
const { getByTestId, container } = render(
,
);
expect(getByTestId('button')).toHaveClass('mm-button-base');
const anchor = container.getElementsByTagName('a').length;
expect(anchor).toBe(1);
});
it('should render anchor element correctly by href only being passed', () => {
const { getByTestId, container } = render(
,
);
expect(getByTestId('button')).toHaveClass('mm-button-base');
const anchor = container.getElementsByTagName('a').length;
expect(anchor).toBe(1);
});
it('should render button as block', () => {
const { getByTestId } = render();
expect(getByTestId('block')).toHaveClass(`mm-button-base--block`);
});
it('should render with different button types', () => {
const { getByTestId, container } = render(
<>
>,
);
expect(getByTestId(BUTTON_VARIANT.PRIMARY)).toHaveClass(
`mm-button-${BUTTON_VARIANT.PRIMARY}`,
);
expect(getByTestId(BUTTON_VARIANT.SECONDARY)).toHaveClass(
`mm-button-${BUTTON_VARIANT.SECONDARY}`,
);
expect(getByTestId(BUTTON_VARIANT.LINK)).toHaveClass(
`mm-button-${BUTTON_VARIANT.LINK}`,
);
expect(container).toMatchSnapshot();
});
it('should render with different size classes', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId(BUTTON_SIZES.INHERIT)).toHaveClass(
`mm-button-link--size-${BUTTON_SIZES.INHERIT}`,
);
expect(getByTestId(BUTTON_SIZES.SM)).toHaveClass(
`mm-button-base--size-${BUTTON_SIZES.SM}`,
);
expect(getByTestId(BUTTON_SIZES.MD)).toHaveClass(
`mm-button-base--size-${BUTTON_SIZES.MD}`,
);
expect(getByTestId(BUTTON_SIZES.LG)).toHaveClass(
`mm-button-base--size-${BUTTON_SIZES.LG}`,
);
});
it('should render with added classname', () => {
const { getByTestId } = render(
,
);
expect(getByTestId('classname')).toHaveClass('mm-button-base--test');
});
it('should render with different button states', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId('loading')).toHaveClass(`mm-button-base--loading`);
expect(getByTestId('disabled')).toHaveClass(`mm-button-base--disabled`);
});
it('should render with icon', () => {
const { getByTestId } = render(
,
);
expect(getByTestId('start-button-icon')).toBeDefined();
});
});
it('should render as danger', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId('danger')).toHaveClass('mm-button-primary--type-danger');
});