-
Notifications
You must be signed in to change notification settings - Fork 134
test: convert src/containers/shared (minus txs) to RTL #1279
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c2ad512
convert src/containers/shared (minus txs) to RTL
mvadari f5d86e4
fix linting
mvadari 09fbc5e
Apply suggestions from code review
mvadari 7d792da
respond to comments
mvadari 6f74000
fix tests
mvadari da77744
fix local tests
mvadari 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
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
42 changes: 22 additions & 20 deletions
42
src/containers/shared/components/Dropdown/test/DropdownItem.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,64 +1,66 @@ | ||
| import { mount } from 'enzyme' | ||
| import { cleanup, fireEvent, render, screen } from '@testing-library/react' | ||
| import { DropdownItem } from '../DropdownItem' | ||
|
|
||
| describe('DropdownItem', () => { | ||
| afterEach(cleanup) | ||
| describe(`prop: className`, () => { | ||
| it('renders with custom className', () => { | ||
| const wrapper = mount( | ||
| <DropdownItem className="custom">Hello</DropdownItem>, | ||
| ) | ||
| expect(wrapper.find('.dropdown-item')).toHaveClassName('custom') | ||
| render(<DropdownItem className="custom">Hello</DropdownItem>) | ||
| const item = screen.getByText('Hello') | ||
| expect(item).toHaveClass('custom') | ||
| }) | ||
| }) | ||
|
|
||
| describe('prop: handler', () => { | ||
| let wrapper | ||
| let item | ||
| const handler = jest.fn() | ||
|
|
||
| beforeEach(() => { | ||
| wrapper = mount(<DropdownItem handler={handler}>Hello</DropdownItem>) | ||
| render(<DropdownItem handler={handler}>Hello</DropdownItem>) | ||
| item = screen.getByText('Hello') | ||
| }) | ||
|
|
||
| it('renders as an anchor tag', () => { | ||
| expect(wrapper.find('.dropdown-item')).toHaveDisplayName('a') | ||
| expect(item.tagName).toBe('A') | ||
| }) | ||
|
|
||
| it('executes handler on click', () => { | ||
| wrapper.find('.dropdown-item').simulate('click') | ||
| fireEvent.click(item) | ||
| expect(handler).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('executes handler on keyup', () => { | ||
| wrapper.find('.dropdown-item').simulate('click') | ||
| fireEvent.click(item) | ||
| expect(handler).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('prop: href', () => { | ||
| let wrapper | ||
| let item | ||
|
|
||
| beforeEach(() => { | ||
| wrapper = mount( | ||
| <DropdownItem href="http://google.com">Hello</DropdownItem>, | ||
| ) | ||
| render(<DropdownItem href="http://google.com">Hello</DropdownItem>) | ||
| item = screen.getByText('Hello') | ||
| }) | ||
|
|
||
| it('renders as an anchor tag', () => { | ||
| expect(wrapper.find('.dropdown-item')).toHaveDisplayName('a') | ||
| expect(item.tagName).toBe('A') | ||
| }) | ||
|
|
||
| it('renders href attribute on anchor', () => { | ||
| expect(wrapper.find('.dropdown-item')).toHaveProp('href') | ||
| expect(item.tagName).toBe('A') | ||
| }) | ||
| }) | ||
|
|
||
| it('renders as div without handler or href', () => { | ||
| const wrapper = mount(<DropdownItem>Hello</DropdownItem>) | ||
| expect(wrapper.find('.dropdown-item')).toHaveDisplayName('div') | ||
| render(<DropdownItem>Hello</DropdownItem>) | ||
| const item = screen.getByText('Hello') | ||
| expect(item.tagName).toBe('DIV') | ||
| }) | ||
|
|
||
| it('adds aria roles', () => { | ||
| const wrapper = mount(<DropdownItem>Hello</DropdownItem>) | ||
| expect(wrapper.find('.dropdown-item')).toHaveProp('role', 'menuitem') | ||
| render(<DropdownItem>Hello</DropdownItem>) | ||
| const item = screen.getByText('Hello') | ||
| expect(item).toHaveAttribute('role', 'menuitem') | ||
| }) | ||
| }) | ||
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
100 changes: 100 additions & 0 deletions
100
src/containers/shared/components/Notification/tests/Notification.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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { cleanup, render, screen } from '@testing-library/react' | ||
| import { Notification } from '../index' | ||
|
|
||
| /* eslint-disable react/jsx-props-no-spreading */ | ||
| const VALID_USAGES = [ | ||
| 'default', | ||
| 'success', | ||
| 'warning', | ||
| 'danger', | ||
| 'dark', | ||
| 'light', | ||
| 'dark50', | ||
| ] | ||
| const notificationLevels = ['primary', 'secondary', 'ghost'] | ||
| const message = 'A catchy message' | ||
|
|
||
| const renderComponent = (props) => render(<Notification {...props} />) | ||
|
|
||
| describe('<Notification />', () => { | ||
| afterEach(cleanup) | ||
|
|
||
| it('renders without crashing', () => { | ||
| render(<Notification key="key" usage="danger" message="boo!" />) | ||
| }) | ||
|
|
||
| it('should render with custom className', () => { | ||
| const className = 'test-class' | ||
| renderComponent({ | ||
| message, | ||
| className, | ||
| }) | ||
| expect(screen.getByText(message).parentElement).toHaveClass(className) | ||
| }) | ||
|
|
||
| it('should render the action button', () => { | ||
| const action = <button type="button" /> | ||
| renderComponent({ | ||
| message, | ||
| action, | ||
| }) | ||
|
|
||
| expect(screen.getByRole('button')).toBeDefined() | ||
| }) | ||
|
|
||
| it('should render its message', () => { | ||
| const { container } = renderComponent({ | ||
| message, | ||
| }) | ||
|
|
||
| expect(container).toHaveTextContent(message) | ||
| }) | ||
|
|
||
| // test all notification levels | ||
| notificationLevels.map((level) => { | ||
| it(`should accept level prop of ${level}`, () => { | ||
| renderComponent({ | ||
| level, | ||
| message, | ||
| }) | ||
| expect(screen.getByText(message).parentElement).toHaveClass( | ||
| `notification default ${level}-theme`, | ||
| ) | ||
| }) | ||
|
|
||
| return false | ||
| }) | ||
|
|
||
| // test all notification usages | ||
| VALID_USAGES.map((usage) => { | ||
| it(`should render with usage prop of ${usage}`, () => { | ||
| renderComponent({ | ||
| usage, | ||
| message, | ||
| }) | ||
| expect(screen.getByText(message).parentElement).toHaveClass(usage) | ||
| }) | ||
|
|
||
| return false | ||
| }) | ||
|
|
||
| it('disappears', (done) => { | ||
| const { container } = render( | ||
| <Notification | ||
| key="key" | ||
| usage="danger" | ||
| message="boo!" | ||
| autoDismiss | ||
| delay={100} | ||
| />, | ||
| ) | ||
| expect(container.innerHTML).toBe( | ||
| '<div class="notification danger primary-theme " data-testid="notification"><span>boo!</span></div>', | ||
| ) | ||
|
|
||
| setTimeout(() => { | ||
| expect(container.innerHTML).toBe('') | ||
| done() | ||
| }, 200) | ||
| }) | ||
| }) |
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.
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.