-
Notifications
You must be signed in to change notification settings - Fork 383
chore(ActionList): update tests to new standards #7669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolethoen
merged 1 commit into
patternfly:main
from
wise-king-sullyman:action-list-test-revamp
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 46 additions & 11 deletions
57
packages/react-core/src/components/ActionList/__tests__/ActionList.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,49 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ActionList } from '../ActionList'; | ||
|
|
||
| describe('action list', () => { | ||
| test('renders successfully', () => { | ||
| const { asFragment } = render(<ActionList>test</ActionList>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| test('isIconList flag adds modifier', () => { | ||
| const { asFragment } = render(<ActionList isIconList>test</ActionList>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| test('Renders without children', () => { | ||
| render(<ActionList data-testid="action-list" />); | ||
| expect(screen.getByTestId('action-list')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders children', () => { | ||
| render(<ActionList>Test</ActionList>); | ||
|
|
||
| expect(screen.getByText('Test')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with class pf-c-action-list', () => { | ||
| render(<ActionList>Test</ActionList>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('pf-c-action-list'); | ||
| }); | ||
|
|
||
| test('Renders with custom class names provided via prop', () => { | ||
| render(<ActionList className="custom-class">Test</ActionList>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('custom-class'); | ||
| }); | ||
|
|
||
| test('Does not render with class pf-m-icons by default', () => { | ||
| render(<ActionList>Test</ActionList>); | ||
|
|
||
| expect(screen.getByText('Test')).not.toHaveClass('pf-m-icons'); | ||
| }); | ||
|
|
||
| test('Renders with class pf-m-icons when isIconList is true', () => { | ||
| render(<ActionList isIconList={true}>Test</ActionList>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('pf-m-icons'); | ||
| }); | ||
|
|
||
| test('Renders with inherited element props spread to the component', () => { | ||
| render(<ActionList aria-label="Test label">Test</ActionList>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveAccessibleName('Test label'); | ||
| }) | ||
|
|
||
| test('Matches the snapshot', () => { | ||
| const { asFragment } = render(<ActionList>test</ActionList>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
41 changes: 34 additions & 7 deletions
41
packages/react-core/src/components/ActionList/__tests__/ActionListGroup.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,37 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ActionListGroup } from '../ActionListGroup'; | ||
|
|
||
| describe('action list group', () => { | ||
| test('renders successfully', () => { | ||
| const { asFragment } = render(<ActionListGroup>test</ActionListGroup>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| test('Renders without children', () => { | ||
| render(<ActionListGroup data-testid="action-list-group" />); | ||
| expect(screen.getByTestId('action-list-group')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders children', () => { | ||
| render(<ActionListGroup>Test</ActionListGroup>); | ||
|
|
||
| expect(screen.getByText('Test')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with class pf-c-action-list__group', () => { | ||
| render(<ActionListGroup>Test</ActionListGroup>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('pf-c-action-list__group'); | ||
| }); | ||
|
|
||
| test('Renders with custom class names provided via prop', () => { | ||
| render(<ActionListGroup className="custom-class">Test</ActionListGroup>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('custom-class'); | ||
| }); | ||
|
|
||
| test('Renders with inherited element props spread to the component', () => { | ||
| render(<ActionListGroup aria-label="Test label">Test</ActionListGroup>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveAccessibleName('Test label'); | ||
| }) | ||
|
|
||
| test('Matches the snapshot', () => { | ||
| const { asFragment } = render(<ActionListGroup>test</ActionListGroup>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); |
41 changes: 34 additions & 7 deletions
41
packages/react-core/src/components/ActionList/__tests__/ActionListItem.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,37 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ActionListItem } from '../ActionListItem'; | ||
|
|
||
| describe('action list item', () => { | ||
| test('renders successfully', () => { | ||
| const { asFragment } = render(<ActionListItem>test</ActionListItem>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| test('Renders without children', () => { | ||
| render(<ActionListItem data-testid="action-list-item" />); | ||
| expect(screen.getByTestId('action-list-item')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders children', () => { | ||
| render(<ActionListItem>Test</ActionListItem>); | ||
|
|
||
| expect(screen.getByText('Test')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with class pf-c-action-list__item', () => { | ||
| render(<ActionListItem>Test</ActionListItem>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('pf-c-action-list__item'); | ||
| }); | ||
|
|
||
| test('Renders with custom class names provided via prop', () => { | ||
| render(<ActionListItem className="custom-class">Test</ActionListItem>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveClass('custom-class'); | ||
| }); | ||
|
|
||
| test('Renders with inherited element props spread to the component', () => { | ||
| render(<ActionListItem aria-label="Test label">Test</ActionListItem>); | ||
|
|
||
| expect(screen.getByText('Test')).toHaveAccessibleName('Test label'); | ||
| }) | ||
|
|
||
| test('Matches the snapshot', () => { | ||
| const { asFragment } = render(<ActionListItem>test</ActionListItem>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); |
12 changes: 1 addition & 11 deletions
12
...ges/react-core/src/components/ActionList/__tests__/__snapshots__/ActionList.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...eact-core/src/components/ActionList/__tests__/__snapshots__/ActionListGroup.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...react-core/src/components/ActionList/__tests__/__snapshots__/ActionListItem.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be reasonable to combine this test with the last since they are rendering the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and there are a couple other below that also render the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely wouldn't call it unreasonable to combine them, but I personally would advocate for a testing approach that only makes assertions about one aspect of component behavior in each test.
The primary reason being that I believe single behavior tests provide maximum utility from the test suite, as with this approach a failing test (or combination of them) can often point you straight to where a regression was introduced.