1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

[MMI] Improved code, fixed bugs and added more tests (#19488)

* Improved code, fixed bugs and added more tests

* removing tabKey prop as is causing to fail other test
This commit is contained in:
Albert Olivé 2023-06-08 11:01:06 +02:00 committed by GitHub
parent 2ee1e4d78b
commit 08b881880f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 5 deletions

View File

@ -704,6 +704,7 @@ export default class ConfirmTransactionBase extends Component {
addToAddressBookIfNew,
toAccounts,
toAddress,
showCustodianDeepLink,
} = this.props;
const { noteText } = this.state;
@ -748,9 +749,8 @@ export default class ConfirmTransactionBase extends Component {
if (!this._isMounted) {
return;
}
if (txData.custodyStatus) {
this.props.showCustodianDeepLink({
showCustodianDeepLink({
fromAddress,
closeNotification: isNotification && unapprovedTxCount === 1,
txId: txData.id,

View File

@ -378,10 +378,12 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
...otherDispatchProps
} = dispatchProps;
let isMainBetaFlask = false;
let isMainBetaFlask = ownProps.isMainBetaFlask || false;
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
isMainBetaFlask = true;
if (ownProps.isMainBetaFlask === undefined) {
isMainBetaFlask = true;
}
///: END:ONLY_INCLUDE_IN
return {

View File

@ -233,10 +233,11 @@ describe('Confirm Transaction Base', () => {
<ConfirmTransactionBase actionKey="confirm" />,
store,
);
expect(getByTestId('transaction-note')).toBeInTheDocument();
});
it('handleMainSubmit calls sendTransaction with correct arguments', async () => {
it('handleMainSubmit calls sendTransaction correctly', async () => {
const newMockedStore = {
...mockedStore,
appState: {
@ -300,6 +301,86 @@ describe('Confirm Transaction Base', () => {
expect(sendTransaction).toHaveBeenCalled();
});
it('handleMMISubmit calls sendTransaction correctly and then showCustodianDeepLink', async () => {
const newMockedStore = {
...mockedStore,
appState: {
...mockedStore.appState,
gasLoadingAnimationIsShowing: false,
},
confirmTransaction: {
...mockedStore.confirmTransaction,
txData: {
...mockedStore.confirmTransaction.txData,
custodyStatus: true,
},
},
metamask: {
...mockedStore.metamask,
accounts: {
[mockTxParamsFromAddress]: {
balance: '0x1000000000000000000',
address: mockTxParamsFromAddress,
},
},
gasEstimateType: GasEstimateTypes.feeMarket,
networkDetails: {
...mockedStore.metamask.networkDetails,
EIPS: {
1559: true,
},
},
customGas: {
gasLimit: '0x5208',
gasPrice: '0x59682f00',
},
noGasPrice: false,
},
send: {
...mockedStore.send,
gas: {
...mockedStore.send.gas,
gasEstimateType: GasEstimateTypes.legacy,
gasFeeEstimates: {
low: '0',
medium: '1',
high: '2',
},
},
hasSimulationError: false,
userAcknowledgedGasMissing: false,
submitting: false,
hardwareWalletRequiresConnection: false,
gasIsLoading: false,
gasFeeIsCustom: true,
},
};
const store = configureMockStore(middleware)(newMockedStore);
const sendTransaction = jest
.fn()
.mockResolvedValue(newMockedStore.confirmTransaction.txData);
const showCustodianDeepLink = jest.fn();
const setWaitForConfirmDeepLinkDialog = jest.fn();
const { getByTestId } = renderWithProvider(
<ConfirmTransactionBase
actionKey="confirm"
sendTransaction={sendTransaction}
showCustodianDeepLink={showCustodianDeepLink}
setWaitForConfirmDeepLinkDialog={setWaitForConfirmDeepLinkDialog}
toAddress={mockPropsToAddress}
toAccounts={[{ address: mockPropsToAddress }]}
isMainBetaFlask={false}
/>,
store,
);
const confirmButton = getByTestId('page-container-footer-next');
fireEvent.click(confirmButton);
expect(setWaitForConfirmDeepLinkDialog).toHaveBeenCalled();
await expect(sendTransaction).toHaveBeenCalled();
expect(showCustodianDeepLink).toHaveBeenCalled();
});
describe('when rendering the recipient value', () => {
describe(`when the transaction is a ${TransactionType.simpleSend} type`, () => {
it(`should use txParams.to address`, () => {