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

chore: Adding e2e for confirmation page scroll button #13575

Merged
merged 9 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
View,
} from 'react-native';

import { ConfirmationPageScrollButton } from '../../../../../../e2e/selectors/Confirmation/ConfirmationView.selectors';
import ButtonIcon, {
ButtonIconSizes,
} from '../../../../../component-library/components/Buttons/ButtonIcon';
Expand Down Expand Up @@ -81,7 +82,7 @@ export const ScrollContextProvider: React.FC<{
style={styles.scrollButton}
iconName={IconName.Arrow2Down}
onPress={scrollToBottom}
testID="scroll-to-bottom-button"
testID={ConfirmationPageScrollButton}
/>
)}
<ScrollView
Expand Down
2 changes: 1 addition & 1 deletion app/util/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const testConfig = {};
* TODO: Update this condition once we change E2E builds to use release instead of debug
*/
export const isTest = process.env.METAMASK_ENVIRONMENT !== 'production';
export const isE2E = process.env.IS_TEST === 'true';
export const isE2E = true; //process.env.IS_TEST === 'true';
export const getFixturesServerPortInApp = () =>
testConfig.fixtureServerPort ?? FIXTURE_SERVER_PORT;
9 changes: 8 additions & 1 deletion e2e/pages/Browser/Confirmations/PageSections.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ConfirmationPageSectionsSelectorIDs } from '../../../selectors/Confirmation/ConfirmationView.selectors';
import {
ConfirmationPageScrollButton,
ConfirmationPageSectionsSelectorIDs,
} from '../../../selectors/Confirmation/ConfirmationView.selectors';
import Matchers from '../../../utils/Matchers';

class PageSections {
Expand All @@ -25,6 +28,10 @@ class PageSections {
ConfirmationPageSectionsSelectorIDs.MESSAGE_SECTION,
);
}

get ScrollButton() {
return Matchers.getElementByID(ConfirmationPageScrollButton);
}
}

export default new PageSections();
10 changes: 10 additions & 0 deletions e2e/pages/Browser/TestDApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class TestDApp {
TestDappSelectorsWebIDs.ETHEREUM_SIGN,
);
}
get permitSignButton() {
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
TestDappSelectorsWebIDs.PERMIT_SIGN,
);
}
// This taps on the transfer tokens button under the "SEND TOKENS section"
get nftTransferFromTokensButton() {
return Matchers.getElementByWebID(
Expand Down Expand Up @@ -199,6 +205,10 @@ class TestDApp {
await this.tapButton(this.ethereumSignButton);
}

async tapPermitSignButton() {
await this.tapButton(this.permitSignButton);
}

async tapERC20TransferButton() {
await this.tapButton(this.erc20TransferTokensButton);
}
Expand Down
1 change: 1 addition & 0 deletions e2e/selectors/Browser/TestDapp.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const TestDappSelectorsWebIDs = {
INCREASE_ALLOWANCE_BUTTON_ID: 'increaseTokenAllowance',
NFT_TRANSFER_FROM_BUTTON_ID: 'transferFromButton',
PERSONAL_SIGN: 'personalSign',
PERMIT_SIGN: 'signPermit',
SET_APPROVAL_FOR_ALL_NFT_BUTTON_ID: 'setApprovalForAllButton',
SET_APPROVAL_FOR_ALL_ERC1155_BUTTON_ID: 'setApprovalForAllERC1155Button',
SIGN_TYPE_DATA: 'signTypedData',
Expand Down
3 changes: 3 additions & 0 deletions e2e/selectors/Confirmation/ConfirmationView.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ export const ConfirmationPageSectionsSelectorIDs = {
MESSAGE_SECTION: 'message-section',
STAKING_DETAILS_SECTION: 'staking-details-section',
};

export const ConfirmationPageScrollButton =
'confirmation-scroll-to-bottom-button';
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
'use strict';
import Assertions from '../../../utils/Assertions.js';
import Browser from '../../../pages/Browser/BrowserView.js';
import FixtureBuilder from '../../../fixtures/fixture-builder.js';
import PageSections from '../../../pages/Browser/Confirmations/PageSections.js';
import TabBarComponent from '../../../pages/wallet/TabBarComponent.js';
import TestDApp from '../../../pages/Browser/TestDApp.js';
import TestHelpers from '../../../helpers.js';
import { loginToApp } from '../../../viewHelper.js';
import {
withFixtures,
defaultGanacheOptions,
} from '../../../fixtures/fixture-helper.js';
import { SmokeConfirmationsRedesigned } from '../../../tags.js';
import { mockEvents } from '../../../api-mocking/mock-config/mock-events.js';

const permitSignRequestBody = {
method: 'eth_signTypedData_v4',
params: [
'0x76cf1cdd1fcc252442b50d6e97207228aa4aefc3',
'{"primaryType":"Permit","types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Permit":[{"name":"owner","type":"address"},{"name":"spender","type":"address"},{"name":"value","type":"uint256"},{"name":"nonce","type":"uint256"},{"name":"deadline","type":"uint256"}]},"domain":{"chainId":1,"name":"MyToken","verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC","version":"1"},"message":{"owner":"0x8eeee1781fd885ff5ddef7789486676961873d12","spender":"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","value":3000,"nonce":0,"deadline":50000000000}}',
],
origin: 'localhost',
};

describe(SmokeConfirmationsRedesigned('Confirmations Page Scroll'), () => {
beforeAll(async () => {
jest.setTimeout(2500000);
await TestHelpers.reverseServerPort();
});

it('should not display scroll button if the page has no scroll', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withGanacheNetwork()
.withPermissionControllerConnectedToTestDapp()
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock: {
GET: [mockEvents.GET.remoteFeatureFlagsReDesignedConfirmations],
},
},
async () => {
await loginToApp();

await TabBarComponent.tapBrowser();
await Browser.navigateToTestDApp();

await TestDApp.tapPersonalSignButton();
await Assertions.checkIfNotVisible(PageSections.ScrollButton);
},
);
});

it('should display scroll button if the page has scroll', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withGanacheNetwork()
.withPermissionControllerConnectedToTestDapp()
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
testSpecificMock: {
GET: [mockEvents.GET.remoteFeatureFlagsReDesignedConfirmations],
POST: [
{
...mockEvents.POST.securityAlertApiValidate,
requestBody: permitSignRequestBody,
response: {
block: 20733277,
result_type: 'Malicious',
reason: 'malicious_domain',
description: `You're interacting with a malicious domain. If you approve this request, you might lose your assets.`,
features: [],
},
},
],
},
},
async () => {
await loginToApp();

await TabBarComponent.tapBrowser();
await Browser.navigateToTestDApp();

await TestDApp.tapPermitSignButton();
await Assertions.checkIfVisible(PageSections.ScrollButton);
},
);
});
});
Loading