2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import * as reactRedux from 'react-redux';
|
|
|
|
import { renderHook } from '@testing-library/react-hooks';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import transactions from '../../../../test/data/transaction-data.json';
|
|
|
|
import * as methodDataHook from '../useMethodData';
|
|
|
|
import * as metricEventHook from '../useMetricEvent';
|
|
|
|
import { showSidebar } from '../../store/actions';
|
|
|
|
import { useRetryTransaction } from '../useRetryTransaction';
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
describe('useRetryTransaction', function () {
|
|
|
|
describe('when transaction meets retry enabled criteria', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const dispatch = sinon.spy(() => Promise.resolve({ blockTime: 0 }));
|
|
|
|
const trackEvent = sinon.spy();
|
2020-11-03 00:41:28 +01:00
|
|
|
const event = {
|
|
|
|
preventDefault: () => undefined,
|
|
|
|
stopPropagation: () => undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
before(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.stub(reactRedux, 'useDispatch').returns(dispatch);
|
|
|
|
sinon.stub(methodDataHook, 'useMethodData').returns({});
|
|
|
|
sinon.stub(metricEventHook, 'useMetricEvent').returns(trackEvent);
|
|
|
|
});
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch.resetHistory();
|
|
|
|
trackEvent.resetHistory();
|
|
|
|
});
|
2020-05-26 22:49:11 +02:00
|
|
|
const retryEnabledTransaction = {
|
|
|
|
...transactions[0],
|
|
|
|
transactions: [
|
|
|
|
{
|
|
|
|
submittedTime: new Date() - 5001,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
hasRetried: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
it('retryTransaction function should track metrics', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const { result } = renderHook(() =>
|
|
|
|
useRetryTransaction(retryEnabledTransaction, true),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const retry = result.current;
|
|
|
|
retry(event);
|
|
|
|
assert.strictEqual(trackEvent.calledOnce, true);
|
|
|
|
});
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
it('retryTransaction function should show retry sidebar', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const { result } = renderHook(() =>
|
|
|
|
useRetryTransaction(retryEnabledTransaction, true),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const retry = result.current;
|
|
|
|
await retry(event);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-05-26 22:49:11 +02:00
|
|
|
dispatch.calledWith(
|
|
|
|
showSidebar({
|
|
|
|
transitionName: 'sidebar-left',
|
|
|
|
type: 'customize-gas',
|
|
|
|
props: { transaction: retryEnabledTransaction.initialTransaction },
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-05-26 22:49:11 +02:00
|
|
|
),
|
2020-07-14 17:20:41 +02:00
|
|
|
true,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
after(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|