2022-11-09 22:57:21 +01:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
2023-02-02 21:15:26 +01:00
|
|
|
import { IconColor } from '../../../helpers/constants/design-system';
|
2023-04-05 18:11:10 +02:00
|
|
|
import { IconName } from '..';
|
2023-04-12 17:55:24 +02:00
|
|
|
import { ButtonIconSize } from './button-icon.types';
|
2022-11-09 22:57:21 +01:00
|
|
|
import { ButtonIcon } from './button-icon';
|
|
|
|
|
|
|
|
describe('ButtonIcon', () => {
|
|
|
|
it('should render button element correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<ButtonIcon
|
|
|
|
data-testid="button-icon"
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(container.querySelector('button')).toBeDefined();
|
|
|
|
expect(getByTestId('button-icon')).toHaveClass('mm-button-icon');
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render anchor element correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<ButtonIcon
|
|
|
|
as="a"
|
|
|
|
data-testid="button-icon"
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('button-icon')).toHaveClass('mm-button-icon');
|
|
|
|
const anchor = container.getElementsByTagName('a').length;
|
|
|
|
expect(anchor).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render anchor element correctly using href', () => {
|
|
|
|
const { getByTestId, getByRole } = render(
|
|
|
|
<ButtonIcon
|
|
|
|
href="/metamask"
|
|
|
|
data-testid="button-icon"
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('button-icon')).toHaveClass('mm-button-icon');
|
|
|
|
expect(getByRole('link')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
2023-04-12 17:55:24 +02:00
|
|
|
size={ButtonIconSize.Sm}
|
|
|
|
data-testid={ButtonIconSize.Sm}
|
2022-11-09 22:57:21 +01:00
|
|
|
/>
|
2023-07-13 22:22:40 +02:00
|
|
|
<ButtonIcon
|
|
|
|
iconName={IconName.AddSquare}
|
|
|
|
ariaLabel="add"
|
|
|
|
size={ButtonIconSize.Md}
|
|
|
|
data-testid={ButtonIconSize.Md}
|
|
|
|
/>
|
2022-11-09 22:57:21 +01:00
|
|
|
<ButtonIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
2023-04-12 17:55:24 +02:00
|
|
|
size={ButtonIconSize.Lg}
|
|
|
|
data-testid={ButtonIconSize.Lg}
|
2022-11-09 22:57:21 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-04-12 17:55:24 +02:00
|
|
|
expect(getByTestId(ButtonIconSize.Sm)).toHaveClass(
|
|
|
|
`mm-button-icon--size-${ButtonIconSize.Sm}`,
|
2022-11-09 22:57:21 +01:00
|
|
|
);
|
2023-07-13 22:22:40 +02:00
|
|
|
expect(getByTestId(ButtonIconSize.Md)).toHaveClass(
|
|
|
|
`mm-button-icon--size-${ButtonIconSize.Md}`,
|
|
|
|
);
|
2023-04-12 17:55:24 +02:00
|
|
|
expect(getByTestId(ButtonIconSize.Lg)).toHaveClass(
|
|
|
|
`mm-button-icon--size-${ButtonIconSize.Lg}`,
|
2022-11-09 22:57:21 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={IconColor.iconDefault}
|
|
|
|
data-testid={IconColor.iconDefault}
|
2022-11-09 22:57:21 +01:00
|
|
|
/>
|
|
|
|
<ButtonIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={IconColor.errorDefault}
|
|
|
|
data-testid={IconColor.errorDefault}
|
2022-11-09 22:57:21 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(IconColor.iconDefault)).toHaveClass(
|
2023-08-03 21:23:47 +02:00
|
|
|
`mm-box--color-${IconColor.iconDefault}`,
|
2022-11-09 22:57:21 +01:00
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(IconColor.errorDefault)).toHaveClass(
|
2023-08-03 21:23:47 +02:00
|
|
|
`mm-box--color-${IconColor.errorDefault}`,
|
2022-11-09 22:57:21 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with added classname', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<ButtonIcon
|
|
|
|
data-testid="classname"
|
|
|
|
className="mm-button-icon--test"
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('classname')).toHaveClass('mm-button-icon--test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different button states', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<ButtonIcon
|
|
|
|
disabled
|
|
|
|
data-testid="disabled"
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId('disabled')).toHaveClass(`mm-button-icon--disabled`);
|
|
|
|
expect(getByTestId('disabled')).toBeDisabled();
|
|
|
|
});
|
|
|
|
it('should render with icon', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<ButtonIcon
|
|
|
|
data-testid="icon"
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.AddSquare}
|
2022-11-09 22:57:21 +01:00
|
|
|
ariaLabel="add"
|
|
|
|
iconProps={{ 'data-testid': 'button-icon' }}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId('button-icon')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with aria-label', () => {
|
|
|
|
const { getByLabelText } = render(
|
2023-04-05 18:11:10 +02:00
|
|
|
<ButtonIcon iconName={IconName.AddSquare} ariaLabel="add" />,
|
2022-11-09 22:57:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByLabelText('add')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|