import React from 'react'; import { render } from '@testing-library/react'; import { axe } from 'jest-axe'; import 'jest-axe/extend-expect'; import 'regenerator-runtime/runtime'; import 'jest-styled-components'; import { Grommet } from '../../Grommet'; import { Box } from '../../Box'; import { Chart, calcs, ChartProps } from '..'; type ChartValues = ChartProps['values']; const VALUES: ChartValues = [ { value: [1, 60], label: 'sixty' }, { value: [0, 0], label: 'zero' }, ]; const UNDEFINED_VALUES: ChartValues = [ { value: [2, 60], label: 'sixty' }, { value: [1] }, { value: [0, 0], label: 'zero' }, ]; const STYLED_VALUES: ChartValues = [ { value: [1, 60], label: 'sixty', color: 'status-ok', opacity: 'strong', thickness: 'small', }, { value: [0, 0], label: 'zero', color: '#123456', opacity: 0.27, thickness: 27, }, ]; describe('Chart', () => { test('should not have accessibility violations', async () => { const { container } = render( , ); const results = await axe(container); expect(container.firstChild).toMatchSnapshot(); expect(results).toHaveNoViolations(); }); test('default', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('opacity', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('type', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('size', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('thickness', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('cap', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('gap', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('dash', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('color', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('point', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('pattern', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('value style', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('pad', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('horizontal', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('animate', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('undefined values', () => { const { container } = render( , ); expect(container.firstChild).toMatchSnapshot(); }); test('calcs basic', () => { const result = calcs([ [1, 2, 2], [2, 2, 2], ]); expect(result).toMatchSnapshot(); }); test('calcs with single value', () => { const result = calcs([1]); expect(result).toMatchSnapshot(); }); test('calcs with negative min', () => { const result = calcs([ [1, -2, -2], [2, 2, 2], ]); expect(result).toMatchSnapshot(); }); test('calcs large thickness', () => { const vals = Array(8).fill([1, 2, 3]); const result = calcs(vals); expect(result).toMatchSnapshot(); }); test('calcs medium thickness', () => { const vals = Array(14).fill([1, 2, 3]); const result = calcs(vals); expect(result).toMatchSnapshot(); }); test('calcs small thickness', () => { const vals = Array(24).fill([1, 2, 3]); const result = calcs(vals); expect(result).toMatchSnapshot(); }); test('calcs xsmall thickness', () => { const vals = Array(64).fill([1, 2, 3]); const result = calcs(vals); expect(result).toMatchSnapshot(); }); test('calcs hair thickness', () => { const vals = Array(124).fill([1, 2, 3]); const result = calcs(vals); expect(result).toMatchSnapshot(); }); test('renders a11yTitle and aria-label', () => { const LABEL = 'Test Label'; const { container, getByLabelText } = render( , ); expect(getByLabelText(LABEL)).toBeTruthy(); expect(getByLabelText(`${LABEL}-2`)).toBeTruthy(); expect(container.firstChild).toMatchSnapshot(); }); });