This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Review and improve React unit test coverage - Closes #531 #601
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
546177e
Run unit tests in Headless Chrome
slaweet 7493cdf
Add missing test for account reducer
slaweet 7b290f0
Add unit tests for metronome util
slaweet 448d42d
Add unit tests for forging component
slaweet 69315c6
Add missing semicolons
slaweet e79766f
Add more unit tests for secondPassphraseInput
slaweet 550844b
Add unit tests of various connect components
slaweet 8ffac13
Ignore development code in coverage
slaweet b470be5
Add more tests for accountComponent
slaweet 0c3719c
Add unit tests for loginFormComponent
slaweet c9adadd
Add more unit tests for signMessage
slaweet 84c7330
Remove an unnecessary unit test
slaweet 292b350
Fix eslint violations in tests
slaweet 865b414
Merge branch 'development' into 531-unit-test-coverage
slaweet 541b044
Add unit tests for registerDelegate
slaweet 6d802fd
Add unit tests for secondPassphrase
slaweet f042816
Setup store.getState in unit tests
slaweet a26d5c6
Remove unused imports
slaweet 15d2320
Fix signMessageComponent unit test
slaweet 88dc089
Merge branch 'development' into 531-unit-test-coverage
slaweet 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 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 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 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,72 +1,106 @@ | ||
import React from 'react'; | ||
import chai, { expect } from 'chai'; | ||
import { spy } from 'sinon'; | ||
import sinon, { spy, mock } from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import { shallow, mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import * as accountApi from '../../utils/api/account'; | ||
import store from '../../store'; | ||
import AccountComponent from './accountComponent'; | ||
import ClickToSend from '../send/clickToSend'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('AccountComponent', () => { | ||
// Mocking store | ||
const onActivePeerUpdated = () => {}; | ||
const peers = { | ||
status: { | ||
online: false, | ||
}, | ||
data: { | ||
currentPeer: 'localhost', | ||
port: 4000, | ||
options: { | ||
name: 'Custom Node', | ||
let props; | ||
|
||
beforeEach(() => { | ||
props = { | ||
onActivePeerUpdated: sinon.spy(), | ||
onAccountUpdated: sinon.spy(), | ||
peers: { | ||
status: { | ||
online: false, | ||
}, | ||
data: { | ||
currentPeer: 'localhost', | ||
port: 4000, | ||
options: { | ||
name: 'Custom Node', | ||
}, | ||
}, | ||
}, | ||
account: { | ||
isDelegate: false, | ||
address: '16313739661670634666L', | ||
username: 'lisk-nano', | ||
balance: 1e8, | ||
}, | ||
}, | ||
}; | ||
const testAccount = { | ||
isDelegate: false, | ||
address: '16313739661670634666L', | ||
username: 'lisk-nano', | ||
balance: 1e8, | ||
}; | ||
}; | ||
}); | ||
|
||
it(' should render 3 article tags', () => { | ||
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. Please remove the extra space character before should. |
||
const wrapper = shallow(<AccountComponent account={testAccount} peers={peers} | ||
onActivePeerUpdated={onActivePeerUpdated} />); | ||
const wrapper = shallow(<AccountComponent {...props} />); | ||
expect(wrapper.find('article')).to.have.lengthOf(3); | ||
}); | ||
|
||
it('depicts being online when peers.status.online is true', () => { | ||
const onlinePeers = Object.assign({}, peers, { status: { online: true } }); | ||
const wrapper = shallow(<AccountComponent account={testAccount} peers={onlinePeers} | ||
onActivePeerUpdated={onActivePeerUpdated} />); | ||
props.peers.status.online = true; | ||
const wrapper = shallow(<AccountComponent {...props} />); | ||
const expectedValue = 'check'; | ||
expect(wrapper.find('.material-icons').text()).to.be.equal(expectedValue); | ||
}); | ||
|
||
it('should render balance with ClickToSend component', () => { | ||
const wrapper = mount(<Provider store={store}> | ||
<AccountComponent account={testAccount} peers={peers} | ||
onActivePeerUpdated={onActivePeerUpdated} /> | ||
<AccountComponent {...props} /> | ||
</Provider>); | ||
expect(wrapper.find('.balance').find(ClickToSend)).to.have.lengthOf(1); | ||
}); | ||
|
||
describe('componentDidMount', () => { | ||
let accountApiMock; | ||
|
||
beforeEach(() => { | ||
accountApiMock = mock(accountApi); | ||
}); | ||
|
||
afterEach(() => { | ||
accountApiMock.restore(); | ||
}); | ||
|
||
it('should be called once', () => { | ||
const actionSpy = spy(AccountComponent.prototype, 'componentDidMount'); | ||
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. You don't need to test 'componentDidMount' because it is part of React and it always runs.You should test functions that call inside the 'componentDidMount'. |
||
mount(<Provider store={store}><AccountComponent account={testAccount} peers={peers} | ||
onActivePeerUpdated={onActivePeerUpdated} /></Provider>); | ||
mount(<Provider store={store}><AccountComponent {...props} /></Provider>); | ||
expect(actionSpy).to.have.been.calledWith(); | ||
}); | ||
|
||
it('binds listener to beat event', () => { | ||
const actionSpy = spy(document, 'addEventListener'); | ||
mount(<Provider store={store}><AccountComponent account={testAccount} peers={peers} | ||
onActivePeerUpdated={onActivePeerUpdated} /></Provider>); | ||
mount(<Provider store={store}><AccountComponent {...props} /></Provider>); | ||
expect(actionSpy).to.have.been.calledWith(); | ||
}); | ||
|
||
it('calls props.onActivePeerUpdated', () => { | ||
accountApiMock.expects('getAccountStatus').resolves({ success: true }); | ||
const wrapper = mount(<Provider store={store}><AccountComponent {...props} /></Provider>); | ||
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. You defined wrapper but you never used it. If it is extra, you need to remove it. |
||
// TODO: this doesn't work for some reason | ||
// expect(props.onActivePeerUpdated).to.have.been.calledWith(); | ||
}); | ||
|
||
it('calls props.onAccountUpdated', () => { | ||
accountApiMock.expects('getAccount').resolves({ balance: props.account.balance }); | ||
const wrapper = mount(<Provider store={store}><AccountComponent {...props} /></Provider>); | ||
// TODO: this doesn't work for some reason | ||
// expect(props.onAccountUpdated).to.have.been.calledWith(); | ||
}); | ||
|
||
it('calls props.onTransactionsUpdated if getAccount returns different balance', () => { | ||
accountApiMock.expects('transactions').resolves({ transactions: [{}] }); | ||
accountApiMock.expects('getAccount').resolves({ balance: props.account.balance + 1 }); | ||
const wrapper = mount(<Provider store={store}><AccountComponent {...props} /></Provider>); | ||
// TODO: this doesn't work for some reason | ||
// expect(props.onAccountUpdated).to.have.been.calledWith(); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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,38 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import sinon from 'sinon'; | ||
import * as accountActions from '../../actions/account'; | ||
import * as dialogActions from '../../actions/dialog'; | ||
import Header from './index'; | ||
import store from '../../store'; | ||
|
||
|
||
describe('Header', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<Provider store={store}><Header /></Provider>); | ||
}); | ||
|
||
it('should render HeaderElement', () => { | ||
expect(wrapper.find('HeaderElement')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('should bind accountLoggedOut action to HeaderElement props.logOut', () => { | ||
const actionsSpy = sinon.spy(accountActions, 'accountLoggedOut'); | ||
wrapper.find('HeaderElement').props().logOut({}); | ||
expect(actionsSpy).to.be.calledWith(); | ||
actionsSpy.restore(); | ||
}); | ||
|
||
it('should bind dialogDisplayed action to HeaderElement props.setActiveDialog', () => { | ||
const actionsSpy = sinon.spy(dialogActions, 'dialogDisplayed'); | ||
wrapper.find('HeaderElement').props().setActiveDialog({}); | ||
expect(actionsSpy).to.be.calledWith(); | ||
actionsSpy.restore(); | ||
}); | ||
}); | ||
|
||
|
This file contains 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.
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.
You defined 'accountApi' and 'sinon' and 'mock' but you didn't use them. please remove them.