1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/app/transaction-detail/transaction-detail.component.test.js

73 lines
2.2 KiB
JavaScript

import React from 'react';
import { screen } from '@testing-library/react';
import { GasEstimateTypes } from '../../../../shared/constants/gas';
import { TransactionEnvelopeType } from '../../../../shared/constants/transaction';
import { GasFeeContextProvider } from '../../../contexts/gasFee';
import { renderWithProvider } from '../../../../test/jest';
import mockEstimates from '../../../../test/data/mock-estimates.json';
import mockState from '../../../../test/data/mock-state.json';
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(),
createTransactionEventFragment: jest.fn(),
}));
const render = ({ componentProps, contextProps } = {}) => {
const store = configureStore({
metamask: {
...mockState.metamask,
accounts: {
[mockState.metamask.selectedAddress]: {
address: mockState.metamask.selectedAddress,
balance: '0x1F4',
},
},
gasFeeEstimates: mockEstimates[GasEstimateTypes.feeMarket],
},
});
return renderWithProvider(
<GasFeeContextProvider {...contextProps}>
<TransactionDetail
onEdit={() => {
console.log('on edit');
}}
rows={[]}
userAcknowledgedGasMissing
{...componentProps}
/>
</GasFeeContextProvider>,
store,
);
};
describe('TransactionDetail', () => {
it('should render edit link with text low if low gas estimates are selected', () => {
render({ contextProps: { transaction: { userFeeLevel: 'low' } } });
expect(screen.queryByText('🐢')).toBeInTheDocument();
expect(screen.queryByText('Low')).toBeInTheDocument();
});
it('should render edit link with text edit for legacy transactions', () => {
render({
contextProps: {
transaction: {
userFeeLevel: 'low',
txParams: { type: TransactionEnvelopeType.legacy },
},
},
});
expect(screen.queryByText('🐢')).not.toBeInTheDocument();
expect(screen.queryByText('Edit')).toBeInTheDocument();
});
});