1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 13:47:06 +01:00
metamask-extension/shared/modules/updateTxData.test.js
Albert Olivé 2070e5e42a
Feature/mmi 3009 confirm transaction base code fences (#19335)
* Added code fences

* Continue working on this ticket

* Fixed policies

* Added compliance-row component

* Fixed tests and css

* Fixed invalid locale

* Fixing linting

* Add optional check

* Fixing issues

* Fixed storybook

* Added missing dependency

* ran lavamoat auto

* ran dedupe and lavamoat

* lint

* Removed compliance row

* Removed unneeded package

* Removed unneeded proptyes

* updates mmi packages

* updating lavamoat

* formatting main

* Fixed conflicts

* updates lock file

* Moved code fences to have them all in the same place

* Updated yarn.lock and lavamoat

* remove linebreak

* Improved logic in order to not have many code fences and improve readability

* Fixing proptypes issues with eslint

* runs lavamoat auto

* Testing fixes issue e2e tests

* Testing issues

* Reverting code fences container

* Fixing issue with binding

* Added code fences in proptypes

* Reverting code fences

* Removed institutional from main lavamoat

* Added code fences in confirm transaction base component

* Adding tests for handleMainSubmit

* Improving code

* Added test for handleMainSubmit

* Removed waitFor

---------

Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
Co-authored-by: António Regadas <apregadas@gmail.com>
2023-06-07 08:43:28 +02:00

103 lines
3.2 KiB
JavaScript

import { TransactionType } from '../constants/transaction';
import updateTxData from './updateTxData';
describe('updateTxData', () => {
const mockAddToAddressBookIfNew = jest.fn();
afterEach(() => {
mockAddToAddressBookIfNew.mockClear();
});
it('should add to address book if txData type is simpleSend', () => {
const txData = {
type: TransactionType.simpleSend,
};
updateTxData({
txData,
addToAddressBookIfNew: mockAddToAddressBookIfNew,
toAccounts: 'mockToAccounts',
toAddress: 'mockToAddress',
});
expect(mockAddToAddressBookIfNew).toHaveBeenCalledWith(
'mockToAddress',
'mockToAccounts',
);
});
it('should update estimatedBaseFee if baseFeePerGas is provided', () => {
const txData = {};
const result = updateTxData({
txData,
baseFeePerGas: 'mockBaseFeePerGas',
});
expect(result.estimatedBaseFee).toBe('mockBaseFeePerGas');
});
it('should update contractMethodName if name is provided', () => {
const txData = {};
const result = updateTxData({
txData,
name: 'mockName',
});
expect(result.contractMethodName).toBe('mockName');
});
it('should update dappProposedTokenAmount and originalApprovalAmount if dappProposedTokenAmount is provided', () => {
const txData = {};
const result = updateTxData({
txData,
dappProposedTokenAmount: 'mockDappProposedTokenAmount',
});
expect(result.dappProposedTokenAmount).toBe('mockDappProposedTokenAmount');
expect(result.originalApprovalAmount).toBe('mockDappProposedTokenAmount');
});
it('should update customTokenAmount and finalApprovalAmount if customTokenAmount is provided', () => {
const txData = {};
const result = updateTxData({
txData,
customTokenAmount: 'mockCustomTokenAmount',
});
expect(result.customTokenAmount).toBe('mockCustomTokenAmount');
expect(result.finalApprovalAmount).toBe('mockCustomTokenAmount');
});
it('should update finalApprovalAmount if dappProposedTokenAmount is provided but customTokenAmount is not', () => {
const txData = {};
const result = updateTxData({
txData,
dappProposedTokenAmount: 'mockDappProposedTokenAmount',
});
expect(result.finalApprovalAmount).toBe('mockDappProposedTokenAmount');
});
it('should update currentTokenBalance if currentTokenBalance is provided', () => {
const txData = {};
const result = updateTxData({
txData,
currentTokenBalance: 'mockCurrentTokenBalance',
});
expect(result.currentTokenBalance).toBe('mockCurrentTokenBalance');
});
it('should update maxFeePerGas in txParams if maxFeePerGas is provided', () => {
const txData = { txParams: {} };
const result = updateTxData({
txData,
maxFeePerGas: 'mockMaxFeePerGas',
});
expect(result.txParams.maxFeePerGas).toBe('mockMaxFeePerGas');
});
it('should update maxPriorityFeePerGas in txParams if maxPriorityFeePerGas is provided', () => {
const txData = { txParams: {} };
const result = updateTxData({
txData,
maxPriorityFeePerGas: 'mockMaxPriorityFeePerGas',
});
expect(result.txParams.maxPriorityFeePerGas).toBe(
'mockMaxPriorityFeePerGas',
);
});
});