forked from arp82/samples-for-react-testing-library-training
-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/issue#19 on mouse up on mouse down tests #24
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
Open
reginafernandezpinar
wants to merge
9
commits into
develop
Choose a base branch
from
feature/issue#19-onMouseUp-onMouseDown-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2422b2f
issue#19: include onMouseUp onMouseDown and onContextMenu events
7036994
feature/issue#19: tests onMouse first approach
e40f90c
feature/issue#19: solve conflicts
5e111f6
feature/issue#19-onMouseUp-onMouseDown-tests: fix context menu display
a770d95
issue#19: Add onMouseUp and onMouseDown tests
8fa7d61
issue#19: Fix lint errors and delete unnecessary comments
cbc44f4
feature/issue#19-onMouseUp-onMouseDown-tests: test menu context
c6e7c97
feature/issue#19-onMouseUp-onMouseDown-tests: add comment
d4c29ba
feature/issue#19-onMouseUp-onMouseDown-tests: fix linter
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
56 changes: 38 additions & 18 deletions
56
03 Tests samples/src/components/MessageList/MessageList.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,47 +1,67 @@ | ||
| import * as React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
| import { shallow } from 'enzyme'; | ||
| import { configure } from 'enzyme'; | ||
| import Adapter from 'enzyme-adapter-react-16'; | ||
| import {MessageList} from './MessageList'; | ||
| import { MessageList } from './MessageList'; | ||
|
|
||
| describe('Message List component test', () => { | ||
| configure({ adapter: new Adapter() }); | ||
|
|
||
| let component; | ||
|
|
||
| const messages = [ | ||
| { | ||
| id: 1, | ||
| subject: 'Hello world', | ||
| body: 'Hello world', | ||
| }, | ||
| ]; | ||
|
|
||
| beforeEach(() => { | ||
| component = shallow(< MessageList messages={[]}/>); | ||
| component = shallow(<MessageList messages={[]} />); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should render a table', () =>{ | ||
| it('should render a table', () => { | ||
| expect(component.find('table')).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('should render two th', () =>{ | ||
| it('should render two th', () => { | ||
| expect(component.find('th')).toHaveLength(2); | ||
| }); | ||
|
|
||
| it('should render a thead', () =>{ | ||
| it('should render a thead', () => { | ||
| expect(component.find('thead')).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('should render a tbody', () =>{ | ||
| it('should render a tbody', () => { | ||
| expect(component.find('tbody')).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('should render none td', () =>{ | ||
| it('should render none td', () => { | ||
| expect(component.find('td')).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('should render two td', () => { | ||
| let messages = [ | ||
| { | ||
| id: 1, | ||
| subject: 'Hello world', | ||
| body: 'Hello world' | ||
| } | ||
| ]; | ||
| component = shallow(< MessageList messages={messages}/>); | ||
| component = shallow(<MessageList messages={messages} />); | ||
| expect(component.find('td')).toHaveLength(2); | ||
| }); | ||
| }); | ||
|
|
||
| it('should alert mousedown on mouse down on the tr', () => { | ||
| jest.spyOn(window, 'alert').mockImplementation(() => {}); | ||
| component = shallow(<MessageList messages={messages} />); | ||
| const bodyMessages = component.find('tr').at(1); | ||
| bodyMessages.simulate('mousedown', { type: 'mousedown' }); | ||
| expect(window.alert).toBeCalledWith('mousedown'); | ||
| }); | ||
|
|
||
| it('should alert mouseup on mouse up on the tr', () => { | ||
| jest.spyOn(window, 'alert').mockImplementation(() => {}); | ||
| component = shallow(<MessageList messages={messages} />); | ||
| const bodyMessages = component.find('tr').at(1); | ||
| bodyMessages.simulate('mouseup', { type: 'mouseup' }); | ||
| expect(window.alert).toBeCalledWith('mouseup'); | ||
| }); | ||
| }); |
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
40 changes: 40 additions & 0 deletions
40
03 Tests samples/src/components/MessageList/onContextMenu.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,40 @@ | ||
| import * as React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
| import { configure } from 'enzyme'; | ||
| import Adapter from 'enzyme-adapter-react-16'; | ||
| import { MessageList } from './MessageList'; | ||
|
|
||
| describe('Message List component test', () => { | ||
| configure({ adapter: new Adapter() }); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as before |
||
|
|
||
| let component; | ||
|
|
||
| beforeEach(() => { | ||
| component = shallow(<MessageList messages={[]} />); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should open a context-menu on right clicking on the table', () => { | ||
| const preventDefault = jest.fn(); | ||
| component | ||
| .find('div') | ||
| .at(0) | ||
| .simulate('contextMenu', { clientX: 969, clientY: 140, preventDefault }); | ||
| expect(component.find('.context-menu-info')).toHaveLength(1); | ||
| }); | ||
| // This test passes due to the setTimeout function, we should work over this. | ||
| it('should close context menu', () => { | ||
| const preventDefault = jest.fn(); | ||
| component | ||
| .find('div') | ||
| .at(0) | ||
| .simulate('contextMenu', { clientX: 969, clientY: 140, preventDefault }); | ||
| component.find('div').at(0).simulate('mousedown', { which: 1 }); | ||
| setTimeout(() => { | ||
| expect(component.find('.context-menu-info')).toHaveLength(0); | ||
| }, 150); | ||
| }); | ||
| }); | ||
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.
Please try to do this generic to only acces as config file and not need to call and configure this in every test file