2022-09-20 19:15:14 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
import { SIZES, COLORS } from '../../../helpers/constants/design-system';
|
2022-11-18 17:58:38 +01:00
|
|
|
import { ICON_NAMES } from './icon.constants';
|
2022-09-20 19:15:14 +02:00
|
|
|
import { Icon } from './icon';
|
|
|
|
|
|
|
|
describe('Icon', () => {
|
|
|
|
it('should render correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
2022-11-18 17:58:38 +01:00
|
|
|
<Icon name={ICON_NAMES.ADD_SQUARE_FILLED} data-testid="icon" />,
|
2022-09-20 19:15:14 +02:00
|
|
|
);
|
|
|
|
expect(getByTestId('icon')).toBeDefined();
|
|
|
|
expect(container.querySelector('svg')).toBeDefined();
|
|
|
|
});
|
|
|
|
it('should render with different icons using mask-image and image urls', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
data-testid="icon-add-square-filled"
|
|
|
|
/>
|
2022-11-18 17:58:38 +01:00
|
|
|
<Icon name={ICON_NAMES.BANK_FILLED} data-testid="icon-bank-filled" />
|
2022-09-20 19:15:14 +02:00
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.BOOKMARK_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
data-testid="icon-bookmark-filled"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.CALCULATOR_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
data-testid="icon-calculator-filled"
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
window.getComputedStyle(getByTestId('icon-add-square-filled')).maskImage,
|
2022-09-28 15:49:54 +02:00
|
|
|
).toBe(`url('./images/icons/icon-add-square-filled.svg`);
|
2022-09-20 19:15:14 +02:00
|
|
|
expect(
|
|
|
|
window.getComputedStyle(getByTestId('icon-bank-filled')).maskImage,
|
2022-09-28 15:49:54 +02:00
|
|
|
).toBe(`url('./images/icons/icon-bank-filled.svg`);
|
2022-09-20 19:15:14 +02:00
|
|
|
expect(
|
|
|
|
window.getComputedStyle(getByTestId('icon-bookmark-filled')).maskImage,
|
2022-09-28 15:49:54 +02:00
|
|
|
).toBe(`url('./images/icons/icon-bookmark-filled.svg`);
|
2022-09-20 19:15:14 +02:00
|
|
|
expect(
|
|
|
|
window.getComputedStyle(getByTestId('icon-calculator-filled')).maskImage,
|
2022-09-28 15:49:54 +02:00
|
|
|
).toBe(`url('./images/icons/icon-calculator-filled.svg`);
|
2022-09-20 19:15:14 +02:00
|
|
|
});
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
size={SIZES.XXS}
|
|
|
|
data-testid="icon-xxs"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
size={SIZES.XS}
|
|
|
|
data-testid="icon-xs"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
size={SIZES.SM}
|
|
|
|
data-testid="icon-sm"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
size={SIZES.MD}
|
|
|
|
data-testid="icon-md"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
size={SIZES.LG}
|
|
|
|
data-testid="icon-lg"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
size={SIZES.XL}
|
|
|
|
data-testid="icon-xl"
|
|
|
|
/>
|
2022-09-29 17:33:34 +02:00
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-29 17:33:34 +02:00
|
|
|
size={SIZES.AUTO}
|
|
|
|
data-testid="icon-auto"
|
|
|
|
/>
|
2022-09-20 19:15:14 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('icon-xxs')).toHaveClass('icon--size-xxs');
|
|
|
|
expect(getByTestId('icon-xs')).toHaveClass('icon--size-xs');
|
|
|
|
expect(getByTestId('icon-sm')).toHaveClass('icon--size-sm');
|
|
|
|
expect(getByTestId('icon-md')).toHaveClass('icon--size-md');
|
|
|
|
expect(getByTestId('icon-lg')).toHaveClass('icon--size-lg');
|
|
|
|
expect(getByTestId('icon-xl')).toHaveClass('icon--size-xl');
|
2022-09-29 17:33:34 +02:00
|
|
|
expect(getByTestId('icon-auto')).toHaveClass('icon--size-auto');
|
2022-09-20 19:15:14 +02:00
|
|
|
});
|
|
|
|
it('should render with icon colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
color={COLORS.ICON_DEFAULT}
|
|
|
|
data-testid="icon-color-default"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
color={COLORS.ICON_ALTERNATIVE}
|
|
|
|
data-testid="icon-color-alternative"
|
|
|
|
/>
|
|
|
|
<Icon
|
2022-11-18 17:58:38 +01:00
|
|
|
name={ICON_NAMES.ADD_SQUARE_FILLED}
|
2022-09-20 19:15:14 +02:00
|
|
|
color={COLORS.ICON_MUTED}
|
|
|
|
data-testid="icon-color-muted"
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('icon-color-default')).toHaveClass(
|
|
|
|
'box--color-icon-default',
|
|
|
|
);
|
|
|
|
expect(getByTestId('icon-color-alternative')).toHaveClass(
|
|
|
|
'box--color-icon-alternative',
|
|
|
|
);
|
|
|
|
expect(getByTestId('icon-color-muted')).toHaveClass(
|
|
|
|
'box--color-icon-muted',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|