2022-10-06 06:51:02 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
2023-04-05 18:11:10 +02:00
|
|
|
import { IconName } from '..';
|
2023-08-04 19:45:55 +02:00
|
|
|
import { ButtonPrimary, ButtonPrimarySize } from '.';
|
2022-10-06 06:51:02 +02:00
|
|
|
|
|
|
|
describe('ButtonPrimary', () => {
|
|
|
|
it('should render button element correctly', () => {
|
|
|
|
const { getByText, getByTestId, container } = render(
|
|
|
|
<ButtonPrimary data-testid="button-primary">
|
|
|
|
Button Primary
|
|
|
|
</ButtonPrimary>,
|
|
|
|
);
|
|
|
|
expect(getByText('Button Primary')).toBeDefined();
|
|
|
|
expect(container.querySelector('button')).toBeDefined();
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('button-primary')).toHaveClass('mm-button-base');
|
2022-11-14 22:41:03 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-10-06 06:51:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render anchor element correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<ButtonPrimary as="a" data-testid="button-primary" />,
|
|
|
|
);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('button-primary')).toHaveClass('mm-button-base');
|
2022-10-06 06:51:02 +02:00
|
|
|
const anchor = container.getElementsByTagName('a').length;
|
|
|
|
expect(anchor).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render button as block', () => {
|
|
|
|
const { getByTestId } = render(<ButtonPrimary block data-testid="block" />);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('block')).toHaveClass(`mm-button-base--block`);
|
2022-10-06 06:51:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with added classname', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<ButtonPrimary data-testid="classname" className="mm-button--test" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('classname')).toHaveClass('mm-button--test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonPrimary
|
2023-08-04 19:45:55 +02:00
|
|
|
size={ButtonPrimarySize.Sm}
|
|
|
|
data-testid={ButtonPrimarySize.Sm}
|
2022-10-06 06:51:02 +02:00
|
|
|
/>
|
|
|
|
<ButtonPrimary
|
2023-08-04 19:45:55 +02:00
|
|
|
size={ButtonPrimarySize.Md}
|
|
|
|
data-testid={ButtonPrimarySize.Md}
|
2022-10-06 06:51:02 +02:00
|
|
|
/>
|
|
|
|
<ButtonPrimary
|
2023-08-04 19:45:55 +02:00
|
|
|
size={ButtonPrimarySize.Lg}
|
|
|
|
data-testid={ButtonPrimarySize.Lg}
|
2022-10-06 06:51:02 +02:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
2023-08-04 19:45:55 +02:00
|
|
|
expect(getByTestId(ButtonPrimarySize.Sm)).toHaveClass(
|
|
|
|
`mm-button-base--size-${ButtonPrimarySize.Sm}`,
|
2022-10-06 06:51:02 +02:00
|
|
|
);
|
2023-08-04 19:45:55 +02:00
|
|
|
expect(getByTestId(ButtonPrimarySize.Md)).toHaveClass(
|
|
|
|
`mm-button-base--size-${ButtonPrimarySize.Md}`,
|
2022-10-06 06:51:02 +02:00
|
|
|
);
|
2023-08-04 19:45:55 +02:00
|
|
|
expect(getByTestId(ButtonPrimarySize.Lg)).toHaveClass(
|
|
|
|
`mm-button-base--size-${ButtonPrimarySize.Lg}`,
|
2022-10-06 06:51:02 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-11-09 22:55:13 +01:00
|
|
|
it('should render as danger', () => {
|
2022-10-06 06:51:02 +02:00
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonPrimary danger data-testid="danger" />
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId('danger')).toHaveClass('mm-button-primary--type-danger');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different button states', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonPrimary loading data-testid="loading" />
|
|
|
|
<ButtonPrimary 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-06 06:51:02 +02:00
|
|
|
});
|
|
|
|
it('should render with icon', () => {
|
|
|
|
const { container } = render(
|
2023-04-05 18:11:10 +02:00
|
|
|
<ButtonPrimary data-testid="icon" startIconName={IconName.AddSquare} />,
|
2022-10-06 06:51:02 +02:00
|
|
|
);
|
|
|
|
|
2022-11-23 18:58:43 +01:00
|
|
|
const icons = container.getElementsByClassName('mm-icon').length;
|
2022-10-06 06:51:02 +02:00
|
|
|
expect(icons).toBe(1);
|
|
|
|
});
|
|
|
|
});
|