Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Add unit tests for SaveAccount component
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Sep 12, 2017
1 parent 1ba157d commit 2726726
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/saveAccount/index.test.js
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();
});
});

50 changes: 50 additions & 0 deletions src/components/saveAccount/saveAccount.test.js
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);
});
});

0 comments on commit 2726726

Please sign in to comment.