import * as React from 'react'; import { renderHook } from '@testing-library/react-hooks'; import { Box } from '../../Box'; import { Blockquote } from '../../Blockquote'; import { Popover } from '../index'; import render from '../../utils/_tests/render'; describe('props', () => { it('should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); describe('placement', () => { ['top-start', 'top', 'top-end', 'left', 'center', 'right', 'bottom-start', 'bottom', 'bottom-end'].forEach( (placement: any) => { it(`should render placement correcty for ${placement}`, () => { function Component() { const popover = Popover.useState({ baseId: 'test', placement }); return ( // @ts-ignore Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); } ); }); it('should render correctly with a title', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('should render correctly with a footer', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('should render correctly with action buttons', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); }); describe('composition', () => { describe('use', () => { it('should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); }); describe('hook', () => { it('should return with Modal props', () => { const { result } = renderHook(() => { const popover = Popover.useState({ baseId: 'test' }); return Popover.useProps(popover); }); expect(result.current).toMatchSnapshot(); }); }); describe('render props', () => { it('should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( {(popoverProps) => ( Hello world )} ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); }); }); describe('theming', () => { it('Popover.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { styles: { base: { backgroundColor: 'red' } } } }, }); expect(baseElement).toMatchSnapshot(); }); it('Popover.Arrow.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { Arrow: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); it('Popover.Content.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { Content: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); it('Popover.Close.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { Close: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); it('Popover.Header.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { Header: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); it('Popover.Title.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { Title: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); it('Popover.Footer.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { Footer: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); ['top-start', 'top', 'top-end', 'left', 'center', 'right', 'bottom-start', 'bottom', 'bottom-end'].forEach( (placement: any) => { it(`Popover.placements.${placement} should render correctly`, () => { function Component() { const popover = Popover.useState({ baseId: 'test', placement }); return ( // @ts-ignore Hello world ); } const { baseElement } = render(, { theme: { Popover: { styles: { placements: { [placement]: { backgroundColor: 'red' } } } } }, }); expect(baseElement).toMatchSnapshot(); }); } ); }); describe('overrides', () => { it('Popover.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('Popover.Arrow.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('Popover.Content.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('Popover.Close.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('Popover.Header.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('Popover.Title.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); it('Popover.Footer.base should render correctly', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); ['top-start', 'top', 'top-end', 'left', 'center', 'right', 'bottom-start', 'bottom', 'bottom-end'].forEach( (placement: any) => { it(`Popover.placements.${placement} should render correctly`, () => { function Component() { const popover = Popover.useState({ baseId: 'test', placement }); return ( // @ts-ignore Hello world ); } const { baseElement } = render(); expect(baseElement).toMatchSnapshot(); }); } ); }); describe('defaultProps', () => { it('should render correctly for className', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { defaultProps: { className: 'test' } } } }); expect(baseElement).toMatchSnapshot(); }); it('should render correctly for hasArrow', () => { function Component() { const popover = Popover.useState({ baseId: 'test' }); return ( Hello world ); } const { baseElement } = render(, { theme: { Popover: { defaultProps: { hasArrow: true } } } }); expect(baseElement).toMatchSnapshot(); }); }); describe('useContext', () => { it('should render correctly', () => { let popover; function ParentComponent({ children }: any) { return ( Toggle {children} ); } function ChildComponent() { const context = Popover.useContext(); popover = context.popover; return hello world; } render( ); expect(popover).toMatchSnapshot(); }); });