import React from 'react'; import styled from '@emotion/styled'; import { render } from '@testing-library/react'; import { axe } from 'jest-axe'; import { renderHook } from '@leafygreen-ui/testing-lib'; import { RowContextProvider } from '../Row/RowContext'; import useLeafyGreenTable, { LeafyGreenTableCell } from '../useLeafyGreenTable'; import { Person } from '../utils/makeData.testutils'; import { getDefaultTestColumns, getDefaultTestData, } from '../utils/testHookCalls.testutils'; import { Cell, CellProps } from '.'; const onScroll = jest.fn(); const defaultProps: CellProps = { onScroll, }; /** Returns the first Cell from the first Row */ const useMockTestCellData = (): LeafyGreenTableCell => { const table = useLeafyGreenTable({ data: getDefaultTestData({}), columns: getDefaultTestColumns({}), }); return table.getRowModel().rows[0].getVisibleCells()[0]; }; function renderCell(props: CellProps) { return render(
, ); } describe('packages/table/Cell', () => { describe('a11y', () => { test('does not have basic accessibility issues', async () => { const { container } = renderCell(defaultProps); const results = await axe(container); expect(results).toHaveNoViolations(); }); }); describe('styled', () => { test('works with `styled`', () => { const StyledCell = styled(Cell)` color: #69ffc6; `; const { getByTestId } = render( Some text, ); expect(getByTestId('styled')).toHaveStyle(`color: #69ffc6;`); }); test('works with `styled` props', () => { // We need to define the additional props that styled should expect interface StyledProps { color?: string; } const StyledCell = styled(Cell)` color: ${props => props.color}; `; const { getByTestId } = render( Some text , ); expect(getByTestId('styled')).toHaveStyle(`color: #69ffc6;`); }); }); describe('accepts a ref', () => { test('regular cell', () => { const ref = React.createRef(); render(Hello); expect(ref.current).toBeInTheDocument(); expect(ref.current!.textContent).toBe('Hello'); }); test('RT cell', () => { const ref = React.createRef(); const { result } = renderHook(() => useMockTestCellData()); const mockCell = result.current; const providerValue = { getIsExpanded: () => false, getCanExpand: () => false, toggleExpanded: () => {}, depth: 1, disabled: false, }; render( Hello RT , ); expect(ref.current).toBeInTheDocument(); expect(ref.current!.textContent).toBe('Hello RT'); }); }); // eslint-disable-next-line jest/no-disabled-tests describe.skip('types behave as expected', () => { const { result } = renderHook(() => useMockTestCellData()); const mockCell = result.current; const ref = React.createRef(); <> ; }); });