1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/test/unit/actions/tx_test.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

import assert from 'assert';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as actions from '../../../ui/app/store/actions';
import * as actionConstants from '../../../ui/app/store/actionConstants';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
2018-07-08 03:53:00 +02:00
describe('tx confirmation screen', function () {
const txId = 1457634084250832;
2018-07-08 03:53:00 +02:00
const initialState = {
2020-11-03 00:41:28 +01:00
appState: {},
2018-07-08 03:53:00 +02:00
metamask: {
unapprovedTxs: {
[txId]: {
id: txId,
status: 'unconfirmed',
time: 1457634084250,
2017-05-04 23:35:10 +02:00
},
2018-07-08 03:53:00 +02:00
},
},
};
2018-07-08 03:53:00 +02:00
const store = mockStore(initialState);
2018-07-08 03:53:00 +02:00
describe('cancelTx', function () {
it('creates COMPLETED_TX with the cancelled transaction ID', async function () {
2018-07-08 03:53:00 +02:00
actions._setBackgroundConnection({
2020-11-03 00:41:28 +01:00
approveTransaction(_, cb) {
cb(new Error('An error!'));
},
2020-11-03 00:41:28 +01:00
cancelTransaction(_, cb) {
cb();
},
2020-11-03 00:41:28 +01:00
getState(cb) {
cb(null, {});
},
});
await store.dispatch(actions.cancelTx({ id: txId }));
const storeActions = store.getActions();
2020-11-03 00:41:28 +01:00
const completedTxAction = storeActions.find(
({ type }) => type === actionConstants.COMPLETED_TX,
);
const { id } = completedTxAction.value;
assert.equal(id, txId);
});
});
});