Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add integration test for pending transaction alert and fix bug … #26986

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion test/integration/confirmations/transactions/alerts.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, fireEvent } from '@testing-library/react';
import { randomUUID } from 'crypto';
import { act, fireEvent, screen } from '@testing-library/react';
import { ApprovalType } from '@metamask/controller-utils';
import nock from 'nock';
import mockMetaMaskState from '../../data/integration-init-state.json';
Expand Down Expand Up @@ -274,4 +275,76 @@ describe('Contract Interaction Confirmation', () => {
await findByTestId('alert-modal-action-showAdvancedGasModal'),
).toHaveTextContent('Update fee');
});

it('displays the alert for pending transactions', async () => {
const account =
mockMetaMaskState.internalAccounts.accounts[
mockMetaMaskState.internalAccounts
.selectedAccount as keyof typeof mockMetaMaskState.internalAccounts.accounts
];

const mockedMetaMaskState =
getMetaMaskStateWithUnapprovedApproveTransaction(account.address);
const unapprovedTransaction = mockedMetaMaskState.transactions[0];
const submittedTransaction = getUnapprovedApproveTransaction(
account.address,
randomUUID(),
pendingTransactionTime - 1000,
);
submittedTransaction.status = 'submitted';

await act(async () => {
await integrationTestRender({
preloadedState: {
...mockedMetaMaskState,
gasEstimateType: 'none',
pendingApprovalCount: 2,
pendingApprovals: {
[pendingTransactionId]: {
id: pendingTransactionId,
origin: 'origin',
time: pendingTransactionTime,
type: ApprovalType.Transaction,
requestData: {
txId: pendingTransactionId,
},
requestState: null,
expectsResult: false,
},
[submittedTransaction.id]: {
id: submittedTransaction.id,
origin: 'origin',
time: pendingTransactionTime - 1000,
type: ApprovalType.Transaction,
requestData: {
txId: submittedTransaction.id,
},
requestState: null,
expectsResult: false,
},
},
transactions: [unapprovedTransaction, submittedTransaction],
},
backgroundConnection: backgroundConnectionMocked,
});
});

expect(await screen.getByTestId('inline-alert')).toBeInTheDocument();

act(() => {
fireEvent.click(screen.getByTestId('inline-alert'));
});

expect(await screen.findByTestId('alert-modal')).toBeInTheDocument();

expect(
await screen.findByTestId('alert-modal__selected-alert'),
).toBeInTheDocument();

expect(
await screen.findByTestId('alert-modal__selected-alert'),
).toHaveTextContent(
'This transaction won’t go through until a previous transaction is complete. Learn how to cancel or speed up a transaction.',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ exports[`<ApproveInfo /> renders component for approve request 1`] = `
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
data-testid="gas-fee-details-speed"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start mm-box--color-info-default"
style="align-items: center;"
>
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ exports[`<BaseTransactionInfo /> renders component for contract interaction requ
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
data-testid="gas-fee-details-speed"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start mm-box--color-info-default"
style="align-items: center;"
>
<p
Expand Down Expand Up @@ -644,10 +644,10 @@ exports[`<BaseTransactionInfo /> renders component for contract interaction requ
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
data-testid="gas-fee-details-speed"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start mm-box--color-info-default"
style="align-items: center;"
>
<p
Expand Down Expand Up @@ -1001,10 +1001,10 @@ exports[`<BaseTransactionInfo /> renders component for contract interaction requ
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
data-testid="gas-fee-details-speed"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start mm-box--color-info-default"
style="align-items: center;"
>
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ exports[`<GasFeesDetails /> renders component for gas fees section 1`] = `
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
data-testid="gas-fee-details-speed"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start mm-box--color-info-default"
style="align-items: center;"
>
<p
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import React, { Dispatch, SetStateAction } from 'react';
import { useSelector } from 'react-redux';
import {
ConfirmInfoRow,
ConfirmInfoRowVariant,
} from '../../../../../../../components/app/confirm/info/row';
import { ConfirmInfoRowVariant } from '../../../../../../../components/app/confirm/info/row';
import { Box } from '../../../../../../../components/component-library';
import {
AlignItems,
Expand All @@ -19,6 +16,8 @@ import { useFeeCalculations } from '../../hooks/useFeeCalculations';
import { useSupportsEIP1559 } from '../../hooks/useSupportsEIP1559';
import { EditGasFeesRow } from '../edit-gas-fees-row/edit-gas-fees-row';
import { GasFeesRow } from '../gas-fees-row/gas-fees-row';
import { ConfirmInfoAlertRow } from '../../../../../../../components/app/confirm/info/row/alert-row/alert-row';
import { RowAlertKey } from '../../../../../../../components/app/confirm/info/row/constants';

export const GasFeesDetails = ({
setShowCustomizeGasPopover,
Expand Down Expand Up @@ -83,18 +82,20 @@ export const GasFeesDetails = ({
</>
)}
{supportsEIP1559 && (
<ConfirmInfoRow
<ConfirmInfoAlertRow
alertKey={RowAlertKey.Speed}
data-testid="gas-fee-details-speed"
label={t('speed')}
variant={ConfirmInfoRowVariant.Default}
ownerId={transactionMeta.id}
>
<Box display={Display.Flex} alignItems={AlignItems.center}>
<GasTiming
maxFeePerGas={maxFeePerGas}
maxPriorityFeePerGas={maxPriorityFeePerGas}
/>
</Box>
</ConfirmInfoRow>
</ConfirmInfoAlertRow>
)}
{showAdvancedDetails && (
<GasFeesRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ exports[`<GasFeesSection /> renders component for gas fees section 1`] = `
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
data-testid="gas-fee-details-speed"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start"
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-flex-start mm-box--color-info-default"
style="align-items: center;"
>
<p
Expand Down