You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.3 KiB
114 lines
3.3 KiB
4 years ago
|
import * as reactRedux from 'react-redux';
|
||
|
import { renderHook } from '@testing-library/react-hooks';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import transactions from '../../test/data/transaction-data.json';
|
||
4 years ago
|
import { showSidebar } from '../store/actions';
|
||
|
import * as methodDataHook from './useMethodData';
|
||
|
import * as metricEventHook from './useMetricEvent';
|
||
|
import { useRetryTransaction } from './useRetryTransaction';
|
||
5 years ago
|
|
||
4 years ago
|
describe('useRetryTransaction', () => {
|
||
|
describe('when transaction meets retry enabled criteria', () => {
|
||
4 years ago
|
const dispatch = sinon.spy(() => Promise.resolve({ blockTime: 0 }));
|
||
|
const trackEvent = sinon.spy();
|
||
4 years ago
|
const event = {
|
||
|
preventDefault: () => undefined,
|
||
|
stopPropagation: () => undefined,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
beforeAll(() => {
|
||
4 years ago
|
sinon.stub(reactRedux, 'useDispatch').returns(dispatch);
|
||
|
sinon.stub(methodDataHook, 'useMethodData').returns({});
|
||
|
sinon.stub(metricEventHook, 'useMetricEvent').returns(trackEvent);
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
dispatch.resetHistory();
|
||
|
trackEvent.resetHistory();
|
||
|
});
|
||
4 years ago
|
|
||
|
afterAll(() => {
|
||
|
sinon.restore();
|
||
|
});
|
||
|
|
||
5 years ago
|
const retryEnabledTransaction = {
|
||
|
...transactions[0],
|
||
|
transactions: [
|
||
|
{
|
||
|
submittedTime: new Date() - 5001,
|
||
|
},
|
||
|
],
|
||
|
hasRetried: false,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
it('retryTransaction function should track metrics', () => {
|
||
4 years ago
|
const { result } = renderHook(() =>
|
||
|
useRetryTransaction(retryEnabledTransaction, true),
|
||
4 years ago
|
);
|
||
|
const retry = result.current;
|
||
|
retry(event);
|
||
4 years ago
|
expect(trackEvent.calledOnce).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('retryTransaction function should show retry sidebar', async () => {
|
||
4 years ago
|
const { result } = renderHook(() =>
|
||
|
useRetryTransaction(retryEnabledTransaction, true),
|
||
4 years ago
|
);
|
||
|
const retry = result.current;
|
||
|
await retry(event);
|
||
4 years ago
|
expect(
|
||
5 years ago
|
dispatch.calledWith(
|
||
|
showSidebar({
|
||
|
transitionName: 'sidebar-left',
|
||
|
type: 'customize-gas',
|
||
|
props: { transaction: retryEnabledTransaction.initialTransaction },
|
||
4 years ago
|
}),
|
||
5 years ago
|
),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should handle cancelled or multiple speedup transactions', async () => {
|
||
4 years ago
|
const cancelledTransaction = {
|
||
|
initialTransaction: {
|
||
|
...transactions[0].initialTransaction,
|
||
|
txParams: {
|
||
|
...transactions[0].initialTransaction.txParams,
|
||
|
},
|
||
|
},
|
||
|
primaryTransaction: {
|
||
|
...transactions[0].primaryTransaction,
|
||
|
txParams: {
|
||
|
from: '0xee014609ef9e09776ac5fe00bdbfef57bcdefebb',
|
||
|
gas: '0x5308',
|
||
|
gasPrice: '0x77359400',
|
||
|
nonce: '0x3',
|
||
|
to: '0xabca64466f257793eaa52fcfff5066894b76a149',
|
||
|
value: '0x0',
|
||
|
},
|
||
|
},
|
||
|
transactions: [
|
||
|
{
|
||
|
submittedTime: new Date() - 5001,
|
||
|
},
|
||
|
],
|
||
|
hasRetried: false,
|
||
|
};
|
||
|
|
||
|
const { result } = renderHook(() =>
|
||
|
useRetryTransaction(cancelledTransaction, true),
|
||
|
);
|
||
|
const retry = result.current;
|
||
|
await retry(event);
|
||
4 years ago
|
expect(
|
||
4 years ago
|
dispatch.calledWith(
|
||
|
showSidebar({
|
||
|
transitionName: 'sidebar-left',
|
||
|
type: 'customize-gas',
|
||
|
props: { transaction: cancelledTransaction.primaryTransaction },
|
||
|
}),
|
||
|
),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|