2017-05-12 02:43:40 +02:00
|
|
|
const assert = require('assert')
|
|
|
|
const additions = require('react-testutils-additions')
|
2017-05-12 02:09:23 +02:00
|
|
|
const h = require('react-hyperscript')
|
2017-05-16 00:07:38 +02:00
|
|
|
const PendingTx = require('../../../ui/app/components/pending-tx')
|
2017-05-12 02:09:23 +02:00
|
|
|
const createReactFactory = require('create-react-factory').createReactFactory
|
|
|
|
const React = require('react')
|
2017-05-16 00:07:38 +02:00
|
|
|
const shallow = require('react-test-renderer/shallow')
|
2017-05-12 02:09:23 +02:00
|
|
|
const Factory = createReactFactory(PendingTx)
|
|
|
|
const ReactTestUtils = require('react-addons-test-utils')
|
2017-05-16 00:21:28 +02:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
2017-05-11 02:26:51 +02:00
|
|
|
|
2017-05-11 23:29:44 +02:00
|
|
|
describe.only('PendingTx', function () {
|
2017-05-11 02:26:51 +02:00
|
|
|
let pendingTxComponent
|
|
|
|
|
|
|
|
const identities = {
|
|
|
|
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': {
|
|
|
|
name: 'Main Account 1',
|
|
|
|
balance: '0x00000000000000056bc75e2d63100000',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const gasPrice = '0x4A817C800' // 20 Gwei
|
|
|
|
const txData = {
|
|
|
|
'id':5021615666270214,
|
|
|
|
'time':1494458763011,
|
|
|
|
'status':'unapproved',
|
|
|
|
'metamaskNetworkId':'1494442339676',
|
|
|
|
'txParams':{
|
|
|
|
'from':'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826',
|
|
|
|
'to':'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
'value':'0xde0b6b3a7640000',
|
|
|
|
gasPrice,
|
|
|
|
'gas':'0x7b0c'},
|
|
|
|
'gasLimitSpecified':false,
|
|
|
|
'estimatedGas':'0x5208',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
it('should use updated values when edited.', function (done) {
|
|
|
|
|
2017-05-12 02:15:45 +02:00
|
|
|
const renderer = ReactTestUtils.createRenderer();
|
2017-05-16 00:21:28 +02:00
|
|
|
const newGasPrice = '0x77359400'
|
2017-05-12 00:28:33 +02:00
|
|
|
|
2017-05-11 02:26:51 +02:00
|
|
|
const props = {
|
|
|
|
identities,
|
|
|
|
accounts: identities,
|
|
|
|
txData,
|
|
|
|
sendTransaction: (txMeta, event) => {
|
2017-05-16 00:23:38 +02:00
|
|
|
|
|
|
|
// Assert changes:
|
2017-05-16 00:21:28 +02:00
|
|
|
const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice)
|
|
|
|
assert.notEqual(result, gasPrice, 'gas price should change')
|
|
|
|
assert.equal(result, newGasPrice, 'gas price assigned.')
|
2017-05-11 02:26:51 +02:00
|
|
|
done()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-12 02:09:23 +02:00
|
|
|
const pendingTxComponent = h(PendingTx, props)
|
2017-05-16 00:07:38 +02:00
|
|
|
const component = additions.renderIntoDocument(pendingTxComponent);
|
2017-05-12 02:09:23 +02:00
|
|
|
renderer.render(pendingTxComponent)
|
2017-05-12 02:15:45 +02:00
|
|
|
const result = renderer.getRenderOutput()
|
2017-05-12 02:43:40 +02:00
|
|
|
const form = result.props.children
|
|
|
|
const children = form.props.children[form.props.children.length - 1]
|
2017-05-12 02:15:45 +02:00
|
|
|
assert.equal(result.type, 'div', 'should create a div')
|
2017-05-12 02:43:40 +02:00
|
|
|
|
|
|
|
try{
|
|
|
|
|
2017-05-16 00:07:38 +02:00
|
|
|
const input = additions.find(component, '.cell.row input[type="number"]')[1]
|
|
|
|
ReactTestUtils.Simulate.change(input, {
|
|
|
|
target: {
|
|
|
|
value: 2,
|
|
|
|
checkValidity() { return true },
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let form = additions.find(component, 'form')[0]
|
|
|
|
form.checkValidity = () => true
|
|
|
|
form.getFormEl = () => { return { checkValidity() { return true } } }
|
|
|
|
ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() {return true} } })
|
2017-05-12 02:43:40 +02:00
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.log("WHAAAA")
|
|
|
|
console.error(e)
|
|
|
|
}
|
2017-05-11 02:26:51 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
2017-05-12 02:09:23 +02:00
|
|
|
|