import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { Box } from '../index';
import { Button } from '../../Button';
import { applyTheme } from '../../utils/applyTheme';
import render from '../../utils/_tests/render';
describe('props', () => {
it('should render correctly', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should assign a ref', () => {
const ref = React.createRef();
render(Hello world);
expect(ref.current).toMatchSnapshot();
});
it('should render correctly with aria* props', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with breakpoints', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with breakpoints', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with breakpoints', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with hover', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with hoveractive', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with focus', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with visited', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with active', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with disabled', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with group hover', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with group active', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with group focus', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with group visited', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with group disabled', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with CSS props with group hover', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a color CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a spacing CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with negative spacing CSS props', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a font CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a fontFamily CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a spacing CSS prop (marginX, paddingX)', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a spacing CSS prop (marginY, paddingY)', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a font size CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a font weight CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it.only('should render correctly with a zIndex CSS prop', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly for an altitude', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly for a custom border', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
['default', '0', '1', '2', '3', '4', '5', '6'].forEach((borderRadius) => {
it(`should render correctly for a borderRadius of ${borderRadius}`, () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
it('should render correctly with overrides', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
['left', 'right', 'center'].forEach((alignX) => {
it(`should render correctly for an alignX of ${alignX}`, () => {
// @ts-ignore
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
['top', 'bottom', 'center'].forEach((alignY) => {
it(`should render correctly for an alignY of ${alignY}`, () => {
// @ts-ignore
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
describe('gradients', () => {
it('should render correctly for a basic gradient', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
['top', 'bottom', 'left', 'right', 'top right', 'top left', 'bottom right', 'bottom left'].forEach(
(direction: any) => {
it(`should render correctly for a gradient with direction of ${direction}`, () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
}
);
it('should render correctly for a gradient with gradientVia', () => {
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly for a gradient with stops', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly for responsive gradients', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
['_hover', '_hoveractive', '_focus'].forEach((pseudoProp) => {
it(`should render correctly for ${pseudoProp}`, () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
});
});
});
describe('composition', () => {
describe('use', () => {
it('should render correctly', () => {
const { container } = render(Hello world);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly for a Button component with props', () => {
const { container } = render(
// @ts-ignore
Hello world
);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('hook', () => {
it('should return with box props', () => {
const { result } = renderHook(() => Box.useProps());
expect(result.current).toMatchSnapshot();
});
});
describe('render props', () => {
it('should render correctly', () => {
const { container } = render({(boxProps) => Hello world
});
expect(container.firstChild).toMatchSnapshot();
});
});
});
describe('theming', () => {
it('Box.base should render correctly', () => {
const { container } = render(hello world, {
theme: { Box: { styles: { base: { backgroundColor: 'red' } } } },
});
expect(container.firstChild).toMatchSnapshot();
});
it('Box.base should render correctly', () => {
const { container } = render(hello world, {
theme: { Box: { styles: { base: { backgroundColor: 'rgb(255, 0, 0)', color: 'rgba(0, 255, 0, 0.1)' } } } },
});
expect(container.firstChild).toMatchSnapshot();
});
it('Box.base should render correctly', () => {
const { container } = render(hello world, {
theme: {
Box: { styles: { base: (props) => ({ backgroundColor: props.color }) } },
},
});
expect(container.firstChild).toMatchSnapshot();
});
});
describe('variants', () => {
it('styles.base should render correctly', () => {
const { container } = render(hello world, {
theme: {
Box: {
variants: { test: { styles: { base: { backgroundColor: 'red' } } } },
},
},
});
expect(container.firstChild).toMatchSnapshot();
});
});
describe('modes', () => {
it('should render correctly when colorMode is set globally', () => {
const { container } = render(hello world, {
colorMode: 'test',
theme: {
Box: {
modes: {
test: {
styles: { base: { backgroundColor: 'red' } },
defaultProps: { color: 'primaryTint' },
},
},
},
},
});
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly when colorMode set as prop', () => {
const { container } = render(hello world, {
theme: {
Box: {
modes: {
test: {
styles: { base: { backgroundColor: 'red' } },
defaultProps: { color: 'primaryTint' },
},
},
},
},
});
expect(container.firstChild).toMatchSnapshot();
});
it('renders correctly for applyTheme', () => {
const Card = applyTheme(Box, {
defaultProps: {
altitude: '100',
padding: 'major-2',
},
variants: {
test: {
defaultProps: {
color: 'red',
},
},
},
});
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
});
describe('modes', () => {
it('should render correctly when colorMode is set globally', () => {
const { container } = render(hello world, {
colorMode: 'test',
theme: {
Box: {
modes: {
test: {
styles: { base: { backgroundColor: 'red' } },
defaultProps: { color: 'primaryTint' },
},
},
},
},
});
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly when colorMode set as prop', () => {
const { container } = render(hello world, {
theme: {
Box: {
modes: {
test: {
styles: { base: { backgroundColor: 'red' } },
defaultProps: { color: 'primaryTint' },
},
},
},
},
});
expect(container.firstChild).toMatchSnapshot();
});
it('renders correctly for applyTheme', () => {
const Card = applyTheme(Box, {
defaultProps: {
altitude: '100',
padding: 'major-2',
},
modes: {
test: {
defaultProps: {
color: 'red',
},
},
},
});
const { container } = render();
expect(container.firstChild).toMatchSnapshot();
});
it('correctly assigns a ref for applyTheme', () => {
const CustomBox = applyTheme(Box, {
defaultProps: {
altitude: '100',
padding: 'major-2',
},
});
const ref = React.createRef();
const { container } = render();
expect(ref.current).toMatchSnapshot();
});
});
describe('defaultProps', () => {
it('should render correctly', () => {
const { container } = render(hello world, {
theme: { Box: { defaultProps: { className: 'test' } } },
});
expect(container.firstChild).toMatchSnapshot();
});
});