aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/actions/tx_test.js
blob: f2f8f1d1c40334b6bb87849eb44b6b4ba4b592bb (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
var assert = require('assert')
var path = require('path')

import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'

const actions = require(path.join(__dirname, '../../../ui/app/store/actions.js'))

const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)

describe('tx confirmation screen', function () {
  const txId = 1457634084250832
  const initialState = {
    appState: {
      currentView: {
        name: 'confTx',
      },
    },
    metamask: {
      unapprovedTxs: {
        [txId]: {
          id: txId,
          status: 'unconfirmed',
          time: 1457634084250,
        },
      },
    },
  }

  const store = mockStore(initialState)

  describe('cancelTx', function () {
    before(function (done) {
      actions._setBackgroundConnection({
        approveTransaction (_, cb) { cb('An error!') },
        cancelTransaction (_, cb) { cb() },
        clearSeedWordCache (cb) { cb() },
        getState (cb) { cb() },
      })
      done()
    })

    it('creates COMPLETED_TX with the cancelled transaction ID', function (done) {
      store.dispatch(actions.cancelTx({ id: txId }))
        .then(() => {
          const storeActions = store.getActions()
          const completedTxAction = storeActions.find(({ type }) => type === actions.COMPLETED_TX)
          assert.equal(completedTxAction.value, txId)
          done()
        })
    })
  })
})