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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for SaveAccount component
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import sinon from 'sinon'; | ||
import * as toasterActions from '../../actions/toaster'; | ||
import SaveAccountHOC from './index'; | ||
import store from '../../store'; | ||
|
||
|
||
describe('SaveAccountHOC', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<Provider store={store}><SaveAccountHOC /></Provider>); | ||
}); | ||
|
||
it('should render SaveAccount', () => { | ||
expect(wrapper.find('SaveAccount')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('should bind dialogDisplayed action to SaveAccount props.successToast', () => { | ||
const actionsSpy = sinon.spy(toasterActions, 'successToastDisplayed'); | ||
wrapper.find('SaveAccount').props().successToast({}); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import { spy } from 'sinon'; | ||
import SaveAccount from './saveAccount'; | ||
import store from '../../store'; | ||
|
||
|
||
describe('SaveAccount', () => { | ||
let wrapper; | ||
let closeDialogSpy; | ||
let successToastSpy; | ||
let localStorageSpy; | ||
|
||
const props = { | ||
account: { | ||
publicKey: 'fab9d261ea050b9e326d7e11587eccc343a20e64e29d8781b50fd06683cacc88', | ||
}, | ||
closeDialog: () => {}, | ||
successToast: () => {}, | ||
}; | ||
|
||
beforeEach(() => { | ||
closeDialogSpy = spy(props, 'closeDialog'); | ||
successToastSpy = spy(props, 'successToast'); | ||
localStorageSpy = spy(localStorage, 'setItem'); | ||
wrapper = mount(<Provider store={store}><SaveAccount {...props} /></Provider>); | ||
}); | ||
|
||
afterEach(() => { | ||
closeDialogSpy.restore(); | ||
successToastSpy.restore(); | ||
localStorageSpy.restore(); | ||
}); | ||
|
||
it('should render ActionBar', () => { | ||
expect(wrapper.find('ActionBar')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('should call props.closeDialog, props.successToast and localStorage.setItem on "save button" click', () => { | ||
wrapper.find('.save-button').simulate('click'); | ||
const componentProps = wrapper.find(SaveAccount).props(); | ||
expect(componentProps.closeDialog).to.have.been.calledWith(); | ||
expect(componentProps.successToast).to.have.been.calledWith({ label: 'Account saved' }); | ||
const expectedValue = '[{"publicKey":"fab9d261ea050b9e326d7e11587eccc343a20e64e29d8781b50fd06683cacc88","network":"0","address":null}]'; | ||
expect(localStorageSpy).to.have.been.calledWith('accounts', expectedValue); | ||
}); | ||
}); | ||
|