-
Notifications
You must be signed in to change notification settings - Fork 24
Add React Testing Library migration infrastructure and first conversions #385
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
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
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
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,13 +1,18 @@ | ||
| import React from 'react'; | ||
| import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { renderWithContexts } from '../../../testUtils/rtlContexts'; | ||
|
|
||
| import AlertModal from './AlertModal'; | ||
|
|
||
| describe('AlertModal', () => { | ||
| test('renders the expected content', () => { | ||
| const wrapper = mountWithContexts( | ||
| <AlertModal title="Danger!">Are you sure?</AlertModal> | ||
| renderWithContexts( | ||
| <AlertModal isOpen title="Danger!"> | ||
| Are you sure? | ||
| </AlertModal> | ||
| ); | ||
| expect(wrapper).toHaveLength(1); | ||
| expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
| expect(screen.getByText('Danger!')).toBeInTheDocument(); | ||
| expect(screen.getByText('Are you sure?')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,18 @@ | ||
| import React from 'react'; | ||
| import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
| import { Chip } from '@patternfly/react-core'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { renderWithContexts } from '../../../testUtils/rtlContexts'; | ||
| import ChipGroup from './ChipGroup'; | ||
|
|
||
| describe('ChipGroup', () => { | ||
| test('should mount properly', () => { | ||
| const wrapper = mountWithContexts( | ||
| <ChipGroup numChips={5} totalChips={10} /> | ||
| ); | ||
| expect(wrapper.find('ChipGroup').at(1).props().collapsedText).toEqual( | ||
| '5 more' | ||
| test('should show the collapsed-chip count', () => { | ||
| renderWithContexts( | ||
| <ChipGroup numChips={5} totalChips={10}> | ||
| {Array.from({ length: 10 }, (v, i) => ( | ||
| <Chip key={i}>{`chip ${i}`}</Chip> | ||
| ))} | ||
| </ChipGroup> | ||
| ); | ||
| expect(screen.getByText('5 more')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,11 +1,12 @@ | ||
| import React from 'react'; | ||
| import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { renderWithContexts } from '../../../testUtils/rtlContexts'; | ||
|
|
||
| import ContentEmpty from './ContentEmpty'; | ||
|
|
||
| describe('ContentEmpty', () => { | ||
| test('renders the expected content', () => { | ||
| const wrapper = mountWithContexts(<ContentEmpty />); | ||
| expect(wrapper).toHaveLength(1); | ||
| renderWithContexts(<ContentEmpty />); | ||
| expect(screen.getByText('No items found.')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,11 +1,12 @@ | ||
| import React from 'react'; | ||
| import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { renderWithContexts } from '../../../testUtils/rtlContexts'; | ||
|
|
||
| import ContentLoading from './ContentLoading'; | ||
|
|
||
| describe('ContentLoading', () => { | ||
| test('renders the expected content', () => { | ||
| const wrapper = mountWithContexts(<ContentLoading />); | ||
| expect(wrapper).toHaveLength(1); | ||
| renderWithContexts(<ContentLoading />); | ||
| expect(screen.getByRole('progressbar')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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
16 changes: 11 additions & 5 deletions
16
awx/ui/src/components/FormActionGroup/FormActionGroup.test.js
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,13 +1,19 @@ | ||
| import React from 'react'; | ||
| import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { renderWithContexts } from '../../../testUtils/rtlContexts'; | ||
|
|
||
| import FormActionGroup from './FormActionGroup'; | ||
|
|
||
| describe('FormActionGroup', () => { | ||
| test('should render the expected content', () => { | ||
| const wrapper = mountWithContexts( | ||
| <FormActionGroup onSubmit={() => {}} onCancel={() => {}} /> | ||
| test('should render save and cancel buttons and invoke their handlers', async () => { | ||
| const onSubmit = jest.fn(); | ||
| const onCancel = jest.fn(); | ||
| const { user } = renderWithContexts( | ||
| <FormActionGroup onSubmit={onSubmit} onCancel={onCancel} /> | ||
| ); | ||
| expect(wrapper).toHaveLength(1); | ||
| await user.click(screen.getByRole('button', { name: 'Save' })); | ||
| expect(onSubmit).toHaveBeenCalled(); | ||
| await user.click(screen.getByRole('button', { name: 'Cancel' })); | ||
| expect(onCancel).toHaveBeenCalled(); | ||
| }); | ||
| }); |
12 changes: 6 additions & 6 deletions
12
awx/ui/src/components/PaginatedTable/ToolbarSyncSourceButton.test.js
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,16 +1,16 @@ | ||
| import React from 'react'; | ||
| import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { renderWithContexts } from '../../../testUtils/rtlContexts'; | ||
| import ToolbarSyncSourceButton from './ToolbarSyncSourceButton'; | ||
|
|
||
| describe('<ToolbarSyncSourceButton />', () => { | ||
| test('should render button', () => { | ||
| test('should render button and invoke onClick', async () => { | ||
| const onClick = jest.fn(); | ||
| const wrapper = mountWithContexts( | ||
| const { user } = renderWithContexts( | ||
| <ToolbarSyncSourceButton onClick={onClick} /> | ||
| ); | ||
| const button = wrapper.find('button'); | ||
| expect(button).toHaveLength(1); | ||
| button.simulate('click'); | ||
| const button = screen.getByRole('button', { name: 'Sync all' }); | ||
| await user.click(button); | ||
| expect(onClick).toHaveBeenCalled(); | ||
| }); | ||
| }); |
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
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing | ||
|
|
||
| exports[`mountWithContexts injected ConfigProvider should mount and render with custom Config value 1`] = ` | ||
| <Foo> | ||
| <div> | ||
| 1.1 | ||
| </div> | ||
| </Foo> | ||
| `; | ||
|
|
||
| exports[`mountWithContexts injected ConfigProvider should mount and render with default values 1`] = ` | ||
| <Foo> | ||
| <div /> | ||
| </Foo> | ||
| `; | ||
|
|
||
| exports[`mountWithContexts injected I18nProvider should mount and render 1`] = ` | ||
| <div> | ||
| <span> | ||
| Text content | ||
| </span> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`mountWithContexts injected I18nProvider should mount and render deeply nested consumer 1`] = ` | ||
| <Parent> | ||
| <Child> | ||
| <div> | ||
| Text content | ||
| </div> | ||
| </Child> | ||
| </Parent> | ||
| `; | ||
|
|
||
| exports[`mountWithContexts injected Router should mount and render 1`] = ` | ||
| <div> | ||
| <Link | ||
| to="/" | ||
| > | ||
| <LinkAnchor | ||
| href="/" | ||
| navigate={[Function]} | ||
| > | ||
| <a | ||
| href="/" | ||
| onClick={[Function]} | ||
| > | ||
| home | ||
| </a> | ||
| </LinkAnchor> | ||
| </Link> | ||
| </div> | ||
| `; |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.