import React from 'react'; import 'jest-styled-components'; import 'jest-axe/extend-expect'; import 'regenerator-runtime/runtime'; import { axe } from 'jest-axe'; import { render } from '@testing-library/react'; import { ThemeType } from '../../../themes'; import { Grommet } from '../../Grommet'; import { NameValueList } from '..'; import { NameValuePair } from '../../NameValuePair'; const data = { name: 'entry', location: 'San Francisco', health: 80, }; describe('NameValueList', () => { test('should have no accessibility violations', async () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); const results = await axe(container); expect(results).toHaveNoViolations(); }); test(`should render`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render correct width of name`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render correct width of value`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render correct width of value when value is array`, () => { const { asFragment } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(asFragment()).toMatchSnapshot(); }); test(`should render correct alignment of name`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render correct alignment of value`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render pairs in a grid when layout="grid"`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should accept and apply Grid props`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render name/value as a column when pairProps = { direction: 'column' }`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render value above name when pairProps = { direction: 'column-reverse' }`, () => { const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should render correct gap between rows and columns`, () => { const customGapTheme: ThemeType = { nameValueList: { gap: { column: 'small', row: 'large' }, }, }; const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); test(`should support custom theme`, () => { const customTheme: ThemeType = { nameValueList: { gap: { column: 'small', row: 'large' }, pair: { column: { gap: { column: 'medium', row: 'small', }, }, }, name: { width: 'xsmall', }, value: { width: 'small', }, }, nameValuePair: { name: { color: 'brand', weight: 'bold', }, value: { weight: 'lighter', }, }, }; const { container } = render( {Object.entries(data).map(([name, value]) => ( {value} ))} , ); expect(container.firstChild).toMatchSnapshot(); }); });