2022-10-07 17:50:28 +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-15 00:13:15 +02:00
|
|
|
import { ButtonSecondary, ButtonSecondarySize } from '.';
|
2022-10-07 17:50:28 +02:00
|
|
|
|
|
|
|
describe('ButtonSecondary', () => {
|
|
|
|
it('should render button element correctly', () => {
|
|
|
|
const { getByText, getByTestId, container } = render(
|
|
|
|
<ButtonSecondary data-testid="button-secondary">
|
|
|
|
Button Secondary
|
|
|
|
</ButtonSecondary>,
|
|
|
|
);
|
|
|
|
expect(getByText('Button Secondary')).toBeDefined();
|
|
|
|
expect(container.querySelector('button')).toBeDefined();
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('button-secondary')).toHaveClass('mm-button-base');
|
2022-11-15 21:48:24 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-10-07 17:50:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render anchor element correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<ButtonSecondary as="a" data-testid="button-secondary" />,
|
|
|
|
);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('button-secondary')).toHaveClass('mm-button-base');
|
2022-10-07 17:50:28 +02:00
|
|
|
const anchor = container.getElementsByTagName('a').length;
|
|
|
|
expect(anchor).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render button as block', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<ButtonSecondary block data-testid="block" />,
|
|
|
|
);
|
2023-01-13 22:58:09 +01:00
|
|
|
expect(getByTestId('block')).toHaveClass(`mm-button-base--block`);
|
2022-10-07 17:50:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with added classname', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<ButtonSecondary data-testid="classname" className="mm-button--test" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('classname')).toHaveClass('mm-button--test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonSecondary
|
2023-08-15 00:13:15 +02:00
|
|
|
size={ButtonSecondarySize.Sm}
|
|
|
|
data-testid={ButtonSecondarySize.Sm}
|
2022-10-07 17:50:28 +02:00
|
|
|
/>
|
|
|
|
<ButtonSecondary
|
2023-08-15 00:13:15 +02:00
|
|
|
size={ButtonSecondarySize.Md}
|
|
|
|
data-testid={ButtonSecondarySize.Md}
|
2022-10-07 17:50:28 +02:00
|
|
|
/>
|
|
|
|
<ButtonSecondary
|
2023-08-15 00:13:15 +02:00
|
|
|
size={ButtonSecondarySize.Lg}
|
|
|
|
data-testid={ButtonSecondarySize.Lg}
|
2022-10-07 17:50:28 +02:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
2023-08-15 00:13:15 +02:00
|
|
|
expect(getByTestId(ButtonSecondarySize.Sm)).toHaveClass(
|
|
|
|
`mm-button-base--size-${ButtonSecondarySize.Sm}`,
|
2022-10-07 17:50:28 +02:00
|
|
|
);
|
2023-08-15 00:13:15 +02:00
|
|
|
expect(getByTestId(ButtonSecondarySize.Md)).toHaveClass(
|
|
|
|
`mm-button-base--size-${ButtonSecondarySize.Md}`,
|
2022-10-07 17:50:28 +02:00
|
|
|
);
|
2023-08-15 00:13:15 +02:00
|
|
|
expect(getByTestId(ButtonSecondarySize.Lg)).toHaveClass(
|
|
|
|
`mm-button-base--size-${ButtonSecondarySize.Lg}`,
|
2022-10-07 17:50:28 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-11-09 22:55:13 +01:00
|
|
|
it('should render as danger', () => {
|
2022-10-07 17:50:28 +02:00
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonSecondary danger data-testid="danger" />
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId('danger')).toHaveClass(
|
|
|
|
'mm-button-secondary--type-danger',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different button states', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonSecondary loading data-testid="loading" />
|
|
|
|
<ButtonSecondary 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-07 17:50:28 +02:00
|
|
|
});
|
|
|
|
it('should render with icon', () => {
|
|
|
|
const { container } = render(
|
2023-04-05 18:11:10 +02:00
|
|
|
<ButtonSecondary data-testid="icon" startIconName={IconName.AddSquare} />,
|
2022-10-07 17:50:28 +02:00
|
|
|
);
|
|
|
|
|
2022-11-23 18:58:43 +01:00
|
|
|
const icons = container.getElementsByClassName('mm-icon').length;
|
2022-10-07 17:50:28 +02:00
|
|
|
expect(icons).toBe(1);
|
|
|
|
});
|
|
|
|
});
|