import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { Text } from './index';
afterEach(cleanup);
test('should take a snapshot', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
describe('tests the box with and without children', () => {
test('renders a Box with no children', () => {
const { getByTestId } = render();
expect(getByTestId('text-id')).toBeInTheDocument();
expect(getByTestId('text-id')).toBeEmptyDOMElement();
});
test('renders a Box with children', () => {
const { getByTestId } = render(
);
expect(getByTestId('text-id')).toBeInTheDocument();
expect(getByTestId('text-id')).toContainElement(getByTestId('child-id'));
});
});
describe('tests the different elements for Text', () => {
test('renders all of the elements', () => {
const { getByTestId } = render(
<>
Undefined Test
Small Test
Span Test
P Test
H6 Test
H5 Test
H4 Test
H3 Test
H2 Test
H1 Test
>
);
expect(getByTestId('undefined-id')).toBeInTheDocument();
expect(getByTestId('undefined-id')).toHaveTextContent('Undefined Test');
expect(getByTestId('undefined-id').tagName).toBe('SPAN');
expect(getByTestId('undefined-id')).toHaveStyle({
'font-size': '0.8rem',
});
expect(getByTestId('small-id')).toBeInTheDocument();
expect(getByTestId('small-id')).toHaveTextContent('Small Test');
expect(getByTestId('small-id').tagName).toBe('SMALL');
expect(getByTestId('small-id')).toHaveStyle({
'font-size': '0.64rem',
});
expect(getByTestId('span-id')).toBeInTheDocument();
expect(getByTestId('span-id')).toHaveTextContent('Span Test');
expect(getByTestId('span-id').tagName).toBe('SPAN');
expect(getByTestId('span-id')).toHaveStyle({
'font-size': '0.8rem',
});
expect(getByTestId('p-id')).toBeInTheDocument();
expect(getByTestId('p-id')).toHaveTextContent('P Test');
expect(getByTestId('p-id').tagName).toBe('P');
expect(getByTestId('p-id')).toHaveStyle({
'font-size': '1rem',
});
expect(getByTestId('h6-id')).toBeInTheDocument();
expect(getByTestId('h6-id')).toHaveTextContent('H6 Test');
expect(getByTestId('h6-id').tagName).toBe('H6');
expect(getByTestId('h6-id')).toHaveStyle({
'font-size': '1rem',
});
expect(getByTestId('h5-id')).toBeInTheDocument();
expect(getByTestId('h5-id')).toHaveTextContent('H5 Test');
expect(getByTestId('h5-id').tagName).toBe('H5');
expect(getByTestId('h5-id')).toHaveStyle({
'font-size': '1.25rem',
});
expect(getByTestId('h4-id')).toBeInTheDocument();
expect(getByTestId('h4-id')).toHaveTextContent('H4 Test');
expect(getByTestId('h4-id').tagName).toBe('H4');
expect(getByTestId('h4-id')).toHaveStyle({
'font-size': '1.6rem',
});
expect(getByTestId('h3-id')).toBeInTheDocument();
expect(getByTestId('h3-id')).toHaveTextContent('H3 Test');
expect(getByTestId('h3-id').tagName).toBe('H3');
expect(getByTestId('h3-id')).toHaveStyle({
'font-size': '2rem',
});
expect(getByTestId('h2-id')).toBeInTheDocument();
expect(getByTestId('h2-id')).toHaveTextContent('H2 Test');
expect(getByTestId('h2-id').tagName).toBe('H2');
expect(getByTestId('h2-id')).toHaveStyle({
'font-size': '2.4rem',
});
expect(getByTestId('h1-id')).toBeInTheDocument();
expect(getByTestId('h1-id')).toHaveTextContent('H1 Test');
expect(getByTestId('h1-id').tagName).toBe('H1');
expect(getByTestId('h1-id')).toHaveStyle({
'font-size': '3rem',
});
});
});
describe('tests the weight prop for Text', () => {
test('renders all of the elements with varying weights', () => {
const { getByTestId } = render(
<>
Undefined Test
Small Test
Span Test
P Test
H6 Test
H5 Test
H4 Test
H3 Test
H2 Test
H1 Test
>
);
expect(getByTestId('undefined-id')).toHaveStyle({
'font-weight': 900,
});
expect(getByTestId('small-id')).toHaveStyle({
'font-weight': 800,
});
expect(getByTestId('span-id')).toHaveStyle({
'font-weight': 700,
});
expect(getByTestId('p-id')).toHaveStyle({
'font-weight': 600,
});
expect(getByTestId('h6-id')).toHaveStyle({
'font-weight': 500,
});
expect(getByTestId('h5-id')).toHaveStyle({
'font-weight': 400,
});
expect(getByTestId('h4-id')).toHaveStyle({
'font-weight': 300,
});
expect(getByTestId('h3-id')).toHaveStyle({
'font-weight': 200,
});
expect(getByTestId('h2-id')).toHaveStyle({
'font-weight': 100,
});
expect(getByTestId('h1-id')).toHaveStyle({
'font-weight': 'bold',
});
});
});
describe('tests the underlined prop for Text', () => {
test('renders all of the elements with an underline', () => {
const { getByTestId } = render(
<>
Undefined Test
Small Test
Span Test
P Test
H6 Test
H5 Test
H4 Test
H3 Test
H2 Test
H1 Test
>
);
expect(getByTestId('undefined-id')).toHaveStyle({
'text-decoration': 'underline',
'text-decoration-color': '#cccccc',
});
expect(getByTestId('small-id')).toHaveStyle({
'text-decoration': 'underline',
'text-decoration-color': '#cccccc',
});
expect(getByTestId('span-id')).toHaveStyle({
'text-decoration': 'underline',
'text-decoration-color': '#cccccc',
});
expect(getByTestId('p-id')).toHaveStyle({
'text-decoration': 'underline',
'text-decoration-color': '#cccccc',
});
expect(getByTestId('h6-id')).toHaveStyle({
'border-bottom': '1px solid #cccccc',
});
expect(getByTestId('h5-id')).toHaveStyle({
'border-bottom': '1px solid #cccccc',
});
expect(getByTestId('h4-id')).toHaveStyle({
'border-bottom': '2px solid #cccccc',
});
expect(getByTestId('h3-id')).toHaveStyle({
'border-bottom': '2px solid #cccccc',
});
expect(getByTestId('h2-id')).toHaveStyle({
'border-bottom': '3px solid #cccccc',
});
expect(getByTestId('h1-id')).toHaveStyle({
'border-bottom': '3px solid #cccccc',
});
});
});
describe('tests the italic prop', () => {
test('', () => {
const { getByTestId } = render(
Testerino
);
expect(getByTestId('text-id')).toBeInTheDocument();
expect(getByTestId('text-id')).toHaveStyle({
'font-style': 'italic',
});
});
});
describe('tests the block prop', () => {
test('', () => {
const { getByTestId } = render(
Testerino
);
expect(getByTestId('text-id')).toBeInTheDocument();
expect(getByTestId('text-id')).toHaveStyle({
display: 'block',
'margin-bottom': '0.5rem',
'margin-top': '0.5rem',
});
});
});