2022-08-18 19:51:53 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import {
|
2023-04-17 19:17:28 +02:00
|
|
|
FontStyle,
|
|
|
|
FontWeight,
|
|
|
|
OverflowWrap,
|
|
|
|
TextAlign,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
2023-04-17 19:17:28 +02:00
|
|
|
TextTransform,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextVariant,
|
|
|
|
Color,
|
2022-08-18 19:51:53 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-04-03 19:42:37 +02:00
|
|
|
import { TextDirection, ValidTag } from './text.types';
|
|
|
|
import { Text } from '.';
|
2022-08-18 19:51:53 +02:00
|
|
|
|
|
|
|
describe('Text', () => {
|
|
|
|
it('should render the Text without crashing', () => {
|
|
|
|
const { getByText } = render(<Text>Test type</Text>);
|
|
|
|
expect(getByText('Test type')).toBeDefined();
|
|
|
|
});
|
|
|
|
it('should render the Text with correct html elements', () => {
|
|
|
|
const { getByText, container } = render(
|
|
|
|
<>
|
2023-04-03 19:42:37 +02:00
|
|
|
<Text as={ValidTag.P}>p</Text>
|
|
|
|
<Text as={ValidTag.H1}>h1</Text>
|
|
|
|
<Text as={ValidTag.H2}>h2</Text>
|
|
|
|
<Text as={ValidTag.H3}>h3</Text>
|
|
|
|
<Text as={ValidTag.H4}>h4</Text>
|
|
|
|
<Text as={ValidTag.H5}>h5</Text>
|
|
|
|
<Text as={ValidTag.H6}>h6</Text>
|
|
|
|
<Text as={ValidTag.Span}>span</Text>
|
|
|
|
<Text as={ValidTag.Strong}>strong</Text>
|
|
|
|
<Text as={ValidTag.Em}>em</Text>
|
|
|
|
<Text as={ValidTag.Li}>li</Text>
|
|
|
|
<Text as={ValidTag.Div}>div</Text>
|
|
|
|
<Text as={ValidTag.Dt}>dt</Text>
|
|
|
|
<Text as={ValidTag.Dd}>dd</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(container.querySelector('p')).toBeDefined();
|
|
|
|
expect(getByText('p')).toBeDefined();
|
|
|
|
expect(container.querySelector('h1')).toBeDefined();
|
|
|
|
expect(getByText('h1')).toBeDefined();
|
|
|
|
expect(container.querySelector('h2')).toBeDefined();
|
|
|
|
expect(getByText('h2')).toBeDefined();
|
|
|
|
expect(container.querySelector('h3')).toBeDefined();
|
|
|
|
expect(getByText('h3')).toBeDefined();
|
|
|
|
expect(container.querySelector('h4')).toBeDefined();
|
|
|
|
expect(getByText('h4')).toBeDefined();
|
|
|
|
expect(container.querySelector('h5')).toBeDefined();
|
|
|
|
expect(getByText('h5')).toBeDefined();
|
|
|
|
expect(container.querySelector('h6')).toBeDefined();
|
|
|
|
expect(getByText('h6')).toBeDefined();
|
|
|
|
expect(container.querySelector('span')).toBeDefined();
|
|
|
|
expect(getByText('span')).toBeDefined();
|
|
|
|
expect(container.querySelector('strong')).toBeDefined();
|
|
|
|
expect(getByText('strong')).toBeDefined();
|
|
|
|
expect(container.querySelector('em')).toBeDefined();
|
|
|
|
expect(getByText('em')).toBeDefined();
|
|
|
|
expect(container.querySelector('li')).toBeDefined();
|
|
|
|
expect(getByText('li')).toBeDefined();
|
|
|
|
expect(container.querySelector('div')).toBeDefined();
|
|
|
|
expect(getByText('div')).toBeDefined();
|
|
|
|
expect(container.querySelector('dt')).toBeDefined();
|
|
|
|
expect(getByText('dt')).toBeDefined();
|
|
|
|
expect(container.querySelector('dd')).toBeDefined();
|
|
|
|
expect(getByText('dd')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper variant class name', () => {
|
2022-12-01 18:26:19 +01:00
|
|
|
const { getByText, container } = render(
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Text variant={TextVariant.displayMd}>display-md</Text>
|
|
|
|
<Text variant={TextVariant.headingLg}>heading-lg</Text>
|
|
|
|
<Text variant={TextVariant.headingMd}>heading-md</Text>
|
|
|
|
<Text variant={TextVariant.headingSm}>heading-sm</Text>
|
|
|
|
<Text variant={TextVariant.bodyLgMedium}>body-lg-medium</Text>
|
|
|
|
<Text variant={TextVariant.bodyMd}>body-md</Text>
|
|
|
|
<Text variant={TextVariant.bodyMdBold}>body-md-bold</Text>
|
|
|
|
<Text variant={TextVariant.bodySm}>body-sm</Text>
|
|
|
|
<Text variant={TextVariant.bodySmBold}>body-sm-bold</Text>
|
|
|
|
<Text variant={TextVariant.bodyXs}>body-xs</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('display-md')).toHaveClass('mm-text--display-md');
|
|
|
|
expect(getByText('heading-lg')).toHaveClass('mm-text--heading-lg');
|
|
|
|
expect(getByText('heading-md')).toHaveClass('mm-text--heading-md');
|
|
|
|
expect(getByText('heading-sm')).toHaveClass('mm-text--heading-sm');
|
|
|
|
expect(getByText('body-lg-medium')).toHaveClass('mm-text--body-lg-medium');
|
|
|
|
expect(getByText('body-md')).toHaveClass('mm-text--body-md');
|
|
|
|
expect(getByText('body-md-bold')).toHaveClass('mm-text--body-md-bold');
|
|
|
|
expect(getByText('body-sm')).toHaveClass('mm-text--body-sm');
|
|
|
|
expect(getByText('body-sm-bold')).toHaveClass('mm-text--body-sm-bold');
|
|
|
|
expect(getByText('body-xs')).toHaveClass('mm-text--body-xs');
|
|
|
|
expect(container).toMatchSnapshot();
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper font weight class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-04-17 19:17:28 +02:00
|
|
|
<Text fontWeight={FontWeight.Bold}>bold</Text>
|
|
|
|
<Text fontWeight={FontWeight.Medium}>medium</Text>
|
|
|
|
<Text fontWeight={FontWeight.Normal}>normal</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('bold')).toHaveClass('mm-text--font-weight-bold');
|
|
|
|
expect(getByText('medium')).toHaveClass('mm-text--font-weight-medium');
|
|
|
|
expect(getByText('normal')).toHaveClass('mm-text--font-weight-normal');
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper text color class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Text color={TextColor.textDefault}>text-default</Text>
|
|
|
|
<Text color={TextColor.textAlternative}>text-alternative</Text>
|
|
|
|
<Text color={TextColor.textMuted}>text-muted</Text>
|
|
|
|
<Text color={Color.overlayInverse}>overlay-inverse</Text>
|
|
|
|
<Text color={TextColor.primaryDefault}>primary-default</Text>
|
|
|
|
<Text color={TextColor.primaryInverse}>primary-inverse</Text>
|
|
|
|
<Text color={TextColor.errorDefault}>error-default</Text>
|
|
|
|
<Text color={TextColor.errorInverse}>error-inverse</Text>
|
|
|
|
<Text color={TextColor.successDefault}>success-default</Text>
|
|
|
|
<Text color={TextColor.successInverse}>success-inverse</Text>
|
|
|
|
<Text color={TextColor.warningInverse}>warning-inverse</Text>
|
|
|
|
<Text color={TextColor.infoDefault}>info-default</Text>
|
|
|
|
<Text color={TextColor.infoInverse}>info-inverse</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
2023-03-23 21:00:37 +01:00
|
|
|
expect(getByText('text-default')).toHaveClass('box--color-text-default');
|
2022-08-18 19:51:53 +02:00
|
|
|
expect(getByText('text-alternative')).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
'box--color-text-alternative',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
2023-03-23 21:00:37 +01:00
|
|
|
expect(getByText('text-muted')).toHaveClass('box--color-text-muted');
|
2022-08-18 19:51:53 +02:00
|
|
|
expect(getByText('primary-default')).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
'box--color-primary-default',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
|
|
|
expect(getByText('primary-inverse')).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
'box--color-primary-inverse',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
2023-03-23 21:00:37 +01:00
|
|
|
expect(getByText('error-default')).toHaveClass('box--color-error-default');
|
|
|
|
expect(getByText('error-inverse')).toHaveClass('box--color-error-inverse');
|
2022-08-18 19:51:53 +02:00
|
|
|
expect(getByText('success-default')).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
'box--color-success-default',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
|
|
|
expect(getByText('success-inverse')).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
'box--color-success-inverse',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
|
|
|
expect(getByText('warning-inverse')).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
'box--color-warning-inverse',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
2023-03-23 21:00:37 +01:00
|
|
|
expect(getByText('info-default')).toHaveClass('box--color-info-default');
|
|
|
|
expect(getByText('info-inverse')).toHaveClass('box--color-info-inverse');
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper font style class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-04-17 19:17:28 +02:00
|
|
|
<Text fontStyle={FontStyle.Italic}>italic</Text>
|
|
|
|
<Text fontStyle={FontStyle.Normal}>normal</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('italic')).toHaveClass('mm-text--font-style-italic');
|
|
|
|
expect(getByText('normal')).toHaveClass('mm-text--font-style-normal');
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper text align class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-04-17 19:17:28 +02:00
|
|
|
<Text textAlign={TextAlign.Left}>left</Text>
|
|
|
|
<Text textAlign={TextAlign.Center}>center</Text>
|
|
|
|
<Text textAlign={TextAlign.Right}>right</Text>
|
|
|
|
<Text textAlign={TextAlign.Justify}>justify</Text>
|
|
|
|
<Text textAlign={TextAlign.End}>end</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('left')).toHaveClass('mm-text--text-align-left');
|
|
|
|
expect(getByText('center')).toHaveClass('mm-text--text-align-center');
|
|
|
|
expect(getByText('right')).toHaveClass('mm-text--text-align-right');
|
|
|
|
expect(getByText('justify')).toHaveClass('mm-text--text-align-justify');
|
|
|
|
expect(getByText('end')).toHaveClass('mm-text--text-align-end');
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper overflow wrap class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-04-17 19:17:28 +02:00
|
|
|
<Text overflowWrap={OverflowWrap.BreakWord}>break-word</Text>
|
|
|
|
<Text overflowWrap={OverflowWrap.Normal}>normal</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByText('break-word')).toHaveClass(
|
2022-12-01 18:26:19 +01:00
|
|
|
'mm-text--overflow-wrap-break-word',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('normal')).toHaveClass('mm-text--overflow-wrap-normal');
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper ellipsis class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
|
|
|
<Text ellipsis>ellipsis</Text>
|
|
|
|
</>,
|
|
|
|
);
|
2022-12-01 18:26:19 +01:00
|
|
|
expect(getByText('ellipsis')).toHaveClass('mm-text--ellipsis');
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the Text with proper text transform class name', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-04-17 19:17:28 +02:00
|
|
|
<Text textTransform={TextTransform.Uppercase}>uppercase</Text>
|
|
|
|
<Text textTransform={TextTransform.Lowercase}>lowercase</Text>
|
|
|
|
<Text textTransform={TextTransform.Capitalize}>capitalize</Text>
|
2022-08-18 19:51:53 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByText('uppercase')).toHaveClass(
|
2022-12-01 18:26:19 +01:00
|
|
|
'mm-text--text-transform-uppercase',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
|
|
|
expect(getByText('lowercase')).toHaveClass(
|
2022-12-01 18:26:19 +01:00
|
|
|
'mm-text--text-transform-lowercase',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
|
|
|
expect(getByText('capitalize')).toHaveClass(
|
2022-12-01 18:26:19 +01:00
|
|
|
'mm-text--text-transform-capitalize',
|
2022-08-18 19:51:53 +02:00
|
|
|
);
|
|
|
|
});
|
2022-10-04 19:05:55 +02:00
|
|
|
it('should accept a ref prop that is passed down to the html element', () => {
|
|
|
|
const mockRef = jest.fn();
|
|
|
|
render(<Text ref={mockRef} />);
|
|
|
|
expect(mockRef).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
2022-12-15 19:49:47 +01:00
|
|
|
|
|
|
|
it('should render the Text with proper direction', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<>
|
2023-04-03 19:42:37 +02:00
|
|
|
<Text textDirection={TextDirection.Auto}>auto</Text>
|
|
|
|
<Text textDirection={TextDirection.LeftToRight}>ltr</Text>
|
|
|
|
<Text textDirection={TextDirection.RightToLeft}>rtl</Text>
|
2022-12-15 19:49:47 +01:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByText('auto')).toHaveAttribute('dir', 'auto');
|
|
|
|
expect(getByText('ltr')).toHaveAttribute('dir', 'ltr');
|
|
|
|
expect(getByText('rtl')).toHaveAttribute('dir', 'rtl');
|
|
|
|
});
|
2022-08-18 19:51:53 +02:00
|
|
|
});
|