aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/components/pending-tx-test.js
blob: 2594a1a267be1458259142ed934a99090e887c7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const assert = require('assert')
const additions = require('react-testutils-additions')
const h = require('react-hyperscript')
var PendingTx = require('../../../ui/app/components/pending-tx')
const createReactFactory = require('create-react-factory').createReactFactory
const React = require('react')
console.dir(createReactFactory)
const shallow = require('enzyme').shallow
const Factory = createReactFactory(PendingTx)
const ReactTestUtils = require('react-addons-test-utils')

describe.only('PendingTx', function () {
  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) {

    const renderer = ReactTestUtils.createRenderer();
    const newGasPrice = '0x451456'

    const props = {
      identities,
      accounts: identities,
      txData,
      sendTransaction: (txMeta, event) => {
        assert.notEqual(txMeta.txParams.gasPrice, gasPrice, 'gas price should change')
        assert.equal(txMeta.txParams.gasPrice, newGasPrice, 'gas price assigned.')
        done()
      },
    }

    const pendingTxComponent = h(PendingTx, props)
    var component = additions.renderIntoDocument(pendingTxComponent);
    renderer.render(pendingTxComponent)
    const result = renderer.getRenderOutput()
    const form = result.props.children
    console.log('FORM children')
    console.dir(form.props.children)
    const children = form.props.children[form.props.children.length - 1]
    assert.equal(result.type, 'div', 'should create a div')
    console.dir(children)

    console.log('finding input')

    try{

      const input = additions.find(component, '.cell.row input[type="number"]')
      console.log('input')
      console.dir(input)

    } catch (e) {
      console.log("WHAAAA")
      console.error(e)
    }

    const noop = () => {}

    setTimeout(() => {
      console.log('timeout finished')

      // Get the gas price input
      // Set it to the newGasPrice value
      // Wait for the value to change
      // Get the submit button
      // Click the submit button
      // Get the output of the submit event.
      // Assert that the value was updated.

    }, 200)

    console.log('calling render')
  })

})