diff --git a/packages/react-core/src/components/DataList/DataList.tsx b/packages/react-core/src/components/DataList/DataList.tsx index 5b2a82a738c..817fb1c6875 100644 --- a/packages/react-core/src/components/DataList/DataList.tsx +++ b/packages/react-core/src/components/DataList/DataList.tsx @@ -73,6 +73,7 @@ class DataList extends React.Component { const { className, children, + 'aria-label': ariaLabel, onSelectDataListItem, selectedDataListItemId, isCompact, @@ -106,6 +107,7 @@ class DataList extends React.Component { )} style={props.style} role="list" + aria-label={ariaLabel} {...props} ref={this.ref} > diff --git a/packages/react-core/src/components/DataList/DataListAction.tsx b/packages/react-core/src/components/DataList/DataListAction.tsx index 807bf915691..ea38de0e3e7 100644 --- a/packages/react-core/src/components/DataList/DataListAction.tsx +++ b/packages/react-core/src/components/DataList/DataListAction.tsx @@ -35,8 +35,8 @@ export const DataListAction: React.FunctionComponent = ({ id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, + /* eslint-disable @typescript-eslint/no-unused-vars */ isPlainButtonAction, - /* eslint-enable @typescript-eslint/no-unused-vars */ ...props }: DataListActionProps) => (
diff --git a/packages/react-core/src/components/DataList/__tests__/DataList.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataList.test.tsx index a7a5bc878c1..f28b8cd6f2c 100644 --- a/packages/react-core/src/components/DataList/__tests__/DataList.test.tsx +++ b/packages/react-core/src/components/DataList/__tests__/DataList.test.tsx @@ -5,346 +5,182 @@ import userEvent from '@testing-library/user-event'; import { DataList } from '../DataList'; import { DataListItem } from '../DataListItem'; -import { DataListAction } from '../DataListAction'; -import { DataListCell } from '../DataListCell'; -import { DataListToggle } from '../DataListToggle'; -import { DataListItemCells } from '../DataListItemCells'; import { DataListItemRow } from '../DataListItemRow'; -import { DataListContent } from '../DataListContent'; -import { Button } from '../../Button'; -import { Dropdown, DropdownList, DropdownItem } from '../../Dropdown'; -import { MenuToggle } from '../../MenuToggle'; -import styles from '@patternfly/react-styles/css/components/DataList/data-list'; -describe('DataList', () => { - test('List default', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; - test('List compact', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); +test('Renders to match snapshot', () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); +}); - describe('DataList variants', () => { - ['none', 'always', 'sm', 'md', 'lg', 'xl', '2xl'].forEach((oneBreakpoint) => { - test(`Breakpoint - ${oneBreakpoint}`, () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); - }); - }); +test(`Renders with default class ${styles.dataList}`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.dataList); +}); - test('List draggable', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); +test(`Renders with custom class when className is passed`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass('custom'); +}); - test('List', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); +test(`Renders with spread props`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveAttribute('id', 'test'); +}); - test('List renders with a hidden input to improve a11y when selectableRow is passed', () => { - render( - {}}> - - -

Test

-
-
-
- ); +test(`Renders with aria-label when aria-label is passed`, () => { + render(test); + expect(screen.getByText('test')).toHaveAccessibleName('list'); +}); - const selectableInput = screen.getByRole('radio', { hidden: true }); +test(`Renders ${styles.modifiers.compact} when isCompact = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.compact); +}); - expect(selectableInput).toBeInTheDocument(); +['nowrap', 'truncate', 'breakWord'].forEach((wrap) => { + test(`Renders with class ${styles.modifiers[wrap]} when wrapModifier = ${wrap} is pased`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers[wrap]); }); +}); - test('List does not render with a hidden input to improve a11y when selectableRow is not passed', () => { - render( - - - -

Test

-
-
-
- ); - - const selectableInput = screen.queryByRole('radio', { hidden: true }); - - expect(selectableInput).not.toBeInTheDocument(); +const gridBreakpointClasses = { + none: styles.modifiers.gridNone, + always: 'pf-m-grid', + sm: styles.modifiers.gridSm, + md: styles.modifiers.gridMd, + lg: styles.modifiers.gridLg, + xl: styles.modifiers.gridXl, + '2xl': styles.modifiers.grid_2xl +}; + +['none', 'always', 'sm', 'md', 'lg', 'xl', '2xl'].forEach((oneBreakpoint) => { + test(`Has breakpoint - ${oneBreakpoint} when gridBreakpoint is pased`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(gridBreakpointClasses[oneBreakpoint]); }); +}); - test('List calls selectableRow.onChange when the selectable input changes', async () => { - const mock = jest.fn(); - const user = userEvent.setup(); - - render( - - - -

Test

-
-
-
- ); - - const selectableInput = screen.getByRole('radio', { hidden: true }); - await user.click(selectableInput); +test(`Renders default class ${styles.dataList}`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.dataList); +}); - expect(mock).toHaveBeenCalled(); - }); +test('Renders custom class when passed', () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass('data-list-custom'); +}); - test('List does not call selectableRow.onChange when the selectable input is not changed', () => { - const mock = jest.fn(); +test('Renders with a hidden input to improve a11y when onSelectableRowChange is passed', () => { + render( + {}}> + + +

Test

+
+
+
+ ); - render( - - - -

Test

-
-
-
- ); + const selectableInput = screen.getByRole('radio', { hidden: true }); - expect(mock).not.toHaveBeenCalled(); - }); - - test('Item applies selectableInputAriaLabel to the hidden input', () => { - render( - {}}> - - -

Test

-
-
-
- ); + expect(selectableInput).toBeInTheDocument(); +}); - const selectableInput = screen.getByRole('radio', { hidden: true }); +test('Does not render with a hidden input to improve a11y when onSelectableRowChange is not passed', () => { + render( + + + +

Test

+
+
+
+ ); - expect(selectableInput).toHaveAccessibleName('Data list item label test'); - }); + const selectableInput = screen.queryByRole('radio', { hidden: true }); - test('Item defaults to labelling its input using its aria-labelledby prop', () => { - render( - {}}> - -

Test cell content

-
-
- ); + expect(selectableInput).not.toBeInTheDocument(); +}); - const selectableInput = screen.getByRole('radio', { hidden: true }); +test('Calls onSelectableRowChange when the selectable input changes', async () => { + const mock = jest.fn(); + const user = userEvent.setup(); - expect(selectableInput).toHaveAccessibleName('Test cell content'); - }); + render( + + + +

Test

+
+
+
+ ); - test('Item prioritizes selectableInputAriaLabel over aria-labelledby prop', () => { - render( - {}}> - -

Test cell content

-
-
- ); + const selectableInput = screen.getByRole('radio', { hidden: true }); + await user.click(selectableInput); - const selectableInput = screen.getByRole('radio', { hidden: true }); + expect(mock).toHaveBeenCalled(); +}); - expect(selectableInput).toHaveAccessibleName('Data list item label test'); - }); +test('Does not call onSelectableRowChange when the selectable input is not changed', () => { + const mock = jest.fn(); - test('Item default', () => { - const { asFragment } = render( - - test + render( + + + +

Test

+
- ); - expect(asFragment()).toMatchSnapshot(); - }); +
+ ); - test('Item expanded', () => { - render( - - test - - ); - expect(screen.getByRole('listitem')).toHaveClass(`${styles.dataListItem} ${styles.modifiers.expanded}`); - }); + expect(mock).not.toHaveBeenCalled(); +}); - test('Item', () => { - const { asFragment } = render( - - test +test('Applies selectableInputAriaLabel to the hidden input', () => { + render( + {}}> + + +

Test

+
- ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('item row default', () => { - const { asFragment } = render(test); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Cell default', () => { - const { asFragment } = render(Secondary); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Cells', () => { - const { asFragment } = render( - - Primary Id - , - - Primary Id 2 - - ]} - /> - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Cell with width modifier', () => { - [ - { width: 1, class: '' }, - { width: 2, class: 'pf-m-flex-2' }, - { width: 3, class: 'pf-m-flex-3' }, - { width: 4, class: 'pf-m-flex-4' }, - { width: 5, class: 'pf-m-flex-5' } - ].forEach((testCase, index) => { - const testId = `cell-test-id-${index}`; - - render( - - Primary Id - - ); - - const dataListCell = screen.getByTestId(testId); - - testCase.class === '' - ? expect(dataListCell).toHaveClass(styles.dataListCell) - : expect(dataListCell).toHaveClass(`${styles.dataListCell} ${testCase.class}`); - }); - }); +
+ ); - test('Cell with text modifiers', () => { - [ - { wrapModifier: null as any, class: '' }, - { wrapModifier: 'breakWord', class: 'pf-m-break-word' }, - { wrapModifier: 'nowrap', class: 'pf-m-nowrap' }, - { wrapModifier: 'truncate', class: 'pf-m-truncate' } - ].forEach((testCase, index) => { - const testId = `cell-test-id-${index}`; - - render( - - Primary Id - - ); - - const dataListCell = screen.getByTestId(testId); - - testCase.class === '' - ? expect(dataListCell).toHaveClass(styles.dataListCell) - : expect(dataListCell).toHaveClass(`${styles.dataListCell} ${testCase.class}`); - }); - }); - - test('Toggle default with aria label', () => { - render(); + const selectableInput = screen.getByRole('radio', { hidden: true }); - expect(screen.getByRole('button')).not.toHaveAttribute('aria-labelledby'); - expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'Toggle details for'); - expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false'); - }); + expect(selectableInput).toHaveAccessibleName('Data list item label test'); +}); - test('Toggle expanded', () => { - render(); - expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true'); - }); +test('Defaults to labelling its input using its aria-labelledby prop', () => { + render( + {}}> + +

Test cell content

+
+
+ ); - test('DataListAction dropdown', () => { - const { asFragment } = render( - - }> - - - action-1 - - , - - action-2 - - - - - ); - expect(asFragment()).toMatchSnapshot(); - }); + const selectableInput = screen.getByRole('radio', { hidden: true }); - test('DataListAction button', () => { - const { asFragment } = render( - - - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('DataListAction visibility - show button when lg', () => { - render( - - - - ); - - expect(screen.getByRole('button').parentElement).toHaveClass('pf-m-hidden'); - expect(screen.getByRole('button').parentElement).toHaveClass('pf-m-visible-on-lg'); - }); + expect(selectableInput).toHaveAccessibleName('Test cell content'); +}); - test('DataListAction visibility - hide button on 2xl', () => { - render( - - - - ); - - expect(screen.getByRole('button').parentElement).toHaveClass('pf-m-hidden-on-2xl'); - }); +test('Prioritizes selectableInputAriaLabel over aria-labelledby prop', () => { + render( + {}}> + +

Test cell content

+
+
+ ); - test('DataListContent', () => { - const { asFragment } = render( test); - expect(asFragment()).toMatchSnapshot(); - }); + const selectableInput = screen.getByRole('radio', { hidden: true }); - test('DataListContent hasNoPadding', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); + expect(selectableInput).toHaveAccessibleName('Data list item label test'); }); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListAction.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListAction.test.tsx new file mode 100644 index 00000000000..38745263caa --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListAction.test.tsx @@ -0,0 +1,75 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListAction } from '../DataListAction'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Renders to match snapshot', () => { + const { asFragment } = render( + + test + + ); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders with default class ${styles.dataListItemAction}`, () => { + render( + + test + + ); + expect(screen.getByText('test')).toHaveClass(styles.dataListItemAction, { exact: true }); +}); + +test(`Renders with custom class when className is passed`, () => { + render( + + test + + ); + expect(screen.getByText('test')).toHaveClass('test-class'); +}); + +test(`Renders with spread props`, () => { + render( + + test + + ); + expect(screen.getByText('test')).toHaveAttribute('dir', 'rtl'); +}); + +test(`Renders with class ${styles.dataListAction} when isPlainButtonAction = true`, () => { + render( + + test + + ); + expect(screen.getByText('test')).toHaveClass(styles.dataListAction); +}); + +['hidden', 'visible'].forEach((vis) => { + const visMod = vis as 'hidden' | 'visible'; + test(`Has visibility - ${vis} for every breakpoint`, () => { + render( + + test + + ); + + if (visMod === 'hidden') { + expect(screen.getByText('test')).toHaveClass(styles.modifiers[`${visMod}`]); + } + expect(screen.getByText('test')).toHaveClass(styles.modifiers[`${visMod}OnSm`]); + expect(screen.getByText('test')).toHaveClass(styles.modifiers[`${visMod}OnMd`]); + expect(screen.getByText('test')).toHaveClass(styles.modifiers[`${visMod}OnLg`]); + expect(screen.getByText('test')).toHaveClass(styles.modifiers[`${visMod}OnXl`]); + expect(screen.getByText('test')).toHaveClass(styles.modifiers[`${visMod}On_2xl`]); + }); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListCell.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListCell.test.tsx new file mode 100644 index 00000000000..6e5954384fa --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListCell.test.tsx @@ -0,0 +1,120 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListCell } from '../DataListCell'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Cell renders to match snapshot', () => { + const { asFragment } = render(Secondary); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders default class ${styles.dataListCell}`, () => { + render( + + Primary Id + + ); + expect(screen.getByTestId('test')).toHaveClass(styles.dataListCell, { exact: true }); +}); + +test(`Renders custom class when className is passed`, () => { + render( + + Primary Id + + ); + expect(screen.getByTestId('test')).toHaveClass('test-class'); +}); + +test(`Renders with spread props`, () => { + render( + + Primary Id + + ); + expect(screen.getByText('Primary Id')).toHaveAttribute('id', 'test'); +}); + +test('Renders width modifier when width is passed', () => { + [ + { width: 1, class: '' }, + { width: 2, class: styles.modifiers.flex_2 }, + { width: 3, class: styles.modifiers.flex_3 }, + { width: 4, class: styles.modifiers.flex_4 }, + { width: 5, class: styles.modifiers.flex_5 } + ].forEach((testCase, index) => { + const testId = `cell-test-id-${index}`; + + render( + + Primary Id + + ); + + const dataListCell = screen.getByTestId(testId); + + testCase.class === '' + ? expect(dataListCell).not.toHaveClass( + styles.modifiers.flex_2, + styles.modifiers.flex_3, + styles.modifiers.flex_4, + styles.modifiers.flex_5 + ) + : expect(dataListCell).toHaveClass(`pf-v5-c-data-list__cell ${testCase.class}`, { exact: true }); + }); +}); + +test('Has text wrap modifiers when wrapModifier is passed', () => { + [ + { wrapModifier: null as any, class: '' }, + { wrapModifier: 'breakWord', class: styles.modifiers.breakWord }, + { wrapModifier: 'nowrap', class: styles.modifiers.nowrap }, + { wrapModifier: 'truncate', class: styles.modifiers.truncate } + ].forEach((testCase, index) => { + const testId = `cell-test-id-${index}`; + + render( + + Primary Id + + ); + + const dataListCell = screen.getByTestId(testId); + + testCase.class === '' + ? expect(dataListCell).not.toHaveClass( + styles.modifiers.breakWord, + styles.modifiers.nowrap, + styles.modifiers.truncate + ) + : expect(dataListCell).toHaveClass(`${testCase.class}`); + }); +}); + +test(`Renders with class ${styles.modifiers.alignRight} when alignRight is passed`, () => { + render( + + Primary Id + + ); + expect(screen.getByTestId('test')).toHaveClass(styles.modifiers.alignRight); +}); + +test(`Renders with class ${styles.modifiers.icon} when isIcon is passed`, () => { + render( + + Primary Id + + ); + expect(screen.getByTestId('test')).toHaveClass(styles.modifiers.icon); +}); + +test(`Renders with class ${styles.modifiers.noFill} when isFilled = false`, () => { + render( + + Primary Id + + ); + expect(screen.getByTestId('test')).toHaveClass(styles.modifiers.noFill); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListCheck.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListCheck.test.tsx index 9e69ff734e8..fa1424c746f 100644 --- a/packages/react-core/src/components/DataList/__tests__/DataListCheck.test.tsx +++ b/packages/react-core/src/components/DataList/__tests__/DataListCheck.test.tsx @@ -3,6 +3,11 @@ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { DataListCheck } from '../DataListCheck'; +test(`Renders with spread props`, () => { + render(); + expect(screen.getByRole('checkbox')).toHaveAttribute('id', 'test'); +}); + it('does not throw a "A component is changing an uncontrolled input of type checkbox to be controlled" error when changed if using isChecked', async () => { const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const user = userEvent.setup(); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListContent.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListContent.test.tsx new file mode 100644 index 00000000000..912bb48f0de --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListContent.test.tsx @@ -0,0 +1,73 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListContent } from '../DataListContent'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Renders to match snapshot', () => { + const { asFragment } = render( test); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders with default class ${styles.dataListExpandableContent}`, () => { + render( + + test + + ); + expect(screen.getByTestId('test-id')).toHaveClass(styles.dataListExpandableContent, { exact: true }); +}); + +test(`Renders with default class ${styles.dataListExpandableContentBody}`, () => { + render( + + test + + ); + expect(screen.getByText('test')).toHaveClass(styles.dataListExpandableContentBody, { exact: true }); +}); + +test(`Renders with custom class when className is passed`, () => { + render( + + test + + ); + expect(screen.getByTestId('test-id')).toHaveClass('test-class'); +}); + +test(`Renders with id when id is passed`, () => { + render( + + test + + ); + expect(screen.getByTestId('test-id')).toHaveAttribute('id', 'idProp'); +}); + +test(`Renders with spread props`, () => { + render( + + test + + ); + expect(screen.getByTestId('test-id')).toHaveAttribute('dir', 'rtl'); +}); + +test(`Renders with class ${styles.modifiers.noPadding} when hasNoPadding is passed`, () => { + render( + + ); + expect(screen.getByText('test')).toHaveClass(styles.modifiers.noPadding); +}); + +test(`Renders with hidden property when isHidden is passed`, () => { + render( + + test + + ); + expect(screen.getByTestId('test-id')).toHaveAttribute('hidden'); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListItem.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListItem.test.tsx new file mode 100644 index 00000000000..54f358c8e83 --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListItem.test.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListItem } from '../DataListItem'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Renders to match snapshot', () => { + const { asFragment } = render( + + test + + ); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders with default class ${styles.dataListItem}`, () => { + render(test); + expect(screen.getByRole('listitem')).toHaveClass(styles.dataListItem, { exact: true }); +}); + +test('Renders with custom class name', () => { + render( + + test + + ); + expect(screen.getByRole('listitem')).toHaveClass('data-list-item-custom'); +}); + +test('Renders with spread props', () => { + render( + + test + + ); + expect(screen.getByRole('listitem')).toHaveAttribute('dir', 'rtl'); +}); + +test(`Renders class ${styles.modifiers.expanded} when isExpanded is passed`, () => { + render( + + test + + ); + expect(screen.getByRole('listitem')).toHaveClass(styles.modifiers.expanded); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListItemCells.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListItemCells.test.tsx new file mode 100644 index 00000000000..e8419f2b361 --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListItemCells.test.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListItemCells } from '../DataListItemCells'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Cells renders to match snapshot', () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders with default class ${styles.dataListItemContent}`, () => { + render(); + expect(screen.getByText('test')).toHaveClass(styles.dataListItemContent, { exact: true }); +}); + +test(`Renders with custom class when className is passed`, () => { + render(); + expect(screen.getByText('test')).toHaveClass('custom'); +}); + +test(`Renders with spread props`, () => { + render(); + expect(screen.getByText('test')).toHaveAttribute('dir', 'rtl'); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListItemRow.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListItemRow.test.tsx new file mode 100644 index 00000000000..74ec2e6fafc --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListItemRow.test.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListItemRow } from '../DataListItemRow'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Item row renders to match snapshot', () => { + const { asFragment } = render(test); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders with default class ${styles.dataListItemRow}`, () => { + render(test); + expect(screen.getByTestId('test')).toHaveClass(styles.dataListItemRow, { exact: true }); +}); + +test(`Renders with custom class when className is passed`, () => { + render( + + test + + ); + expect(screen.getByTestId('test')).toHaveClass('custom'); +}); + +test(`Renders with spread props`, () => { + render( + + test + + ); + expect(screen.getByTestId('test')).toHaveAttribute('dir', 'rtl'); +}); + +['nowrap', 'truncate', 'breakWord'].forEach((wrap) => { + test(`Renders with class ${styles.modifiers[wrap]} when wrapModifier = ${wrap} is pased`, () => { + render( + + test + + ); + expect(screen.getByTestId('test')).toHaveClass(styles.modifiers[wrap]); + }); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/DataListToggle.test.tsx b/packages/react-core/src/components/DataList/__tests__/DataListToggle.test.tsx new file mode 100644 index 00000000000..8f7f8b4cd9b --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/DataListToggle.test.tsx @@ -0,0 +1,61 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { DataListToggle } from '../DataListToggle'; + +import styles from '@patternfly/react-styles/css/components/DataList/data-list'; + +test('Renders to match snapshot', () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); +}); + +test(`Renders with default class ${styles.dataListToggle}`, () => { + render(); + expect(screen.getByRole('button').parentElement).toHaveClass(styles.dataListToggle); +}); + +test(`Renders with default class ${styles.dataListItemControl}`, () => { + render(); + expect(screen.getByRole('button').parentElement?.parentElement).toHaveClass(styles.dataListItemControl, { + exact: true + }); +}); + +test(`Renders with custom class when className is passed`, () => { + render(); + expect(screen.getByRole('button').parentElement?.parentElement).toHaveClass('custom'); +}); + +test(`Renders with spread props`, () => { + render(); + expect(screen.getByRole('button').parentElement?.parentElement).toHaveAttribute('dir', 'rtl'); +}); + +test(`Renders with spread buttonProps`, () => { + render(); + expect(screen.getByRole('button')).toHaveAttribute('disabled'); +}); + +test('Renders aria-labelledby by default when no custom aria-label is passed', () => { + render(); + + expect(screen.getByRole('button')).toHaveAttribute('aria-labelledby', 'row ex-toggle2'); +}); + +test('Does not render aria-labelledby when custom aria-label is passed', () => { + render(); + + expect(screen.getByRole('button')).not.toHaveAttribute('aria-labelledby'); + expect(screen.getByRole('button')).toHaveAccessibleName('Toggle details for'); +}); + +test(`Renders with ariaControls when ariaControls is passed`, () => { + render(); + expect(screen.getByRole('button')).toHaveAttribute('aria-controls', 'control'); +}); + +test('Renders with aria-expanded when isExpanded = true', () => { + render(); + + expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true'); +}); diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataList.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataList.test.tsx.snap index ee9d1720bb9..c8bebb7725c 100644 --- a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataList.test.tsx.snap +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataList.test.tsx.snap @@ -1,332 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`DataList Cell default 1`] = ` - -
- Secondary -
-
-`; - -exports[`DataList Cells 1`] = ` - -
-
- Primary Id -
-
- Primary Id 2 -
-
-
-`; - -exports[`DataList DataList variants Breakpoint - 2xl 1`] = ` - -
    - -`; - -exports[`DataList DataList variants Breakpoint - always 1`] = ` - -
      - -`; - -exports[`DataList DataList variants Breakpoint - lg 1`] = ` - -
        - -`; - -exports[`DataList DataList variants Breakpoint - md 1`] = ` - -
          - -`; - -exports[`DataList DataList variants Breakpoint - none 1`] = ` - -
            - -`; - -exports[`DataList DataList variants Breakpoint - sm 1`] = ` - -
              - -`; - -exports[`DataList DataList variants Breakpoint - xl 1`] = ` - -
                - -`; - -exports[`DataList DataListAction button 1`] = ` - -
                - -
                -
                -`; - -exports[`DataList DataListAction dropdown 1`] = ` - -
                -
                - -
                -
                - -
                -
                -
                -
                -
                -`; - -exports[`DataList DataListContent 1`] = ` - -
                -
                - test -
                -
                -
                -`; - -exports[`DataList DataListContent hasNoPadding 1`] = ` - - - -`; - -exports[`DataList Item 1`] = ` - -
              • - -`; - -exports[`DataList Item default 1`] = ` - -
              • - -`; - -exports[`DataList List 1`] = ` - -
                  - -`; - -exports[`DataList List compact 1`] = ` +exports[`Renders to match snapshot 1`] = `
                    - -`; - -exports[`DataList List default 1`] = ` - -
                      `; - -exports[`DataList List draggable 1`] = ` - -
                        - -`; - -exports[`DataList item row default 1`] = ` - -
                        - -`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListAction.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListAction.test.tsx.snap new file mode 100644 index 00000000000..cf61bf5eabf --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListAction.test.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renders to match snapshot 1`] = ` + +
                        + test +
                        +
                        +`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListCell.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListCell.test.tsx.snap new file mode 100644 index 00000000000..8dfb9393730 --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListCell.test.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Cell renders to match snapshot 1`] = ` + +
                        + Secondary +
                        +
                        +`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListContent.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListContent.test.tsx.snap new file mode 100644 index 00000000000..15736a7aa11 --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListContent.test.tsx.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renders to match snapshot 1`] = ` + +
                        +
                        + test +
                        +
                        +
                        +`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItem.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItem.test.tsx.snap new file mode 100644 index 00000000000..1f0da0b84eb --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItem.test.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renders to match snapshot 1`] = ` + +
                      • + +`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItemCells.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItemCells.test.tsx.snap new file mode 100644 index 00000000000..05d99f283e7 --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItemCells.test.tsx.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Cells renders to match snapshot 1`] = ` + +
                        + +`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItemRow.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItemRow.test.tsx.snap new file mode 100644 index 00000000000..bacaa0a7320 --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListItemRow.test.tsx.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Item row renders to match snapshot 1`] = ` + +
                        + +`; diff --git a/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListToggle.test.tsx.snap b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListToggle.test.tsx.snap new file mode 100644 index 00000000000..cd3276482cf --- /dev/null +++ b/packages/react-core/src/components/DataList/__tests__/__snapshots__/DataListToggle.test.tsx.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renders to match snapshot 1`] = ` + +
                        +
                        + +
                        +
                        +
                        +`; diff --git a/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx b/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx index c4eb52d718c..8f3ca384ddd 100644 --- a/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx +++ b/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx @@ -166,8 +166,8 @@ export const DataListCheckboxes: React.FunctionComponent = () => { @@ -192,7 +192,7 @@ export const DataListCheckboxes: React.FunctionComponent = () => { @@ -231,8 +231,8 @@ export const DataListCheckboxes: React.FunctionComponent = () => { diff --git a/packages/react-core/src/components/DataList/examples/DataListMixedExpandable.tsx b/packages/react-core/src/components/DataList/examples/DataListMixedExpandable.tsx index 87648fdc0ed..7f6a33c6b9b 100644 --- a/packages/react-core/src/components/DataList/examples/DataListMixedExpandable.tsx +++ b/packages/react-core/src/components/DataList/examples/DataListMixedExpandable.tsx @@ -162,7 +162,7 @@ export const DataListMixedExpandable: React.FunctionComponent = () => { ]} />