-
Notifications
You must be signed in to change notification settings - Fork 377
chore: Migrate tests to RTL (4) #7044
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 3 commits into
patternfly:main
from
jpuzz0:chore/rtl-migrate-bundle-4
Apr 8, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
66 changes: 33 additions & 33 deletions
66
packages/react-core/src/components/List/__tests__/List.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,120 +1,120 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { mount } from 'enzyme'; | ||
| import { List, ListVariant, ListComponent, OrderType } from '../List'; | ||
| import { ListItem } from '../ListItem'; | ||
|
|
||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| import BookOpen from '@patternfly/react-icons/dist/esm/icons/book-open-icon'; | ||
| import Key from '@patternfly/react-icons/dist/esm/icons/key-icon'; | ||
| import Desktop from '@patternfly/react-icons/dist/esm/icons/desktop-icon'; | ||
| import { List, ListVariant, ListComponent, OrderType } from '../List'; | ||
| import { ListItem } from '../ListItem'; | ||
|
|
||
| const ListItems = () => ( | ||
| <React.Fragment> | ||
| <List> | ||
| <ListItem>First</ListItem> | ||
| <ListItem>Second</ListItem> | ||
| <ListItem>Third</ListItem> | ||
| </List> | ||
| </React.Fragment> | ||
| <List> | ||
| <ListItem>First</ListItem> | ||
| <ListItem>Second</ListItem> | ||
| <ListItem>Third</ListItem> | ||
| </List> | ||
| ); | ||
|
|
||
| describe('list', () => { | ||
| describe('List', () => { | ||
| test('simple list', () => { | ||
| const view = render( | ||
| const { asFragment } = render( | ||
| <List> | ||
| <ListItems /> | ||
| </List> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('inline list', () => { | ||
| const view = render( | ||
| const { asFragment } = render( | ||
| <List variant={ListVariant.inline}> | ||
| <ListItems /> | ||
| </List> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('ordered list', () => { | ||
| const view = mount( | ||
| const { asFragment } = render( | ||
| <List component={ListComponent.ol}> | ||
| <ListItem>Apple</ListItem> | ||
| <ListItem>Banana</ListItem> | ||
| <ListItem>Orange</ListItem> | ||
| </List> | ||
| ); | ||
| expect(view.find('ol').length).toBe(1); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('ordered list starts with 2nd item', () => { | ||
| const view = mount( | ||
| render( | ||
| <List component={ListComponent.ol} start={2}> | ||
| <ListItem>Banana</ListItem> | ||
| <ListItem>Orange</ListItem> | ||
| </List> | ||
| ); | ||
| expect(view.find('ol').prop('start')).toBe(2); | ||
| expect(screen.getByRole('list')).toHaveAttribute('start', '2'); | ||
| }); | ||
|
|
||
| test('ordered list items will be numbered with uppercase letters', () => { | ||
| const view = mount( | ||
| render( | ||
| <List component={ListComponent.ol} type={OrderType.uppercaseLetter}> | ||
| <ListItem>Banana</ListItem> | ||
| <ListItem>Orange</ListItem> | ||
| </List> | ||
| ); | ||
| expect(view.find('ol').prop('type')).toBe('A'); | ||
| expect(screen.getByRole('list')).toHaveAttribute('type', 'A'); | ||
| }); | ||
|
|
||
| test('inlined ordered list', () => { | ||
| const view = mount( | ||
| render( | ||
| <List variant={ListVariant.inline} component={ListComponent.ol}> | ||
| <ListItem>Apple</ListItem> | ||
| <ListItem>Banana</ListItem> | ||
| <ListItem>Orange</ListItem> | ||
| </List> | ||
| ); | ||
| expect(view.find('ol.pf-m-inline').length).toBe(1); | ||
| expect(screen.getByRole('list')).toHaveClass('pf-m-inline'); | ||
| }); | ||
|
|
||
| test('bordered list', () => { | ||
| const view = render( | ||
| render( | ||
| <List isBordered> | ||
| <ListItems /> | ||
| </List> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(screen.getAllByRole('list')[0]).toHaveClass('pf-m-bordered'); | ||
| }); | ||
|
|
||
| test('plain list', () => { | ||
| const view = render( | ||
| render( | ||
| <List isPlain> | ||
| <ListItems /> | ||
| </List> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(screen.getAllByRole('list')[0]).toHaveClass('pf-m-plain'); | ||
| }); | ||
|
|
||
| test('icon list', () => { | ||
| const view = render( | ||
| const { asFragment } = render( | ||
| <List isPlain> | ||
| <ListItem icon={<BookOpen />}>Apple</ListItem> | ||
| <ListItem icon={<Key />}>Banana</ListItem> | ||
| <ListItem icon={<Desktop />}>Orange</ListItem> | ||
| </List> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('icon large list', () => { | ||
| const view = render( | ||
| <List iconSize='large'> | ||
| const { asFragment } = render( | ||
| <List iconSize="large"> | ||
| <ListItem icon={<BookOpen />}>Apple</ListItem> | ||
| <ListItem icon={<Key />}>Banana</ListItem> | ||
| <ListItem icon={<Desktop />}>Orange</ListItem> | ||
| </List> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
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
70 changes: 37 additions & 33 deletions
70
packages/react-core/src/components/Menu/__tests__/Menu.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,46 +1,50 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { mount } from 'enzyme'; | ||
|
|
||
| import { render, screen } from '@testing-library/react'; | ||
| import "@testing-library/jest-dom"; | ||
|
|
||
| import { Menu } from '../Menu'; | ||
|
|
||
| test('should render Menu successfully', () => { | ||
| const view = render( | ||
| <Menu activeItemId={0} onSelect={jest.fn()}> | ||
| content | ||
| </Menu> | ||
| describe('Menu', () => { | ||
| test('should render Menu successfully', () => { | ||
| const { asFragment } = render( | ||
| <Menu activeItemId={0} onSelect={jest.fn()}> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(view.container).toMatchSnapshot(); | ||
| }); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| describe('with isPlain', () => { | ||
| describe('with isPlain', () => { | ||
| test('should render Menu with plain styles applied', () => { | ||
| const view = mount( | ||
| <Menu activeItemId={0} onSelect={jest.fn()} isPlain> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(view.find('div.pf-m-plain')).toMatchSnapshot(); | ||
| render( | ||
| <Menu activeItemId={0} onSelect={jest.fn()} isPlain> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(screen.getByText('content')).toHaveClass('pf-m-plain'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with isScrollable', () => { | ||
| describe('with isScrollable', () => { | ||
| test('should render Menu with scrollable styles applied', () => { | ||
| const view = mount( | ||
| <Menu activeItemId={0} onSelect={jest.fn()} isScrollable> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(view.find('div.pf-m-scrollable')).toMatchSnapshot(); | ||
| render( | ||
| <Menu activeItemId={0} onSelect={jest.fn()} isScrollable> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(screen.getByText('content')).toHaveClass('pf-m-scrollable'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with isNavFlyout', () => { | ||
| describe('with isNavFlyout', () => { | ||
| test('should render Menu with nav flyout styles applied', () => { | ||
| const view = mount( | ||
| <Menu activeItemId={0} onSelect={jest.fn()} isNavFlyout> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(view.find('div.pf-m-nav')).toMatchSnapshot(); | ||
| render( | ||
| <Menu activeItemId={0} onSelect={jest.fn()} isNavFlyout> | ||
| content | ||
| </Menu> | ||
| ); | ||
| expect(screen.getByText('content')).toHaveClass('pf-m-nav'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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.
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.
Should these 2 tests still be included to test
startandtypeproperties?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.
Yes, they should. I'll update. I was maybe thinking those weren't props that translated to ones we'd see in the DOM.