diff --git a/src/components/saveAccount/index.test.js b/src/components/saveAccount/index.test.js new file mode 100644 index 000000000..c582a5b17 --- /dev/null +++ b/src/components/saveAccount/index.test.js @@ -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(); + }); + + 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(); + }); +}); + diff --git a/src/components/saveAccount/saveAccount.test.js b/src/components/saveAccount/saveAccount.test.js new file mode 100644 index 000000000..12874fe46 --- /dev/null +++ b/src/components/saveAccount/saveAccount.test.js @@ -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(); + }); + + 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); + }); +}); +