From 3cb7df4bab4e7194efcec9f8771c01dad9926aa4 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 16 Oct 2023 11:39:42 -0400 Subject: [PATCH] chore(DescriptionList): update tests --- .../__tests__/DescriptionList.test.tsx | 319 +++++++++++------- .../DescriptionList.test.tsx.snap | 139 ++------ 2 files changed, 218 insertions(+), 240 deletions(-) diff --git a/packages/react-core/src/components/DescriptionList/__tests__/DescriptionList.test.tsx b/packages/react-core/src/components/DescriptionList/__tests__/DescriptionList.test.tsx index 22431afd832..4587be102a0 100644 --- a/packages/react-core/src/components/DescriptionList/__tests__/DescriptionList.test.tsx +++ b/packages/react-core/src/components/DescriptionList/__tests__/DescriptionList.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import { DescriptionList } from '../DescriptionList'; import { DescriptionListGroup } from '../DescriptionListGroup'; import { DescriptionListTerm } from '../DescriptionListTerm'; @@ -7,124 +7,201 @@ import { DescriptionListDescription } from '../DescriptionListDescription'; import { DescriptionListTermHelpText } from '../DescriptionListTermHelpText'; import { DescriptionListTermHelpTextButton } from '../DescriptionListTermHelpTextButton'; -describe('Description List', () => { - test('default', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('1 col on all breakpoints', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('2 col on all breakpoints', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('3 col on all breakpoints', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Horizontal Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Compact Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Compact Horizontal Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Fluid Horizontal Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('alignment breakpoints', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Auto Column Widths Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Inline Grid Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Auto fit Description List', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Auto fit with responsive grid Description List', () => { - const { asFragment } = render( - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Term default', () => { - const { asFragment } = render( - - test - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Term helper text', () => { - const { asFragment } = render( - - test - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Group', () => { - const { asFragment } = render( - - test - - ); - expect(asFragment()).toMatchSnapshot(); - }); - - test('Description', () => { - const { asFragment } = render( - - test - - ); - expect(asFragment()).toMatchSnapshot(); - }); +import styles from '@patternfly/react-styles/css/components/DescriptionList/description-list'; + +test('renders to match snapshot', () => { + const { asFragment } = render(); + expect(screen.getByLabelText('list')).toBeInTheDocument(); + expect(asFragment()).toMatchSnapshot(); +}); + +test('renders custom className', () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass('custom'); +}); + +test('renders 1Col on all breakpoints', () => { + render( + + ); + expect(screen.getByLabelText('list')).toHaveClass( + styles.modifiers['1Col'], + styles.modifiers['1ColOnSm'], + styles.modifiers['1ColOnMd'], + styles.modifiers['1ColOnLg'], + styles.modifiers['1ColOnXl'], + styles.modifiers['1ColOn_2xl'] + ); +}); + +test('renders 2Col on all breakpoints', () => { + render( + + ); + expect(screen.getByLabelText('list')).toHaveClass( + styles.modifiers['2Col'], + styles.modifiers['2ColOnSm'], + styles.modifiers['2ColOnMd'], + styles.modifiers['2ColOnLg'], + styles.modifiers['2ColOnXl'], + styles.modifiers['2ColOn_2xl'] + ); +}); + +test('renders 3Col on all breakpoints', () => { + render( + + ); + expect(screen.getByLabelText('list')).toHaveClass( + styles.modifiers['3Col'], + styles.modifiers['3ColOnSm'], + styles.modifiers['3ColOnMd'], + styles.modifiers['3ColOnLg'], + styles.modifiers['3ColOnXl'], + styles.modifiers['3ColOn_2xl'] + ); +}); + +test(`renders ${styles.modifiers.horizontal} when isHorizontal = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.horizontal); +}); + +test(`renders ${styles.modifiers.compact} when isCompact = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.compact); +}); + +test(`renders ${styles.modifiers.horizontal} and ${styles.modifiers.fluid} when isFluid = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.fluid, styles.modifiers.horizontal); +}); + +test('renders alignment breakpoints', () => { + render( + + ); + expect(screen.getByLabelText('list')).toHaveClass( + styles.modifiers.horizontal, + styles.modifiers.horizontalOnSm, + styles.modifiers.verticalOnMd, + styles.modifiers.horizontalOnLg, + styles.modifiers.verticalOnXl, + styles.modifiers.horizontalOn_2xl + ); +}); + +test(`renders ${styles.modifiers.autoColumnWidths} when isAutoColumnWidths = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.autoColumnWidths); +}); + +test(`renders ${styles.modifiers.inlineGrid} when isInlineGrid = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.inlineGrid); +}); + +test(`renders ${styles.modifiers.autoFit} when isAutoFit = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.autoFit); +}); + +test(`renders ${styles.modifiers.fillColumns} when isFillColumns = true`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.fillColumns); +}); + +test(`renders ${styles.modifiers.displayLg} when displaySize = lg`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.displayLg); +}); + +test(`renders ${styles.modifiers.display_2xl} when displaySize = 2xl`, () => { + render(); + expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.display_2xl); +}); + +test('DescriptionListTerm renders to match snapshot', () => { + const { asFragment } = render( + + test + + ); + expect(asFragment()).toMatchSnapshot(); +}); + +test('DescriptionListTerm renders custom className', () => { + render(test); + expect(screen.getByText('test').parentElement).toHaveClass('custom'); +}); + +test('DescriptionListTerm renders icon', () => { + render(icon}>test); + expect(screen.getByText('icon').parentElement).toHaveClass(styles.descriptionListTermIcon); +}); + +test('DescriptioinListTermHelpText renders to match snapshot', () => { + const { asFragment } = render( + + test + + ); + expect(asFragment()).toMatchSnapshot(); +}); + +test('DescriptioinListTermHelpText renders custom className', () => { + render( + + test + + ); + expect(screen.getByLabelText('help-text')).toHaveClass('custom'); +}); + +test('DescriptioinListTermHelpTextButton renders custom className', () => { + render( + + test + + ); + expect(screen.getByText('test')).toHaveClass('custom'); +}); + +test('DescriptionListGroup renders to match snapshot', () => { + const { asFragment } = render(test); + expect(asFragment()).toMatchSnapshot(); +}); + +test('DescriptionListGroup renders custom className', () => { + render(test); + expect(screen.getByText('test')).toHaveClass('custom'); +}); + +test('DescriptionListDescription renders to match snapshot', () => { + const { asFragment } = render(test); + expect(asFragment()).toMatchSnapshot(); +}); + +test('DescriptionListDescription renders custom className', () => { + render(test); + expect(screen.getByText('test').parentElement).toHaveClass('custom'); }); diff --git a/packages/react-core/src/components/DescriptionList/__tests__/__snapshots__/DescriptionList.test.tsx.snap b/packages/react-core/src/components/DescriptionList/__tests__/__snapshots__/DescriptionList.test.tsx.snap index b9bde9f6974..b9943761789 100644 --- a/packages/react-core/src/components/DescriptionList/__tests__/__snapshots__/DescriptionList.test.tsx.snap +++ b/packages/react-core/src/components/DescriptionList/__tests__/__snapshots__/DescriptionList.test.tsx.snap @@ -1,75 +1,26 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Description List 1 col on all breakpoints 1`] = ` +exports[`DescriptioinListTermHelpText renders to match snapshot 1`] = ` -
- -`; - -exports[`Description List 2 col on all breakpoints 1`] = ` - -
- -`; - -exports[`Description List 3 col on all breakpoints 1`] = ` - -
- -`; - -exports[`Description List Auto Column Widths Description List 1`] = ` - -
- -`; - -exports[`Description List Auto fit Description List 1`] = ` - -
- -`; - -exports[`Description List Auto fit with responsive grid Description List 1`] = ` - -
- -`; - -exports[`Description List Compact Description List 1`] = ` - -
- -`; - -exports[`Description List Compact Horizontal Description List 1`] = ` - -
+
+ + test + +
`; -exports[`Description List Description 1`] = ` +exports[`DescriptionListDescription renders to match snapshot 1`] = `
`; -exports[`Description List Fluid Horizontal Description List 1`] = ` - -
- -`; - -exports[`Description List Group 1`] = ` +exports[`DescriptionListGroup renders to match snapshot 1`] = `
test
`; -exports[`Description List Horizontal Description List 1`] = ` - -
- -`; - -exports[`Description List Inline Grid Description List 1`] = ` - -
- -`; - -exports[`Description List Term default 1`] = ` +exports[`DescriptionListTerm renders to match snapshot 1`] = `
`; -exports[`Description List Term helper text 1`] = ` - -
- - test - -
-
-`; - -exports[`Description List alignment breakpoints 1`] = ` - -
- -`; - -exports[`Description List default 1`] = ` +exports[`renders to match snapshot 1`] = `