2022-10-14 00:39:22 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
import { SIZES } from '../../../helpers/constants/design-system';
|
|
|
|
import { ButtonLink } from './button-link';
|
|
|
|
|
|
|
|
describe('ButtonLink', () => {
|
|
|
|
it('should render button element correctly', () => {
|
|
|
|
const { getByText, getByTestId, container } = render(
|
|
|
|
<ButtonLink data-testid="button-link">Button Link</ButtonLink>,
|
|
|
|
);
|
|
|
|
expect(getByText('Button Link')).toBeDefined();
|
|
|
|
expect(container.querySelector('button')).toBeDefined();
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('button-link')).toHaveClass('mm-button-base');
|
2022-11-18 21:36:33 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-10-14 00:39:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render anchor element correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<ButtonLink as="a" data-testid="button-link" />,
|
|
|
|
);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('button-link')).toHaveClass('mm-button-base');
|
2022-10-14 00:39:22 +02:00
|
|
|
const anchor = container.getElementsByTagName('a').length;
|
|
|
|
expect(anchor).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render button as block', () => {
|
|
|
|
const { getByTestId } = render(<ButtonLink block data-testid="block" />);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('block')).toHaveClass(`mm-button-base--block`);
|
2022-10-14 00:39:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with added classname', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<ButtonLink data-testid="classname" className="mm-button--test" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('classname')).toHaveClass('mm-button--test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonLink size={SIZES.SM} data-testid={SIZES.SM} />
|
|
|
|
<ButtonLink size={SIZES.MD} data-testid={SIZES.MD} />
|
|
|
|
<ButtonLink size={SIZES.LG} data-testid={SIZES.LG} />
|
|
|
|
<ButtonLink size={SIZES.AUTO} data-testid={SIZES.AUTO} />
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId(SIZES.SM)).toHaveClass(
|
|
|
|
`mm-button-base--size-${SIZES.SM}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(SIZES.MD)).toHaveClass(
|
|
|
|
`mm-button-base--size-${SIZES.MD}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(SIZES.LG)).toHaveClass(
|
|
|
|
`mm-button-base--size-${SIZES.LG}`,
|
|
|
|
);
|
2022-10-14 00:39:22 +02:00
|
|
|
expect(getByTestId(SIZES.AUTO)).toHaveClass(
|
2023-01-13 22:58:09 +01:00
|
|
|
`mm-button-base--size-${SIZES.AUTO}`,
|
2022-10-14 00:39:22 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-11-09 22:55:13 +01:00
|
|
|
it('should render as danger', () => {
|
2022-10-14 00:39:22 +02:00
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonLink danger data-testid="danger" />
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId('danger')).toHaveClass('mm-button-link--type-danger');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different button states', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonLink loading data-testid="loading" />
|
|
|
|
<ButtonLink disabled data-testid="disabled" />
|
|
|
|
</>,
|
|
|
|
);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('loading')).toHaveClass(`mm-button-base--loading`);
|
|
|
|
expect(getByTestId('disabled')).toHaveClass(`mm-button-base--disabled`);
|
2022-10-14 00:39:22 +02:00
|
|
|
});
|
|
|
|
it('should render with icon', () => {
|
|
|
|
const { container } = render(
|
2023-01-25 19:11:13 +01:00
|
|
|
<ButtonLink data-testid="icon" iconName="add-square" />,
|
2022-10-14 00:39:22 +02:00
|
|
|
);
|
|
|
|
|
2022-11-23 18:58:43 +01:00
|
|
|
const icons = container.getElementsByClassName('mm-icon').length;
|
2022-10-14 00:39:22 +02:00
|
|
|
expect(icons).toBe(1);
|
|
|
|
});
|
|
|
|
});
|