2022-11-03 18:09:09 +01:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
import { COLORS } from '../../../helpers/constants/design-system';
|
|
|
|
import { Icon, ICON_NAMES } from '../icon';
|
|
|
|
|
|
|
|
import { HelpText } from './help-text';
|
|
|
|
|
|
|
|
describe('HelpText', () => {
|
|
|
|
it('should render with text inside the HelpText', () => {
|
2022-11-29 22:00:51 +01:00
|
|
|
const { getByText, container } = render(<HelpText>help text</HelpText>);
|
2022-11-03 18:09:09 +01:00
|
|
|
expect(getByText('help text')).toBeDefined();
|
2022-11-29 22:00:51 +01:00
|
|
|
expect(getByText('help text')).toHaveClass('mm-help-text');
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('should render with and additional className', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<HelpText className="test-class">help text</HelpText>,
|
|
|
|
);
|
|
|
|
expect(getByText('help text')).toHaveClass('mm-help-text test-class');
|
2022-11-03 18:09:09 +01:00
|
|
|
});
|
|
|
|
it('should render with react nodes inside the HelpText', () => {
|
|
|
|
const { getByText, getByTestId } = render(
|
|
|
|
<HelpText>
|
2023-01-24 18:39:46 +01:00
|
|
|
help text <Icon name={ICON_NAMES.WARNING} data-testid="icon" />
|
2022-11-03 18:09:09 +01:00
|
|
|
</HelpText>,
|
|
|
|
);
|
|
|
|
expect(getByText('help text')).toBeDefined();
|
|
|
|
expect(getByTestId('icon')).toBeDefined();
|
|
|
|
});
|
|
|
|
it('should render with error state', () => {
|
2022-11-29 22:00:51 +01:00
|
|
|
const { getByText } = render(<HelpText error>error</HelpText>);
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('error')).toHaveClass('mm-text--color-error-default');
|
2022-11-03 18:09:09 +01:00
|
|
|
});
|
|
|
|
it('should render with different colors', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
|
|
|
<HelpText>default</HelpText>
|
|
|
|
<HelpText color={COLORS.WARNING_DEFAULT}>warning</HelpText>
|
|
|
|
<HelpText color={COLORS.SUCCESS_DEFAULT}>success</HelpText>
|
|
|
|
<HelpText color={COLORS.INFO_DEFAULT}>info</HelpText>
|
|
|
|
</>,
|
|
|
|
);
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('default')).toHaveClass('mm-text--color-text-default');
|
|
|
|
expect(getByText('warning')).toHaveClass('mm-text--color-warning-default');
|
|
|
|
expect(getByText('success')).toHaveClass('mm-text--color-success-default');
|
|
|
|
expect(getByText('info')).toHaveClass('mm-text--color-info-default');
|
2022-11-03 18:09:09 +01:00
|
|
|
});
|
|
|
|
});
|