mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fixes for components that break e2e gas customization tests, plus unit test updates.
This commit is contained in:
parent
a8259f7f6a
commit
b70886a99b
@ -19,7 +19,7 @@ export default class GasPriceChart extends Component {
|
|||||||
gasPrices: PropTypes.array,
|
gasPrices: PropTypes.array,
|
||||||
estimatedTimes: PropTypes.array,
|
estimatedTimes: PropTypes.array,
|
||||||
gasPricesMax: PropTypes.number,
|
gasPricesMax: PropTypes.number,
|
||||||
estimatedTimesMax: PropTypes.number,
|
estimatedTimesMax: PropTypes.string,
|
||||||
currentPrice: PropTypes.number,
|
currentPrice: PropTypes.number,
|
||||||
updateCustomGasPrice: PropTypes.func,
|
updateCustomGasPrice: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ const testProps = {
|
|||||||
gasPrices: [1.5, 2.5, 4, 8],
|
gasPrices: [1.5, 2.5, 4, 8],
|
||||||
estimatedTimes: [100, 80, 40, 10],
|
estimatedTimes: [100, 80, 40, 10],
|
||||||
gasPricesMax: 9,
|
gasPricesMax: 9,
|
||||||
estimatedTimesMax: 100,
|
estimatedTimesMax: '100',
|
||||||
currentPrice: 6,
|
currentPrice: 6,
|
||||||
updateCustomGasPrice: propsMethodSpies.updateCustomGasPrice,
|
updateCustomGasPrice: propsMethodSpies.updateCustomGasPrice,
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export default class GasFeeDisplay extends Component {
|
|||||||
convertedCurrency: PropTypes.string,
|
convertedCurrency: PropTypes.string,
|
||||||
gasLoadingError: PropTypes.bool,
|
gasLoadingError: PropTypes.bool,
|
||||||
gasTotal: PropTypes.string,
|
gasTotal: PropTypes.string,
|
||||||
showGasButtonGroup: PropTypes.func,
|
onReset: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -19,7 +19,7 @@ export default class GasFeeDisplay extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { gasTotal, onClick, gasLoadingError } = this.props
|
const { gasTotal, gasLoadingError, onReset } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="send-v2__gas-fee-display">
|
<div className="send-v2__gas-fee-display">
|
||||||
@ -47,7 +47,7 @@ export default class GasFeeDisplay extends Component {
|
|||||||
}
|
}
|
||||||
<button
|
<button
|
||||||
className="gas-fee-reset"
|
className="gas-fee-reset"
|
||||||
onClick={showGasButtonGroup}
|
onClick={onReset}
|
||||||
>
|
>
|
||||||
{ this.context.t('reset') }
|
{ this.context.t('reset') }
|
||||||
</button>
|
</button>
|
||||||
|
@ -8,9 +8,10 @@ import sinon from 'sinon'
|
|||||||
|
|
||||||
const propsMethodSpies = {
|
const propsMethodSpies = {
|
||||||
showCustomizeGasModal: sinon.spy(),
|
showCustomizeGasModal: sinon.spy(),
|
||||||
|
onReset: sinon.spy(),
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('SendGasRow Component', function () {
|
describe('GasFeeDisplay Component', function () {
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -20,6 +21,7 @@ describe('SendGasRow Component', function () {
|
|||||||
primaryCurrency={'mockPrimaryCurrency'}
|
primaryCurrency={'mockPrimaryCurrency'}
|
||||||
convertedCurrency={'mockConvertedCurrency'}
|
convertedCurrency={'mockConvertedCurrency'}
|
||||||
showGasButtonGroup={propsMethodSpies.showCustomizeGasModal}
|
showGasButtonGroup={propsMethodSpies.showCustomizeGasModal}
|
||||||
|
onReset={propsMethodSpies.onReset}
|
||||||
/>, {context: {t: str => str + '_t'}})
|
/>, {context: {t: str => str + '_t'}})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -47,9 +49,9 @@ describe('SendGasRow Component', function () {
|
|||||||
className,
|
className,
|
||||||
} = wrapper.find('button').props()
|
} = wrapper.find('button').props()
|
||||||
assert.equal(className, 'gas-fee-reset')
|
assert.equal(className, 'gas-fee-reset')
|
||||||
assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 0)
|
assert.equal(propsMethodSpies.onReset.callCount, 0)
|
||||||
onClick()
|
onClick()
|
||||||
assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 1)
|
assert.equal(propsMethodSpies.onReset.callCount, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should render the reset button with the correct text', () => {
|
it('should render the reset button with the correct text', () => {
|
||||||
|
@ -14,8 +14,8 @@ export default class SendGasRow extends Component {
|
|||||||
gasTotal: PropTypes.string,
|
gasTotal: PropTypes.string,
|
||||||
showCustomizeGasModal: PropTypes.func,
|
showCustomizeGasModal: PropTypes.func,
|
||||||
gasPriceButtonGroupProps: PropTypes.object,
|
gasPriceButtonGroupProps: PropTypes.object,
|
||||||
showGasButtonGroup: PropTypes.func,
|
|
||||||
gasButtonGroupShown: PropTypes.bool,
|
gasButtonGroupShown: PropTypes.bool,
|
||||||
|
resetGasButtons: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -32,7 +32,7 @@ export default class SendGasRow extends Component {
|
|||||||
showCustomizeGasModal,
|
showCustomizeGasModal,
|
||||||
gasPriceButtonGroupProps,
|
gasPriceButtonGroupProps,
|
||||||
gasButtonGroupShown,
|
gasButtonGroupShown,
|
||||||
showGasButtonGroup,
|
resetGasButtons,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -57,7 +57,7 @@ export default class SendGasRow extends Component {
|
|||||||
convertedCurrency={convertedCurrency}
|
convertedCurrency={convertedCurrency}
|
||||||
gasLoadingError={gasLoadingError}
|
gasLoadingError={gasLoadingError}
|
||||||
gasTotal={gasTotal}
|
gasTotal={gasTotal}
|
||||||
showGasButtonGroup={showGasButtonGroup}
|
onReset={resetGasButtons}
|
||||||
onClick={() => showCustomizeGasModal()}
|
onClick={() => showCustomizeGasModal()}
|
||||||
/>}
|
/>}
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
showGasButtonGroup,
|
showGasButtonGroup,
|
||||||
} from '../../../../ducks/send.duck'
|
} from '../../../../ducks/send.duck'
|
||||||
|
import {
|
||||||
|
resetCustomData,
|
||||||
|
} from '../../../../ducks/gas.duck'
|
||||||
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
|
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
|
||||||
import { showModal, setGasPrice } from '../../../../actions'
|
import { showModal, setGasPrice } from '../../../../actions'
|
||||||
import SendGasRow from './send-gas-row.component'
|
import SendGasRow from './send-gas-row.component'
|
||||||
@ -44,13 +47,17 @@ function mapDispatchToProps (dispatch) {
|
|||||||
showCustomizeGasModal: () => dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })),
|
showCustomizeGasModal: () => dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })),
|
||||||
setGasPrice: newPrice => dispatch(setGasPrice(newPrice)),
|
setGasPrice: newPrice => dispatch(setGasPrice(newPrice)),
|
||||||
showGasButtonGroup: () => dispatch(showGasButtonGroup()),
|
showGasButtonGroup: () => dispatch(showGasButtonGroup()),
|
||||||
|
resetCustomData: () => dispatch(resetCustomData()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeProps (stateProps, dispatchProps, ownProps) {
|
function mergeProps (stateProps, dispatchProps, ownProps) {
|
||||||
const { gasPriceButtonGroupProps } = stateProps
|
const { gasPriceButtonGroupProps } = stateProps
|
||||||
|
const { gasButtonInfo } = gasPriceButtonGroupProps
|
||||||
const {
|
const {
|
||||||
setGasPrice: dispatchSetGasPrice,
|
setGasPrice: dispatchSetGasPrice,
|
||||||
|
showGasButtonGroup: dispatchShowGasButtonGroup,
|
||||||
|
resetCustomData: dispatchResetCustomData,
|
||||||
...otherDispatchProps
|
...otherDispatchProps
|
||||||
} = dispatchProps
|
} = dispatchProps
|
||||||
|
|
||||||
@ -62,5 +69,10 @@ function mergeProps (stateProps, dispatchProps, ownProps) {
|
|||||||
...gasPriceButtonGroupProps,
|
...gasPriceButtonGroupProps,
|
||||||
handleGasPriceSelection: dispatchSetGasPrice,
|
handleGasPriceSelection: dispatchSetGasPrice,
|
||||||
},
|
},
|
||||||
|
resetGasButtons: () => {
|
||||||
|
dispatchResetCustomData()
|
||||||
|
dispatchSetGasPrice(gasButtonInfo[1].priceInHexWei)
|
||||||
|
dispatchShowGasButtonGroup()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import GasPriceButtonGroup from '../../../../gas-customization/gas-price-button-
|
|||||||
|
|
||||||
const propsMethodSpies = {
|
const propsMethodSpies = {
|
||||||
showCustomizeGasModal: sinon.spy(),
|
showCustomizeGasModal: sinon.spy(),
|
||||||
|
resetGasButtons: sinon.spy(),
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('SendGasRow Component', function () {
|
describe('SendGasRow Component', function () {
|
||||||
@ -22,9 +23,9 @@ describe('SendGasRow Component', function () {
|
|||||||
gasFeeError={'mockGasFeeError'}
|
gasFeeError={'mockGasFeeError'}
|
||||||
gasLoadingError={false}
|
gasLoadingError={false}
|
||||||
gasTotal={'mockGasTotal'}
|
gasTotal={'mockGasTotal'}
|
||||||
showGasButtonGroup={'mockShowGasPriceButtonGroup'}
|
|
||||||
gasButtonGroupShown={false}
|
gasButtonGroupShown={false}
|
||||||
showCustomizeGasModal={propsMethodSpies.showCustomizeGasModal}
|
showCustomizeGasModal={propsMethodSpies.showCustomizeGasModal}
|
||||||
|
resetGasButtons={propsMethodSpies.resetGasButtons}
|
||||||
gasPriceButtonGroupProps={{
|
gasPriceButtonGroupProps={{
|
||||||
someGasPriceButtonGroupProp: 'foo',
|
someGasPriceButtonGroupProp: 'foo',
|
||||||
anotherGasPriceButtonGroupProp: 'bar',
|
anotherGasPriceButtonGroupProp: 'bar',
|
||||||
@ -33,7 +34,7 @@ describe('SendGasRow Component', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
propsMethodSpies.showCustomizeGasModal.resetHistory()
|
propsMethodSpies.resetGasButtons.resetHistory()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('render', () => {
|
describe('render', () => {
|
||||||
@ -63,17 +64,15 @@ describe('SendGasRow Component', function () {
|
|||||||
convertedCurrency,
|
convertedCurrency,
|
||||||
gasLoadingError,
|
gasLoadingError,
|
||||||
gasTotal,
|
gasTotal,
|
||||||
onClick,
|
onReset,
|
||||||
showGasButtonGroup,
|
|
||||||
} = wrapper.find(SendRowWrapper).childAt(0).props()
|
} = wrapper.find(SendRowWrapper).childAt(0).props()
|
||||||
assert.equal(conversionRate, 20)
|
assert.equal(conversionRate, 20)
|
||||||
assert.equal(convertedCurrency, 'mockConvertedCurrency')
|
assert.equal(convertedCurrency, 'mockConvertedCurrency')
|
||||||
assert.equal(gasLoadingError, false)
|
assert.equal(gasLoadingError, false)
|
||||||
assert.equal(gasTotal, 'mockGasTotal')
|
assert.equal(gasTotal, 'mockGasTotal')
|
||||||
assert.equal(showGasButtonGroup, 'mockShowGasPriceButtonGroup')
|
assert.equal(propsMethodSpies.resetGasButtons.callCount, 0)
|
||||||
assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 0)
|
onReset()
|
||||||
onClick()
|
assert.equal(propsMethodSpies.resetGasButtons.callCount, 1)
|
||||||
assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should render the GasPriceButtonGroup if gasButtonGroupShown is true', () => {
|
it('should render the GasPriceButtonGroup if gasButtonGroupShown is true', () => {
|
||||||
|
@ -15,6 +15,10 @@ const sendDuckSpies = {
|
|||||||
showGasButtonGroup: sinon.spy(),
|
showGasButtonGroup: sinon.spy(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gasDuckSpies = {
|
||||||
|
resetCustomData: sinon.spy(),
|
||||||
|
}
|
||||||
|
|
||||||
proxyquire('../send-gas-row.container.js', {
|
proxyquire('../send-gas-row.container.js', {
|
||||||
'react-redux': {
|
'react-redux': {
|
||||||
connect: (ms, md, mp) => {
|
connect: (ms, md, mp) => {
|
||||||
@ -42,6 +46,7 @@ proxyquire('../send-gas-row.container.js', {
|
|||||||
getDefaultActiveButtonIndex: (gasButtonInfo, gasPrice) => gasButtonInfo.length + gasPrice.length,
|
getDefaultActiveButtonIndex: (gasButtonInfo, gasPrice) => gasButtonInfo.length + gasPrice.length,
|
||||||
},
|
},
|
||||||
'../../../../ducks/send.duck': sendDuckSpies,
|
'../../../../ducks/send.duck': sendDuckSpies,
|
||||||
|
'../../../../ducks/gas.duck': gasDuckSpies,
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('send-gas-row container', () => {
|
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', () => {
|
describe('mergeProps', () => {
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import sinon from 'sinon'
|
import sinon from 'sinon'
|
||||||
|
import proxyquire from 'proxyquire'
|
||||||
|
|
||||||
import GasReducer, {
|
|
||||||
|
const GasDuck = proxyquire('../gas.duck.js', {
|
||||||
|
'../../lib/local-storage-helpers': {
|
||||||
|
loadLocalStorageData: sinon.spy(),
|
||||||
|
saveLocalStorageData: sinon.spy(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const {
|
||||||
basicGasEstimatesLoadingStarted,
|
basicGasEstimatesLoadingStarted,
|
||||||
basicGasEstimatesLoadingFinished,
|
basicGasEstimatesLoadingFinished,
|
||||||
setBasicGasEstimateData,
|
setBasicGasEstimateData,
|
||||||
@ -16,7 +25,8 @@ import GasReducer, {
|
|||||||
setPricesAndTimeEstimates,
|
setPricesAndTimeEstimates,
|
||||||
fetchGasEstimates,
|
fetchGasEstimates,
|
||||||
setApiEstimatesLastRetrieved,
|
setApiEstimatesLastRetrieved,
|
||||||
} from '../gas.duck.js'
|
} = GasDuck
|
||||||
|
const GasReducer = GasDuck.default
|
||||||
|
|
||||||
describe('Gas Duck', () => {
|
describe('Gas Duck', () => {
|
||||||
let tempFetch
|
let tempFetch
|
||||||
@ -312,6 +322,11 @@ describe('Gas Duck', () => {
|
|||||||
|
|
||||||
describe('fetchGasEstimates', () => {
|
describe('fetchGasEstimates', () => {
|
||||||
const mockDistpatch = sinon.spy()
|
const mockDistpatch = sinon.spy()
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockDistpatch.resetHistory()
|
||||||
|
})
|
||||||
|
|
||||||
it('should call fetch with the expected params', async () => {
|
it('should call fetch with the expected params', async () => {
|
||||||
global.fetch.resetHistory()
|
global.fetch.resetHistory()
|
||||||
await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign(
|
await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign(
|
||||||
@ -377,6 +392,46 @@ describe('Gas Duck', () => {
|
|||||||
[{ type: GAS_ESTIMATE_LOADING_FINISHED }]
|
[{ type: GAS_ESTIMATE_LOADING_FINISHED }]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not call fetch if the estimates were retrieved < 75000 ms ago', async () => {
|
||||||
|
global.fetch.resetHistory()
|
||||||
|
await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign(
|
||||||
|
{},
|
||||||
|
initState,
|
||||||
|
{
|
||||||
|
priceAndTimeEstimatesLastRetrieved: Date.now(),
|
||||||
|
priceAndTimeEstimates: [{
|
||||||
|
expectedTime: '10',
|
||||||
|
expectedWait: 2,
|
||||||
|
gasprice: 50,
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
) }))
|
||||||
|
assert.deepEqual(
|
||||||
|
mockDistpatch.getCall(0).args,
|
||||||
|
[{ type: GAS_ESTIMATE_LOADING_STARTED} ]
|
||||||
|
)
|
||||||
|
assert.equal(global.fetch.callCount, 0)
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
mockDistpatch.getCall(1).args,
|
||||||
|
[{
|
||||||
|
type: SET_PRICE_AND_TIME_ESTIMATES,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
expectedTime: '10',
|
||||||
|
expectedWait: 2,
|
||||||
|
gasprice: 50,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
mockDistpatch.getCall(2).args,
|
||||||
|
[{ type: GAS_ESTIMATE_LOADING_FINISHED }]
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('gasEstimatesLoadingStarted', () => {
|
describe('gasEstimatesLoadingStarted', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user