import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { Button } from './index';
afterEach(cleanup);
test('should take a snapshot', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
describe('tests the Button with/without children', () => {
test('renders a Button with no children', () => {
const { getByTestId } = render();
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toBeEmptyDOMElement();
});
test('renders a Button with children', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id-text')).toHaveTextContent(
"Wowwee It's a button"
);
});
});
describe('tests the Button variants', () => {
test('tests the round variant', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
'border-radius': '1.6rem',
});
});
test('tests the round variant with small', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
'border-radius': '0.6rem',
});
});
test('tests the round variant with large', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
'border-radius': '2.4rem',
});
});
test('tests the round outlined variant with large', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
border: '1px solid #851bb7',
'border-radius': '1.6rem',
color: '#851bb7',
});
});
test('tests the outlined variant', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
border: '1px solid #851bb7',
color: '#851bb7',
});
});
test('tests the outlined variant with bg', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
border: '1px solid #334b41',
color: '#334b41',
});
});
test('tests the unstyled variant', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
all: 'unset',
});
});
});
describe('tests the Button sizes', () => {
test('tests small size', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
height: '2rem',
width: '4rem',
});
expect(getByTestId('button-id-text').tagName).toBe('SMALL');
});
test('tests large size', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
height: '4rem',
width: '8rem',
});
expect(getByTestId('button-id-text').tagName).toBe('P');
});
});
describe('tests the background prop', () => {
test('tests light background', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
background: '#fff',
color: '#00000f',
});
});
test('tests dark background', () => {
const { getByTestId } = render(
);
expect(getByTestId('button-id')).toBeInTheDocument();
expect(getByTestId('button-id')).toHaveStyle({
background: '#000',
color: '#fffffa',
});
});
});