import * as React from 'react'; import { applyTheme } from 'bumbag/utils/applyTheme'; import { Box } from '../index'; import { Text } from '../../Text'; 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 CSS props', () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); it('should render correctly with height/width CSS props', () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); it('should render correctly with height/width CSS props', () => { 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 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 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('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 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(); }); ['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('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: (props) => ({ backgroundColor: props.color }) } }, }, } ); expect(container.firstChild).toMatchSnapshot(); }); }); describe('overrides', () => { it('Box.base should render correctly', () => { const { container } = render( hello world ); expect(container.firstChild).toMatchSnapshot(); }); }); describe('applyTheme', () => { it('renders correctly', () => { const Card = applyTheme(Box, { styles: { base: { backgroundColor: 'red', }, }, defaultProps: { altitude: '100', padding: 'major-2', }, }); const { container } = render(); 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(); }); it('renders correctly for overrides', () => { const { container } = render( hello world ); 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 overrides', () => { const { container } = render( hello world ); expect(container.firstChild).toMatchSnapshot(); }); it('renders correctly for applyTheme', () => { const Card = applyTheme(Box, { defaultProps: { altitude: '100', padding: 'major-2', }, modes: { test: { styles: { base: { backgroundColor: 'red' } }, defaultProps: { color: 'primaryTint' }, }, }, }); const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); });