From b70886a99b466366e84d24271adbb890aebf6460 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Mon, 5 Nov 2018 13:31:46 -0330 Subject: Fixes for components that break e2e gas customization tests, plus unit test updates. --- .../gas-price-chart/gas-price-chart.component.js | 2 +- .../tests/gas-price-chart.component.test.js | 2 +- .../gas-fee-display/gas-fee-display.component.js | 6 +++--- .../test/gas-fee-display.component.test.js | 8 +++++--- .../send-content/send-gas-row/send-gas-row.component.js | 6 +++--- .../send-content/send-gas-row/send-gas-row.container.js | 12 ++++++++++++ .../send-gas-row/tests/send-gas-row-component.test.js | 15 +++++++-------- .../send-gas-row/tests/send-gas-row-container.test.js | 13 +++++++++++++ 8 files changed, 45 insertions(+), 19 deletions(-) (limited to 'ui/app/components') diff --git a/ui/app/components/gas-customization/gas-price-chart/gas-price-chart.component.js b/ui/app/components/gas-customization/gas-price-chart/gas-price-chart.component.js index 993dd0a2b..5ca465ba9 100644 --- a/ui/app/components/gas-customization/gas-price-chart/gas-price-chart.component.js +++ b/ui/app/components/gas-customization/gas-price-chart/gas-price-chart.component.js @@ -19,7 +19,7 @@ export default class GasPriceChart extends Component { gasPrices: PropTypes.array, estimatedTimes: PropTypes.array, gasPricesMax: PropTypes.number, - estimatedTimesMax: PropTypes.number, + estimatedTimesMax: PropTypes.string, currentPrice: PropTypes.number, updateCustomGasPrice: PropTypes.func, } diff --git a/ui/app/components/gas-customization/gas-price-chart/tests/gas-price-chart.component.test.js b/ui/app/components/gas-customization/gas-price-chart/tests/gas-price-chart.component.test.js index 158813edb..46341195b 100644 --- a/ui/app/components/gas-customization/gas-price-chart/tests/gas-price-chart.component.test.js +++ b/ui/app/components/gas-customization/gas-price-chart/tests/gas-price-chart.component.test.js @@ -51,7 +51,7 @@ const testProps = { gasPrices: [1.5, 2.5, 4, 8], estimatedTimes: [100, 80, 40, 10], gasPricesMax: 9, - estimatedTimesMax: 100, + estimatedTimesMax: '100', currentPrice: 6, updateCustomGasPrice: propsMethodSpies.updateCustomGasPrice, } diff --git a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js index 40f8b1fe0..b667aa037 100644 --- a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js +++ b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js @@ -11,7 +11,7 @@ export default class GasFeeDisplay extends Component { convertedCurrency: PropTypes.string, gasLoadingError: PropTypes.bool, gasTotal: PropTypes.string, - showGasButtonGroup: PropTypes.func, + onReset: PropTypes.func, }; static contextTypes = { @@ -19,7 +19,7 @@ export default class GasFeeDisplay extends Component { }; render () { - const { gasTotal, onClick, gasLoadingError } = this.props + const { gasTotal, gasLoadingError, onReset } = this.props return (
@@ -47,7 +47,7 @@ export default class GasFeeDisplay extends Component { } diff --git a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js index c7ac175d9..cb4180508 100644 --- a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js +++ b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js @@ -8,9 +8,10 @@ import sinon from 'sinon' const propsMethodSpies = { showCustomizeGasModal: sinon.spy(), + onReset: sinon.spy(), } -describe('SendGasRow Component', function () { +describe('GasFeeDisplay Component', function () { let wrapper beforeEach(() => { @@ -20,6 +21,7 @@ describe('SendGasRow Component', function () { primaryCurrency={'mockPrimaryCurrency'} convertedCurrency={'mockConvertedCurrency'} showGasButtonGroup={propsMethodSpies.showCustomizeGasModal} + onReset={propsMethodSpies.onReset} />, {context: {t: str => str + '_t'}}) }) @@ -47,9 +49,9 @@ describe('SendGasRow Component', function () { className, } = wrapper.find('button').props() assert.equal(className, 'gas-fee-reset') - assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 0) + assert.equal(propsMethodSpies.onReset.callCount, 0) onClick() - assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 1) + assert.equal(propsMethodSpies.onReset.callCount, 1) }) it('should render the reset button with the correct text', () => { diff --git a/ui/app/components/send/send-content/send-gas-row/send-gas-row.component.js b/ui/app/components/send/send-content/send-gas-row/send-gas-row.component.js index 507407306..8d305dd4f 100644 --- a/ui/app/components/send/send-content/send-gas-row/send-gas-row.component.js +++ b/ui/app/components/send/send-content/send-gas-row/send-gas-row.component.js @@ -14,8 +14,8 @@ export default class SendGasRow extends Component { gasTotal: PropTypes.string, showCustomizeGasModal: PropTypes.func, gasPriceButtonGroupProps: PropTypes.object, - showGasButtonGroup: PropTypes.func, gasButtonGroupShown: PropTypes.bool, + resetGasButtons: PropTypes.func, } static contextTypes = { @@ -32,7 +32,7 @@ export default class SendGasRow extends Component { showCustomizeGasModal, gasPriceButtonGroupProps, gasButtonGroupShown, - showGasButtonGroup, + resetGasButtons, } = this.props return ( @@ -57,7 +57,7 @@ export default class SendGasRow extends Component { convertedCurrency={convertedCurrency} gasLoadingError={gasLoadingError} gasTotal={gasTotal} - showGasButtonGroup={showGasButtonGroup} + onReset={resetGasButtons} onClick={() => showCustomizeGasModal()} />} diff --git a/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js b/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js index dd16559d0..39266e590 100644 --- a/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js +++ b/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js @@ -13,6 +13,9 @@ import { import { showGasButtonGroup, } from '../../../../ducks/send.duck' +import { + resetCustomData, +} from '../../../../ducks/gas.duck' import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js' import { showModal, setGasPrice } from '../../../../actions' import SendGasRow from './send-gas-row.component' @@ -44,13 +47,17 @@ function mapDispatchToProps (dispatch) { showCustomizeGasModal: () => dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })), setGasPrice: newPrice => dispatch(setGasPrice(newPrice)), showGasButtonGroup: () => dispatch(showGasButtonGroup()), + resetCustomData: () => dispatch(resetCustomData()), } } function mergeProps (stateProps, dispatchProps, ownProps) { const { gasPriceButtonGroupProps } = stateProps + const { gasButtonInfo } = gasPriceButtonGroupProps const { setGasPrice: dispatchSetGasPrice, + showGasButtonGroup: dispatchShowGasButtonGroup, + resetCustomData: dispatchResetCustomData, ...otherDispatchProps } = dispatchProps @@ -62,5 +69,10 @@ function mergeProps (stateProps, dispatchProps, ownProps) { ...gasPriceButtonGroupProps, handleGasPriceSelection: dispatchSetGasPrice, }, + resetGasButtons: () => { + dispatchResetCustomData() + dispatchSetGasPrice(gasButtonInfo[1].priceInHexWei) + dispatchShowGasButtonGroup() + }, } } diff --git a/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-component.test.js b/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-component.test.js index 171cd7bf6..059c6cdd3 100644 --- a/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-component.test.js +++ b/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-component.test.js @@ -10,6 +10,7 @@ import GasPriceButtonGroup from '../../../../gas-customization/gas-price-button- const propsMethodSpies = { showCustomizeGasModal: sinon.spy(), + resetGasButtons: sinon.spy(), } describe('SendGasRow Component', function () { @@ -22,9 +23,9 @@ describe('SendGasRow Component', function () { gasFeeError={'mockGasFeeError'} gasLoadingError={false} gasTotal={'mockGasTotal'} - showGasButtonGroup={'mockShowGasPriceButtonGroup'} gasButtonGroupShown={false} showCustomizeGasModal={propsMethodSpies.showCustomizeGasModal} + resetGasButtons={propsMethodSpies.resetGasButtons} gasPriceButtonGroupProps={{ someGasPriceButtonGroupProp: 'foo', anotherGasPriceButtonGroupProp: 'bar', @@ -33,7 +34,7 @@ describe('SendGasRow Component', function () { }) afterEach(() => { - propsMethodSpies.showCustomizeGasModal.resetHistory() + propsMethodSpies.resetGasButtons.resetHistory() }) describe('render', () => { @@ -63,17 +64,15 @@ describe('SendGasRow Component', function () { convertedCurrency, gasLoadingError, gasTotal, - onClick, - showGasButtonGroup, + onReset, } = wrapper.find(SendRowWrapper).childAt(0).props() assert.equal(conversionRate, 20) assert.equal(convertedCurrency, 'mockConvertedCurrency') assert.equal(gasLoadingError, false) assert.equal(gasTotal, 'mockGasTotal') - assert.equal(showGasButtonGroup, 'mockShowGasPriceButtonGroup') - assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 0) - onClick() - assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 1) + assert.equal(propsMethodSpies.resetGasButtons.callCount, 0) + onReset() + assert.equal(propsMethodSpies.resetGasButtons.callCount, 1) }) it('should render the GasPriceButtonGroup if gasButtonGroupShown is true', () => { diff --git a/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js b/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js index 1c385e216..766bf6cab 100644 --- a/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js +++ b/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js @@ -15,6 +15,10 @@ const sendDuckSpies = { showGasButtonGroup: sinon.spy(), } +const gasDuckSpies = { + resetCustomData: sinon.spy(), +} + proxyquire('../send-gas-row.container.js', { 'react-redux': { connect: (ms, md, mp) => { @@ -42,6 +46,7 @@ proxyquire('../send-gas-row.container.js', { getDefaultActiveButtonIndex: (gasButtonInfo, gasPrice) => gasButtonInfo.length + gasPrice.length, }, '../../../../ducks/send.duck': sendDuckSpies, + '../../../../ducks/gas.duck': gasDuckSpies, }) describe('send-gas-row container', () => { @@ -104,6 +109,14 @@ describe('send-gas-row container', () => { }) }) + describe('resetCustomData()', () => { + it('should dispatch an action', () => { + mapDispatchToPropsObject.resetCustomData() + assert(dispatchSpy.calledOnce) + assert(gasDuckSpies.resetCustomData.calledOnce) + }) + }) + }) describe('mergeProps', () => { -- cgit