import * as React from 'react';
import { render } from '@testing-library/react';
import {
FONT_STYLE,
FONT_WEIGHT,
OVERFLOW_WRAP,
TEXT_ALIGN,
TextColor,
TEXT_TRANSFORM,
TextVariant,
Color,
} from '../../../helpers/constants/design-system';
import { Text, TEXT_DIRECTIONS } from '.';
describe('Text', () => {
it('should render the Text without crashing', () => {
const { getByText } = render(Test type);
expect(getByText('Test type')).toBeDefined();
});
it('should render the Text with correct html elements', () => {
const { getByText, container } = render(
<>
p
h1
h2
h3
h4
h5
h6
span
strong
em
li
div
dt
dd
>,
);
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', () => {
const { getByText, container } = render(
<>
display-md
heading-lg
heading-md
heading-sm
body-lg-medium
body-md
body-md-bold
body-sm
body-sm-bold
body-xs
>,
);
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();
});
it('should render the Text with proper font weight class name', () => {
const { getByText } = render(
<>
bold
medium
normal
>,
);
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');
});
it('should render the Text with proper text color class name', () => {
const { getByText } = render(
<>
text-default
text-alternative
text-muted
overlay-inverse
primary-default
primary-inverse
error-default
error-inverse
success-default
success-inverse
warning-inverse
info-default
info-inverse
>,
);
expect(getByText('text-default')).toHaveClass(
'mm-text--color-text-default',
);
expect(getByText('text-alternative')).toHaveClass(
'mm-text--color-text-alternative',
);
expect(getByText('text-muted')).toHaveClass('mm-text--color-text-muted');
expect(getByText('primary-default')).toHaveClass(
'mm-text--color-primary-default',
);
expect(getByText('primary-inverse')).toHaveClass(
'mm-text--color-primary-inverse',
);
expect(getByText('error-default')).toHaveClass(
'mm-text--color-error-default',
);
expect(getByText('error-inverse')).toHaveClass(
'mm-text--color-error-inverse',
);
expect(getByText('success-default')).toHaveClass(
'mm-text--color-success-default',
);
expect(getByText('success-inverse')).toHaveClass(
'mm-text--color-success-inverse',
);
expect(getByText('warning-inverse')).toHaveClass(
'mm-text--color-warning-inverse',
);
expect(getByText('info-default')).toHaveClass(
'mm-text--color-info-default',
);
expect(getByText('info-inverse')).toHaveClass(
'mm-text--color-info-inverse',
);
});
it('should render the Text with proper font style class name', () => {
const { getByText } = render(
<>
italic
normal
>,
);
expect(getByText('italic')).toHaveClass('mm-text--font-style-italic');
expect(getByText('normal')).toHaveClass('mm-text--font-style-normal');
});
it('should render the Text with proper text align class name', () => {
const { getByText } = render(
<>
left
center
right
justify
end
>,
);
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');
});
it('should render the Text with proper overflow wrap class name', () => {
const { getByText } = render(
<>
break-word
normal
>,
);
expect(getByText('break-word')).toHaveClass(
'mm-text--overflow-wrap-break-word',
);
expect(getByText('normal')).toHaveClass('mm-text--overflow-wrap-normal');
});
it('should render the Text with proper ellipsis class name', () => {
const { getByText } = render(
<>
ellipsis
>,
);
expect(getByText('ellipsis')).toHaveClass('mm-text--ellipsis');
});
it('should render the Text with proper text transform class name', () => {
const { getByText } = render(
<>
uppercase
lowercase
capitalize
>,
);
expect(getByText('uppercase')).toHaveClass(
'mm-text--text-transform-uppercase',
);
expect(getByText('lowercase')).toHaveClass(
'mm-text--text-transform-lowercase',
);
expect(getByText('capitalize')).toHaveClass(
'mm-text--text-transform-capitalize',
);
});
it('should accept a ref prop that is passed down to the html element', () => {
const mockRef = jest.fn();
render();
expect(mockRef).toHaveBeenCalledTimes(1);
});
it('should render the Text with proper direction', () => {
const { getByText } = render(
<>
auto
ltr
rtl
>,
);
expect(getByText('auto')).toHaveAttribute('dir', 'auto');
expect(getByText('ltr')).toHaveAttribute('dir', 'ltr');
expect(getByText('rtl')).toHaveAttribute('dir', 'rtl');
});
});