2021-11-12 20:09:59 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { screen } from '@testing-library/react';
|
|
|
|
|
2021-11-29 18:40:48 +01:00
|
|
|
import {
|
|
|
|
GAS_ESTIMATE_TYPES,
|
|
|
|
PRIORITY_LEVELS,
|
|
|
|
} from '../../../../shared/constants/gas';
|
2021-11-29 17:08:24 +01:00
|
|
|
import { TRANSACTION_ENVELOPE_TYPES } from '../../../../shared/constants/transaction';
|
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
import { GasFeeContextProvider } from '../../../contexts/gasFee';
|
|
|
|
import { renderWithProvider } from '../../../../test/jest';
|
2021-11-29 17:08:24 +01:00
|
|
|
import mockEstimates from '../../../../test/data/mock-estimates.json';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
2021-11-12 20:09:59 +01:00
|
|
|
import configureStore from '../../../store/store';
|
|
|
|
|
|
|
|
import TransactionDetail from './transaction-detail.component';
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
const render = ({ componentProps, contextProps } = {}) => {
|
2021-11-12 20:09:59 +01:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
2021-11-29 17:08:24 +01:00
|
|
|
...mockState.metamask,
|
2021-11-12 20:09:59 +01:00
|
|
|
accounts: {
|
2021-11-29 17:08:24 +01:00
|
|
|
[mockState.metamask.selectedAddress]: {
|
|
|
|
address: mockState.metamask.selectedAddress,
|
|
|
|
balance: '0x1F4',
|
2021-11-12 20:09:59 +01:00
|
|
|
},
|
|
|
|
},
|
2021-11-29 17:08:24 +01:00
|
|
|
gasFeeEstimates: mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET],
|
2021-11-12 20:09:59 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return renderWithProvider(
|
2021-11-24 18:02:53 +01:00
|
|
|
<GasFeeContextProvider {...contextProps}>
|
2021-11-12 20:09:59 +01:00
|
|
|
<TransactionDetail
|
|
|
|
onEdit={() => {
|
|
|
|
console.log('on edit');
|
|
|
|
}}
|
|
|
|
rows={[]}
|
2021-12-01 01:31:21 +01:00
|
|
|
userAcknowledgedGasMissing
|
2021-11-24 18:02:53 +01:00
|
|
|
{...componentProps}
|
2021-11-12 20:09:59 +01:00
|
|
|
/>
|
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('TransactionDetail', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
process.env.EIP_1559_V2 = true;
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
afterEach(() => {
|
|
|
|
process.env.EIP_1559_V2 = false;
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
it('should render edit link with text low if low gas estimates are selected', () => {
|
2021-11-24 18:02:53 +01:00
|
|
|
render({ contextProps: { transaction: { userFeeLevel: 'low' } } });
|
2021-11-12 20:09:59 +01:00
|
|
|
expect(screen.queryByText('🐢')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Low')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
it('should render edit link with text markey if medium gas estimates are selected', () => {
|
2021-11-24 18:02:53 +01:00
|
|
|
render({ contextProps: { transaction: { userFeeLevel: 'medium' } } });
|
2021-11-12 20:09:59 +01:00
|
|
|
expect(screen.queryByText('🦊')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Market')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
it('should render edit link with text agressive if high gas estimates are selected', () => {
|
2021-11-24 18:02:53 +01:00
|
|
|
render({ contextProps: { transaction: { userFeeLevel: 'high' } } });
|
2021-11-12 20:09:59 +01:00
|
|
|
expect(screen.queryByText('🦍')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Aggressive')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
it('should render edit link with text Site suggested if site suggested estimated are used', () => {
|
|
|
|
render({
|
2021-11-24 18:02:53 +01:00
|
|
|
contextProps: {
|
|
|
|
transaction: {
|
2021-11-29 18:40:48 +01:00
|
|
|
userFeeLevel: PRIORITY_LEVELS.DAPP_SUGGESTED,
|
2021-11-24 18:02:53 +01:00
|
|
|
dappSuggestedGasFees: { maxFeePerGas: 1, maxPriorityFeePerGas: 1 },
|
|
|
|
txParams: { maxFeePerGas: 1, maxPriorityFeePerGas: 1 },
|
|
|
|
},
|
2021-11-12 20:09:59 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('🌐')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Site suggested')).toBeInTheDocument();
|
|
|
|
expect(document.getElementsByClassName('info-tooltip')).toHaveLength(1);
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2021-11-12 20:09:59 +01:00
|
|
|
it('should render edit link with text advance if custom gas estimates are used', () => {
|
|
|
|
render({
|
2021-11-24 18:02:53 +01:00
|
|
|
contextProps: {
|
|
|
|
defaultEstimateToUse: 'custom',
|
|
|
|
},
|
2021-11-12 20:09:59 +01:00
|
|
|
});
|
|
|
|
expect(screen.queryByText('⚙')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Advanced')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Edit')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
|
|
|
it('should not render edit link if transaction has simulation error and prop userAcknowledgedGasMissing is false', () => {
|
|
|
|
render({
|
|
|
|
contextProps: {
|
|
|
|
transaction: {
|
|
|
|
simulationFails: true,
|
|
|
|
userFeeLevel: 'low',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
componentProps: { userAcknowledgedGasMissing: false },
|
|
|
|
});
|
|
|
|
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Low')).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render edit link if userAcknowledgedGasMissing is true even if transaction has simulation error', () => {
|
|
|
|
render({
|
|
|
|
contextProps: {
|
|
|
|
transaction: {
|
|
|
|
simulationFails: true,
|
|
|
|
userFeeLevel: 'low',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
componentProps: { userAcknowledgedGasMissing: true },
|
|
|
|
});
|
|
|
|
expect(screen.queryByRole('button')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Low')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-29 17:08:24 +01:00
|
|
|
|
|
|
|
it('should render edit link with text edit for legacy transactions', () => {
|
|
|
|
render({
|
|
|
|
contextProps: {
|
|
|
|
transaction: {
|
|
|
|
userFeeLevel: 'low',
|
|
|
|
txParams: { type: TRANSACTION_ENVELOPE_TYPES.LEGACY },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('🐢')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Edit')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-12 20:09:59 +01:00
|
|
|
});
|