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';
|
2023-02-16 21:42:15 +01:00
|
|
|
import { Color, SEVERITIES } from '../../../helpers/constants/design-system';
|
2023-04-05 18:11:10 +02:00
|
|
|
import { Icon, IconName } from '..';
|
2022-11-03 18:09:09 +01:00
|
|
|
|
|
|
|
import { HelpText } from './help-text';
|
|
|
|
|
|
|
|
describe('HelpText', () => {
|
|
|
|
it('should render with text inside the HelpText', () => {
|
2023-02-16 21:42:15 +01:00
|
|
|
const { getByText } = 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');
|
2023-02-16 21:42:15 +01:00
|
|
|
});
|
|
|
|
it('should match snapshot', () => {
|
|
|
|
const { container } = render(<HelpText>help text</HelpText>);
|
2022-11-29 22:00:51 +01:00
|
|
|
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-04-05 18:11:10 +02:00
|
|
|
help text <Icon name={IconName.Warning} data-testid="icon" as="span" />
|
2022-11-03 18:09:09 +01:00
|
|
|
</HelpText>,
|
|
|
|
);
|
|
|
|
expect(getByText('help text')).toBeDefined();
|
|
|
|
expect(getByTestId('icon')).toBeDefined();
|
|
|
|
});
|
2023-02-16 21:42:15 +01:00
|
|
|
it('should render with severities', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
|
|
|
<HelpText severity={SEVERITIES.DANGER}>error</HelpText>
|
|
|
|
<HelpText severity={SEVERITIES.SUCCESS}>success</HelpText>
|
|
|
|
<HelpText severity={SEVERITIES.WARNING}>warning</HelpText>
|
|
|
|
<HelpText severity={SEVERITIES.INFO}>info</HelpText>
|
|
|
|
</>,
|
|
|
|
);
|
2023-07-17 23:00:16 +02:00
|
|
|
expect(getByText('error')).toHaveClass('mm-box--color-error-default');
|
|
|
|
expect(getByText('success')).toHaveClass('mm-box--color-success-default');
|
|
|
|
expect(getByText('warning')).toHaveClass('mm-box--color-warning-default');
|
|
|
|
expect(getByText('info')).toHaveClass('mm-box--color-info-default');
|
2022-11-03 18:09:09 +01:00
|
|
|
});
|
|
|
|
it('should render with different colors', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
|
|
|
<HelpText>default</HelpText>
|
2023-02-16 21:42:15 +01:00
|
|
|
<HelpText color={Color.textDefault}>text default</HelpText>
|
|
|
|
<HelpText color={Color.textAlternative}>text alternative</HelpText>
|
|
|
|
<HelpText color={Color.textMuted}>text muted</HelpText>
|
2022-11-03 18:09:09 +01:00
|
|
|
</>,
|
|
|
|
);
|
2023-07-17 23:00:16 +02:00
|
|
|
expect(getByText('default')).toHaveClass('mm-box--color-text-default');
|
|
|
|
expect(getByText('text default')).toHaveClass('mm-box--color-text-default');
|
2023-02-16 21:42:15 +01:00
|
|
|
expect(getByText('text alternative')).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
'mm-box--color-text-alternative',
|
2023-02-16 21:42:15 +01:00
|
|
|
);
|
2023-07-17 23:00:16 +02:00
|
|
|
expect(getByText('text muted')).toHaveClass('mm-box--color-text-muted');
|
2023-02-16 21:42:15 +01:00
|
|
|
});
|
|
|
|
it('should render with a different html element if children is an object', () => {
|
|
|
|
const { getByText, getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<HelpText>help text as p</HelpText>
|
|
|
|
<HelpText data-testid="help-text-div">
|
2023-04-05 18:11:10 +02:00
|
|
|
<span>help text as div</span> <Icon name={IconName.Warning} />
|
2023-02-16 21:42:15 +01:00
|
|
|
</HelpText>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByText('help text as p')).toBeDefined();
|
|
|
|
expect(getByText('help text as p').tagName).toBe('P');
|
|
|
|
expect(getByText('help text as div')).toBeDefined();
|
|
|
|
expect(getByTestId('help-text-div').tagName).toBe('DIV');
|
2022-11-03 18:09:09 +01:00
|
|
|
});
|
|
|
|
});
|