2023-04-17 16:34:26 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { screen } from '@testing-library/react';
|
|
|
|
|
2023-08-03 19:31:35 +02:00
|
|
|
import { NetworkType } from '@metamask/controller-utils';
|
|
|
|
import { NetworkStatus } from '@metamask/network-controller';
|
2023-04-17 16:34:26 +02:00
|
|
|
import { GasEstimateTypes } from '../../../../shared/constants/gas';
|
|
|
|
import mockEstimates from '../../../../test/data/mock-estimates.json';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
|
|
import { renderWithProvider } from '../../../../test/jest';
|
|
|
|
import configureStore from '../../../store/store';
|
|
|
|
|
|
|
|
import { GasFeeContextProvider } from '../../../contexts/gasFee';
|
|
|
|
import ConfirmGasDisplay from './confirm-gas-display';
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
|
|
|
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const render = ({ transactionProp = {}, contextProps = {} } = {}) => {
|
|
|
|
const store = configureStore({
|
|
|
|
...mockState,
|
|
|
|
...contextProps,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
accounts: {
|
|
|
|
[mockState.metamask.selectedAddress]: {
|
|
|
|
address: mockState.metamask.selectedAddress,
|
|
|
|
balance: '0x1F4',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
},
|
|
|
|
gasFeeEstimates: mockEstimates[GasEstimateTypes.feeMarket],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return renderWithProvider(
|
|
|
|
<GasFeeContextProvider transaction={transactionProp}>
|
|
|
|
<ConfirmGasDisplay />
|
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('ConfirmGasDisplay', () => {
|
|
|
|
it('should match snapshot', async () => {
|
|
|
|
const { container } = render();
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('should render gas display labels for EIP1559 transcations', () => {
|
|
|
|
render({
|
|
|
|
transactionProp: {
|
|
|
|
txParams: {
|
|
|
|
gas: '0x5208',
|
|
|
|
maxFeePerGas: '0x59682f10',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
|
|
},
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Gas')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('(estimated)')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
|
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
|
|
|
});
|
|
|
|
it('should render gas display labels for legacy transcations', () => {
|
|
|
|
render({
|
|
|
|
contextProps: {
|
|
|
|
metamask: {
|
2023-08-03 19:31:35 +02:00
|
|
|
selectedNetworkClientId: NetworkType.mainnet,
|
|
|
|
networksMetadata: {
|
|
|
|
[NetworkType.mainnet]: {
|
|
|
|
EIPS: {
|
|
|
|
1559: false,
|
|
|
|
},
|
|
|
|
status: NetworkStatus.Available,
|
2023-04-17 16:34:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
confirmTransaction: {
|
|
|
|
txData: {
|
|
|
|
id: 8393540981007587,
|
|
|
|
status: 'unapproved',
|
|
|
|
chainId: '0x5',
|
|
|
|
txParams: {
|
|
|
|
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
to: '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
|
|
|
|
value: '0x0',
|
|
|
|
gas: '0x5208',
|
|
|
|
gasPrice: '0x3b9aca00',
|
|
|
|
type: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Estimated gas fee')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
|
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
|
|
|
});
|
|
|
|
});
|