import React from 'react'; import { render, cleanup } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import { FlexDirectionsEnum, JustifyEnum, AlignEnum } from '../../types'; import { Box } 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('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toBeEmptyDOMElement(); }); test('renders a Box with children', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toContainElement(getByTestId('child-id')); }); }); describe('tests the flexbox properties', () => { test('renders a Box with flex row', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ display: 'flex', 'flex-direction': 'row', }); }); test('renders a Box with flex column and justify', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ display: 'flex', 'flex-direction': 'column', 'justify-content': 'center', }); }); test('renders a Box with flex reverse-column align and justify', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'align-items': 'center', display: 'flex', 'flex-direction': 'column-reverse', 'justify-content': 'center', }); }); }); describe('tests the adjustable height and width', () => { test('renders a Box with height and width', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ height: '5rem', width: '10rem', }); }); }); describe('tests the adjustable max/min height/width', () => { test('renders a Box with max height and max width', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'max-height': '50px', 'max-width': '100px', }); }); test('renders a Box with min height and min width', () => { const { getByTestId } = render(
); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'min-height': '50px', 'min-width': '100px', }); }); }); describe('tests the border props', () => { test('renders a Box with a b string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ border: '1px solid #aaaaaa', }); }); test('renders a Box with bx/by as number', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'border-top-width': '1px', 'border-right-width': '1px', 'border-bottom-width': '1px', 'border-left-width': '1px', 'border-color': '#aaaaaa', 'border-style': 'solid', }); }); test('renders a Box with bx/by as string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'border-top-width': '2px', 'border-right-width': '2px', 'border-bottom-width': '2px', 'border-left-width': '2px', }); }); test('renders a Box with bt/br/bb/bl as string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'border-top-width': '2px', 'border-right-width': '2px', 'border-bottom-width': '2px', 'border-left-width': '2px', }); }); test('renders a Box with bt/br/bb/bl as number', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'border-top-width': '1px', 'border-right-width': '1px', 'border-bottom-width': '1px', 'border-left-width': '1px', }); }); }); describe('tests the radius props', () => { test('renders a Box with a radius string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ borderRadius: '1rem 0.5rem', }); }); test('renders a Box with a radius number', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ borderRadius: '2rem', }); }); }); describe('tests the spacing properties (margin/padding)', () => { test('renders a Box with padding and margin as numbers', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ margin: '0.5rem', padding: '0.5rem', }); }); test('renders a Box with padding and margin as string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ margin: '10px 12px 16px 14px', padding: '10px 12px 16px 14px', }); }); test('renders a Box with px/py and mx/my as number', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'margin-top': '0.75rem', 'margin-right': '0.75rem', 'margin-bottom': '0.75rem', 'margin-left': '0.75rem', 'padding-top': '0.75rem', 'padding-right': '0.75rem', 'padding-bottom': '0.75rem', 'padding-left': '0.75rem', }); }); test('renders a Box with px/py and mx/my as string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'margin-top': '12px', 'margin-right': '12px', 'margin-bottom': '12px', 'margin-left': '12px', 'padding-top': '12px', 'padding-right': '12px', 'padding-bottom': '12px', 'padding-left': '12px', }); }); test('renders a Box with pt/pr/pb/pl and mt/mr/mb/ml as string', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'margin-top': '12px', 'margin-right': '12px', 'margin-bottom': '12px', 'margin-left': '12px', 'padding-top': '12px', 'padding-right': '12px', 'padding-bottom': '12px', 'padding-left': '12px', }); }); test('renders a Box with pt/pr/pb/pl and mt/mr/mb/ml as number', () => { const { getByTestId } = render( ); expect(getByTestId('box-id')).toBeInTheDocument(); expect(getByTestId('box-id')).toHaveStyle({ 'margin-top': '0.75rem', 'margin-right': '0.75rem', 'margin-bottom': '0.75rem', 'margin-left': '0.75rem', 'padding-top': '0.75rem', 'padding-right': '0.75rem', 'padding-bottom': '0.75rem', 'padding-left': '0.75rem', }); }); }); describe('tests the elevation prop', () => { test('renders Boxes with different elevations', () => { const { getByTestId } = render( <> ); expect(getByTestId('elevation-5')).toHaveStyle({ 'box-shadow': '0px 15px 20px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation-4')).toHaveStyle({ 'box-shadow': '0px 10px 15px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation-3')).toHaveStyle({ 'box-shadow': '0px 5px 10px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation-2')).toHaveStyle({ 'box-shadow': '0px 2.5px 5px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation-1')).toHaveStyle({ 'box-shadow': '0px 1.25px 2.5px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation-0')).toHaveStyle({ 'box-shadow': 'none', border: '1px solid #fffffe', }); expect(getByTestId('elevation--1')).toHaveStyle({ 'box-shadow': 'inset 0px 2.5px 5px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation--2')).toHaveStyle({ 'box-shadow': 'inset 0px 5px 10px rgba(0,0,0,0.15)', }); expect(getByTestId('elevation--3')).toHaveStyle({ 'box-shadow': 'inset 0px 10px 15px rgba(0,0,0,0.15)', }); }); });