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.
- Loading branch information
Showing
4 changed files
with
51 additions
and
138 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
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,111 +1,23 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import configureStore from 'redux-mock-store'; | ||
import RegisterDelegate from './registerDelegate'; | ||
import RegisterDelegateConnected from './index'; | ||
import { accountUpdated } from '../../actions/account'; | ||
import actionTypes from '../../constants/actions'; | ||
import Alert from '../dialog/alert'; | ||
import { Provider } from 'react-redux'; | ||
import store from '../../store'; | ||
import RegisterDelegate from './index'; | ||
|
||
const fakeStore = configureStore(); | ||
|
||
describe('RegisterDelegateConnected', () => { | ||
let mountedAccount; | ||
// Mocking store | ||
const peers = { | ||
status: { | ||
online: false, | ||
}, | ||
data: { | ||
currentPeer: 'localhost', | ||
port: 4000, | ||
options: { | ||
name: 'Custom Node', | ||
}, | ||
}, | ||
}; | ||
|
||
const account = { | ||
isDelegate: false, | ||
address: '16313739661670634666L', | ||
username: 'lisk-nano', | ||
}; | ||
|
||
const store = fakeStore({ | ||
account, | ||
peers, | ||
}); | ||
|
||
const initialProps = { | ||
onAccountUpdated: () => (data) => { | ||
store.account = data; | ||
return accountUpdated(data); | ||
}, | ||
showSuccessAlert: () => {}, | ||
showErrorAlert: () => {}, | ||
}; | ||
describe('RegisterDelegate HOC', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
mountedAccount = mount(<RegisterDelegateConnected store={store} {...initialProps} />); | ||
}); | ||
|
||
it('should mount registerDelegate with appropriate properties', () => { | ||
const props = mountedAccount.find(RegisterDelegate).props(); | ||
expect(props.peers).to.be.equal(peers); | ||
expect(props.account).to.be.equal(account); | ||
expect(typeof props.onAccountUpdated).to.be.equal('function'); | ||
expect(typeof props.showSuccessAlert).to.be.equal('function'); | ||
expect(typeof props.showErrorAlert).to.be.equal('function'); | ||
wrapper = mount(<Provider store={store}><RegisterDelegate closeDialog={() => {}} /></Provider>); | ||
}); | ||
|
||
describe('onAccountUpdated', () => { | ||
it('should return a dispatch object', () => { | ||
const props = mountedAccount.find(RegisterDelegate).props(); | ||
const data = props.onAccountUpdated(account); | ||
|
||
expect(data).to.deep.equal({ | ||
type: actionTypes.accountUpdated, | ||
data: account, | ||
}); | ||
}); | ||
it('should render RegisterDelegate', () => { | ||
expect(wrapper.find('RegisterDelegate')).to.have.lengthOf(1); | ||
}); | ||
|
||
describe('showSuccessAlert', () => { | ||
it('should return a dispatch object', () => { | ||
const props = mountedAccount.find(RegisterDelegate).props(); | ||
const data = props.showSuccessAlert({ text: 'sample text' }); | ||
|
||
expect(data).to.deep.equal({ | ||
type: actionTypes.dialogDisplayed, | ||
data: { | ||
title: 'Success', | ||
type: 'success', | ||
childComponent: Alert, | ||
childComponentProps: { | ||
text: 'sample text', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('showErrorAlert', () => { | ||
it('should return a dispatch object', () => { | ||
const props = mountedAccount.find(RegisterDelegate).props(); | ||
const data = props.showErrorAlert({ text: 'sample text' }); | ||
|
||
expect(data).to.deep.equal({ | ||
type: actionTypes.dialogHidden, | ||
data: { | ||
title: 'Error', | ||
type: 'error', | ||
childComponent: Alert, | ||
childComponentProps: { | ||
text: 'sample text', | ||
}, | ||
}, | ||
}); | ||
}); | ||
it('should mount registerDelegate with appropriate properties', () => { | ||
const props = wrapper.find('RegisterDelegate').props(); | ||
expect(typeof props.closeDialog).to.be.equal('function'); | ||
}); | ||
}); |
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