Use shallow-only rendering in all tests (#4087)
* Container/Title with shallow * IdentityName with shallow * IdentityIcon with shallow * TypedInput to shallow * DetailsStep to shallow
This commit is contained in:
		
							parent
							
								
									4c94878cf7
								
							
						
					
					
						commit
						378739fae1
					
				| @ -14,15 +14,13 @@ | |||||||
| // You should have received a copy of the GNU General Public License
 | // You should have received a copy of the GNU General Public License
 | ||||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||||
| 
 | 
 | ||||||
| import { mount } from 'enzyme'; | import { shallow } from 'enzyme'; | ||||||
| import React from 'react'; | import React from 'react'; | ||||||
| import sinon from 'sinon'; | import sinon from 'sinon'; | ||||||
| 
 | 
 | ||||||
| import { ContextProvider, muiTheme } from '~/ui'; |  | ||||||
| 
 |  | ||||||
| import DetailsStep from './'; | import DetailsStep from './'; | ||||||
| 
 | 
 | ||||||
| import { createApi, STORE, CONTRACT } from '../executeContract.test.js'; | import { CONTRACT } from '../executeContract.test.js'; | ||||||
| 
 | 
 | ||||||
| let component; | let component; | ||||||
| let onAmountChange; | let onAmountChange; | ||||||
| @ -40,8 +38,7 @@ function render (props) { | |||||||
|   onGasEditClick = sinon.stub(); |   onGasEditClick = sinon.stub(); | ||||||
|   onValueChange = sinon.stub(); |   onValueChange = sinon.stub(); | ||||||
| 
 | 
 | ||||||
|   component = mount( |   component = shallow( | ||||||
|     <ContextProvider api={ createApi() } muiTheme={ muiTheme } store={ STORE }> |  | ||||||
|     <DetailsStep |     <DetailsStep | ||||||
|       { ...props } |       { ...props } | ||||||
|       contract={ CONTRACT } |       contract={ CONTRACT } | ||||||
| @ -51,7 +48,6 @@ function render (props) { | |||||||
|       onFuncChange={ onFuncChange } |       onFuncChange={ onFuncChange } | ||||||
|       onGasEditClick={ onGasEditClick } |       onGasEditClick={ onGasEditClick } | ||||||
|       onValueChange={ onValueChange } /> |       onValueChange={ onValueChange } /> | ||||||
|     </ContextProvider> |  | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   return component; |   return component; | ||||||
| @ -74,7 +70,7 @@ describe('modals/ExecuteContract/DetailsStep', () => { | |||||||
| 
 | 
 | ||||||
|     describe('bool parameters', () => { |     describe('bool parameters', () => { | ||||||
|       it('toggles from false to true', () => { |       it('toggles from false to true', () => { | ||||||
|         component.find('DropDownMenu').last().simulate('change', { target: { value: 'true' } }); |         component.find('TypedInput').last().shallow().simulate('change', { target: { value: 'true' } }); | ||||||
| 
 | 
 | ||||||
|         expect(onValueChange).to.have.been.calledWith(null, 0, true); |         expect(onValueChange).to.have.been.calledWith(null, 0, true); | ||||||
|       }); |       }); | ||||||
|  | |||||||
| @ -15,38 +15,32 @@ | |||||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||||
| 
 | 
 | ||||||
| import React from 'react'; | import React from 'react'; | ||||||
| import { mount, shallow } from 'enzyme'; | import { shallow } from 'enzyme'; | ||||||
| 
 | 
 | ||||||
| import Title from './title'; | import Title from './title'; | ||||||
| 
 | 
 | ||||||
| function renderShallow (props) { | function render (props) { | ||||||
|   return shallow( |   return shallow( | ||||||
|     <Title { ...props } /> |     <Title { ...props } /> | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function renderMount (props) { |  | ||||||
|   return mount( |  | ||||||
|     <Title { ...props } /> |  | ||||||
|   ); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| describe('ui/Container/Title', () => { | describe('ui/Container/Title', () => { | ||||||
|   describe('rendering', () => { |   describe('rendering', () => { | ||||||
|     it('renders defaults', () => { |     it('renders defaults', () => { | ||||||
|       expect(renderShallow()).to.be.ok; |       expect(render()).to.be.ok; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('renders with the specified className', () => { |     it('renders with the specified className', () => { | ||||||
|       expect(renderShallow({ className: 'testClass' })).to.have.className('testClass'); |       expect(render({ className: 'testClass' })).to.have.className('testClass'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('renders the specified title', () => { |     it('renders the specified title', () => { | ||||||
|       expect(renderMount({ title: 'titleText' })).to.contain.text('titleText'); |       expect(render({ title: 'titleText' })).to.contain.text('titleText'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('renders the specified byline', () => { |     it('renders the specified byline', () => { | ||||||
|       expect(renderMount({ byline: 'bylineText' })).to.contain.text('bylineText'); |       expect(render({ byline: 'bylineText' })).to.contain.text('bylineText'); | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -14,27 +14,26 @@ | |||||||
| // You should have received a copy of the GNU General Public License
 | // You should have received a copy of the GNU General Public License
 | ||||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||||
| 
 | 
 | ||||||
| import { mount } from 'enzyme'; | import { shallow } from 'enzyme'; | ||||||
| import React from 'react'; | import React from 'react'; | ||||||
| import sinon from 'sinon'; | import sinon from 'sinon'; | ||||||
| 
 | 
 | ||||||
| import { ContextProvider, muiTheme } from '~/ui'; |  | ||||||
| import { ABI_TYPES } from '~/util/abi'; | import { ABI_TYPES } from '~/util/abi'; | ||||||
| 
 | 
 | ||||||
| import TypedInput from './'; | import TypedInput from './'; | ||||||
| 
 | 
 | ||||||
| let component; | let component; | ||||||
|  | let select; | ||||||
| let onChange; | let onChange; | ||||||
| 
 | 
 | ||||||
| function render (props) { | function render (props) { | ||||||
|   onChange = sinon.stub(); |   onChange = sinon.stub(); | ||||||
|   component = mount( |   component = shallow( | ||||||
|     <ContextProvider api={ {} } muiTheme={ muiTheme } store={ {} }> |  | ||||||
|     <TypedInput |     <TypedInput | ||||||
|       { ...props } |       { ...props } | ||||||
|       onChange={ onChange } /> |       onChange={ onChange } /> | ||||||
|     </ContextProvider> |  | ||||||
|   ); |   ); | ||||||
|  |   select = component.find('Select'); | ||||||
| 
 | 
 | ||||||
|   return component; |   return component; | ||||||
| } | } | ||||||
| @ -50,19 +49,19 @@ describe('ui/Form/TypedInput', () => { | |||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('calls onChange when value changes', () => { |     it('calls onChange when value changes', () => { | ||||||
|       component.find('DropDownMenu').simulate('change', { target: { value: 'true' } }); |       select.shallow().simulate('change', { target: { value: 'true' } }); | ||||||
| 
 | 
 | ||||||
|       expect(onChange).to.have.been.called; |       expect(onChange).to.have.been.called; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it("calls onChange(true) when value changes to 'true'", () => { |     it("calls onChange(true) when value changes to 'true'", () => { | ||||||
|       component.find('DropDownMenu').simulate('change', { target: { value: 'true' } }); |       select.shallow().simulate('change', { target: { value: 'true' } }); | ||||||
| 
 | 
 | ||||||
|       expect(onChange).to.have.been.calledWith(true); |       expect(onChange).to.have.been.calledWith(true); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it("calls onChange(false) when value changes to 'false'", () => { |     it("calls onChange(false) when value changes to 'false'", () => { | ||||||
|       component.find('DropDownMenu').simulate('change', { target: { value: 'false' } }); |       select.shallow().simulate('change', { target: { value: 'false' } }); | ||||||
| 
 | 
 | ||||||
|       expect(onChange).to.have.been.calledWith(false); |       expect(onChange).to.have.been.calledWith(false); | ||||||
|     }); |     }); | ||||||
|  | |||||||
| @ -16,7 +16,6 @@ | |||||||
| 
 | 
 | ||||||
| import React, { Component, PropTypes } from 'react'; | import React, { Component, PropTypes } from 'react'; | ||||||
| import { connect } from 'react-redux'; | import { connect } from 'react-redux'; | ||||||
| import { bindActionCreators } from 'redux'; |  | ||||||
| 
 | 
 | ||||||
| import { createIdentityImg } from '~/api/util/identity'; | import { createIdentityImg } from '~/api/util/identity'; | ||||||
| import { isNullAddress } from '~/util/validation'; | import { isNullAddress } from '~/util/validation'; | ||||||
| @ -145,11 +144,7 @@ function mapStateToProps (state) { | |||||||
|   return { images }; |   return { images }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function mapDispatchToProps (dispatch) { |  | ||||||
|   return bindActionCreators({}, dispatch); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default connect( | export default connect( | ||||||
|   mapStateToProps, |   mapStateToProps, | ||||||
|   mapDispatchToProps |   null | ||||||
| )(IdentityIcon); | )(IdentityIcon); | ||||||
|  | |||||||
| @ -14,12 +14,10 @@ | |||||||
| // You should have received a copy of the GNU General Public License
 | // You should have received a copy of the GNU General Public License
 | ||||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||||
| 
 | 
 | ||||||
| import { mount } from 'enzyme'; | import { shallow } from 'enzyme'; | ||||||
| import React, { PropTypes } from 'react'; | import React from 'react'; | ||||||
| import sinon from 'sinon'; | import sinon from 'sinon'; | ||||||
| 
 | 
 | ||||||
| import muiTheme from '../Theme'; |  | ||||||
| 
 |  | ||||||
| import IdentityIcon from './'; | import IdentityIcon from './'; | ||||||
| 
 | 
 | ||||||
| const ADDRESS0 = '0x0000000000000000000000000000000000000000'; | const ADDRESS0 = '0x0000000000000000000000000000000000000000'; | ||||||
| @ -27,6 +25,7 @@ const ADDRESS1 = '0x0123456789012345678901234567890123456789'; | |||||||
| const ADDRESS2 = '0x9876543210987654321098765432109876543210'; | const ADDRESS2 = '0x9876543210987654321098765432109876543210'; | ||||||
| 
 | 
 | ||||||
| let component; | let component; | ||||||
|  | let instance; | ||||||
| 
 | 
 | ||||||
| function createApi () { | function createApi () { | ||||||
|   return { |   return { | ||||||
| @ -53,20 +52,13 @@ function render (props = {}) { | |||||||
|     props.address = ADDRESS1; |     props.address = ADDRESS1; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   component = mount( |   component = shallow( | ||||||
|     <IdentityIcon { ...props } />, |     <IdentityIcon { ...props } />, | ||||||
|     { |     { context: { store: createRedux() } } | ||||||
|       childContextTypes: { |   ).find('IdentityIcon').shallow({ context: { api: createApi() } }); | ||||||
|         api: PropTypes.object, | 
 | ||||||
|         muiTheme: PropTypes.object |   instance = component.instance(); | ||||||
|       }, |   instance.componentDidMount(); | ||||||
|       context: { |  | ||||||
|         api: createApi(), |  | ||||||
|         muiTheme, |  | ||||||
|         store: createRedux() |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   ); |  | ||||||
| 
 | 
 | ||||||
|   return component; |   return component; | ||||||
| } | } | ||||||
|  | |||||||
| @ -17,7 +17,6 @@ | |||||||
| import React, { Component, PropTypes } from 'react'; | import React, { Component, PropTypes } from 'react'; | ||||||
| import { FormattedMessage } from 'react-intl'; | import { FormattedMessage } from 'react-intl'; | ||||||
| import { connect } from 'react-redux'; | import { connect } from 'react-redux'; | ||||||
| import { bindActionCreators } from 'redux'; |  | ||||||
| 
 | 
 | ||||||
| import { isNullAddress } from '~/util/validation'; | import { isNullAddress } from '~/util/validation'; | ||||||
| import ShortenedHash from '../ShortenedHash'; | import ShortenedHash from '../ShortenedHash'; | ||||||
| @ -85,11 +84,7 @@ function mapStateToProps (state) { | |||||||
|   }; |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function mapDispatchToProps (dispatch) { |  | ||||||
|   return bindActionCreators({}, dispatch); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default connect( | export default connect( | ||||||
|   mapStateToProps, |   mapStateToProps, | ||||||
|   mapDispatchToProps |   null | ||||||
| )(IdentityName); | )(IdentityName); | ||||||
|  | |||||||
| @ -14,9 +14,8 @@ | |||||||
| // You should have received a copy of the GNU General Public License
 | // You should have received a copy of the GNU General Public License
 | ||||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||||
| 
 | 
 | ||||||
| import { mount } from 'enzyme'; | import { shallow } from 'enzyme'; | ||||||
| import React from 'react'; | import React from 'react'; | ||||||
| import { IntlProvider } from 'react-intl'; |  | ||||||
| 
 | 
 | ||||||
| import sinon from 'sinon'; | import sinon from 'sinon'; | ||||||
| 
 | 
 | ||||||
| @ -45,13 +44,11 @@ const STORE = { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function render (props) { | function render (props) { | ||||||
|   return mount( |   return shallow( | ||||||
|     <IntlProvider locale='en'> |  | ||||||
|     <IdentityName |     <IdentityName | ||||||
|       store={ STORE } |       store={ STORE } | ||||||
|       { ...props } /> |       { ...props } /> | ||||||
|     </IntlProvider> |   ).find('IdentityName').shallow(); | ||||||
|   ); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| describe('ui/IdentityName', () => { | describe('ui/IdentityName', () => { | ||||||
| @ -62,23 +59,33 @@ describe('ui/IdentityName', () => { | |||||||
| 
 | 
 | ||||||
|     describe('account not found', () => { |     describe('account not found', () => { | ||||||
|       it('renders null with empty', () => { |       it('renders null with empty', () => { | ||||||
|         expect(render({ address: ADDR_C, empty: true }).html()).to.be.null; |         expect( | ||||||
|  |           render({ address: ADDR_C, empty: true }).html() | ||||||
|  |         ).to.be.null; | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|       it('renders address without empty', () => { |       it('renders address without empty', () => { | ||||||
|         expect(render({ address: ADDR_C }).text()).to.equal(ADDR_C); |         expect( | ||||||
|  |           render({ address: ADDR_C }).text() | ||||||
|  |         ).to.equal(ADDR_C); | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|       it('renders short address with shorten', () => { |       it('renders short address with shorten', () => { | ||||||
|         expect(render({ address: ADDR_C, shorten: true }).text()).to.equal('123456…56789c'); |         expect( | ||||||
|  |           render({ address: ADDR_C, shorten: true }).find('ShortenedHash').props().data | ||||||
|  |         ).to.equal(ADDR_C); | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|       it('renders unknown with flag', () => { |       it('renders unknown with flag', () => { | ||||||
|         expect(render({ address: ADDR_C, unknown: true }).text()).to.equal('UNNAMED'); |         expect( | ||||||
|  |           render({ address: ADDR_C, unknown: true } | ||||||
|  |         ).find('FormattedMessage').props().id).to.equal('ui.identityName.unnamed'); | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|       it('renders 0x000...000 as null', () => { |       it('renders 0x000...000 as null', () => { | ||||||
|         expect(render({ address: ADDR_NULL }).text()).to.equal('NULL'); |         expect( | ||||||
|  |           render({ address: ADDR_NULL }).find('FormattedMessage').props().id | ||||||
|  |         ).to.equal('ui.identityName.null'); | ||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user