Skip to content

Commit 7a90c6b

Browse files
test: Fix Per dapp selected network e2e to include GNS disabled scenario (#19750)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 628d6ba commit 7a90c6b

File tree

2 files changed

+199
-119
lines changed

2 files changed

+199
-119
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
import FixtureBuilder from '../../../framework/fixtures/FixtureBuilder.ts';
2+
import { withFixtures } from '../../../framework/fixtures/FixtureHelper.ts';
3+
import { buildPermissions } from '../../../framework/fixtures/FixtureUtils.ts';
4+
import Browser from '../../../pages/Browser/BrowserView.ts';
5+
import ConfirmationFooterActions from '../../../pages/Browser/Confirmations/FooterActions.ts';
6+
import ConfirmationUITypes from '../../../pages/Browser/Confirmations/ConfirmationUITypes.ts';
7+
import TestDApp from '../../../pages/Browser/TestDApp.ts';
8+
import NetworkEducationModal from '../../../pages/Network/NetworkEducationModal.ts';
9+
import NetworkListModal from '../../../pages/Network/NetworkListModal.ts';
10+
import TabBarComponent from '../../../pages/wallet/TabBarComponent.ts';
11+
import WalletView from '../../../pages/wallet/WalletView.ts';
12+
import {
13+
RegressionConfirmations,
14+
SmokeConfirmationsRedesigned,
15+
} from '../../../tags.js';
16+
import Assertions from '../../../framework/Assertions.ts';
17+
import { loginToApp } from '../../../viewHelper.ts';
18+
import { DappVariants } from '../../../framework/Constants.ts';
19+
import { setupRemoteFeatureFlagsMock } from '../../../api-mocking/helpers/remoteFeatureFlagsHelper.ts';
20+
import { confirmationsRedesignedFeatureFlags } from '../../../api-mocking/mock-responses/feature-flags-mocks.ts';
21+
import { Mockttp } from 'mockttp';
22+
23+
const LOCAL_CHAIN_ID = '0x539';
24+
const LOCAL_CHAIN_NAME = 'Localhost';
25+
26+
async function changeNetworkFromNetworkListModal(networkName: string) {
27+
await TabBarComponent.tapWallet();
28+
await WalletView.tapNetworksButtonOnNavBar();
29+
await NetworkListModal.changeNetworkTo(networkName);
30+
await device.disableSynchronization();
31+
await NetworkEducationModal.tapGotItButton();
32+
await device.enableSynchronization();
33+
}
34+
35+
async function changeNetworkFromNetworkListModalGNSDisabled(
36+
networkName: string,
37+
) {
38+
await TabBarComponent.tapWallet();
39+
await WalletView.tapTokenNetworkFilter();
40+
await NetworkListModal.changeNetworkTo(networkName);
41+
}
42+
43+
describe(SmokeConfirmationsRedesigned('Per Dapp Selected Network'), () => {
44+
const testSpecificMock = async (mockServer: Mockttp) => {
45+
await setupRemoteFeatureFlagsMock(
46+
mockServer,
47+
Object.assign({}, ...confirmationsRedesignedFeatureFlags),
48+
);
49+
};
50+
51+
// Some tests depend on the MM_REMOVE_GLOBAL_NETWORK_SELECTOR environment variable being set to false.
52+
const isRemoveGlobalNetworkSelectorEnabled =
53+
process.env.MM_REMOVE_GLOBAL_NETWORK_SELECTOR === 'true';
54+
const itif = (condition: boolean) => (condition ? it : it.skip);
55+
56+
beforeAll(async () => {
57+
jest.setTimeout(15000);
58+
});
59+
60+
itif(isRemoveGlobalNetworkSelectorEnabled)(
61+
'submits a transaction to a dApp selected network',
62+
async () => {
63+
await withFixtures(
64+
{
65+
dapps: [
66+
{
67+
dappVariant: DappVariants.TEST_DAPP,
68+
},
69+
],
70+
fixture: new FixtureBuilder()
71+
.withGanacheNetwork()
72+
.withPermissionControllerConnectedToTestDapp(
73+
buildPermissions([LOCAL_CHAIN_ID]),
74+
)
75+
.build(),
76+
restartDevice: true,
77+
testSpecificMock,
78+
},
79+
async () => {
80+
await loginToApp();
81+
await TabBarComponent.tapBrowser();
82+
await Browser.navigateToTestDApp();
83+
84+
// Make sure the dapp is connected to the predefined network in configuration (LOCAL_CHAIN_ID)
85+
// by checking chainId text in the test dapp
86+
await TestDApp.verifyCurrentNetworkText('Chain id ' + LOCAL_CHAIN_ID);
87+
88+
// Change the network to Ethereum Main Network in app
89+
await changeNetworkFromNetworkListModalGNSDisabled(
90+
'Ethereum Main Network',
91+
);
92+
93+
await TabBarComponent.tapBrowser();
94+
// Assert the dapp is still connected the previously selected network (LOCAL_CHAIN_ID)
95+
await TestDApp.verifyCurrentNetworkText('Chain id ' + LOCAL_CHAIN_ID);
96+
97+
// Now do a transaction
98+
await TestDApp.tapSendEIP1559Button();
99+
100+
// Wait for the confirmation modal to appear
101+
await Assertions.expectElementToBeVisible(
102+
ConfirmationUITypes.ModalConfirmationContainer,
103+
);
104+
105+
// Assert the transaction is happening on the correct network
106+
await Assertions.expectTextDisplayed(LOCAL_CHAIN_NAME);
107+
108+
// Accept confirmation
109+
await ConfirmationFooterActions.tapConfirmButton();
110+
111+
// Change the network to Localhost in app
112+
await changeNetworkFromNetworkListModalGNSDisabled(LOCAL_CHAIN_NAME);
113+
114+
// Check activity tab
115+
await TabBarComponent.tapActivity();
116+
await Assertions.expectTextDisplayed('Confirmed');
117+
},
118+
);
119+
},
120+
);
121+
});
122+
123+
describe(RegressionConfirmations('Per Dapp Selected Network'), () => {
124+
const testSpecificMock = async (mockServer: Mockttp) => {
125+
await setupRemoteFeatureFlagsMock(
126+
mockServer,
127+
Object.assign({}, ...confirmationsRedesignedFeatureFlags),
128+
);
129+
};
130+
131+
// Some tests depend on the MM_REMOVE_GLOBAL_NETWORK_SELECTOR environment variable being set to false.
132+
const isRemoveGlobalNetworkSelectorEnabled =
133+
process.env.MM_REMOVE_GLOBAL_NETWORK_SELECTOR === 'true';
134+
const itif = (condition: boolean) => (condition ? it.skip : it);
135+
136+
beforeAll(async () => {
137+
jest.setTimeout(15000);
138+
});
139+
140+
itif(isRemoveGlobalNetworkSelectorEnabled)(
141+
'submits a transaction to a dApp selected network',
142+
async () => {
143+
await withFixtures(
144+
{
145+
dapps: [
146+
{
147+
dappVariant: DappVariants.TEST_DAPP,
148+
},
149+
],
150+
fixture: new FixtureBuilder()
151+
.withGanacheNetwork()
152+
.withPermissionControllerConnectedToTestDapp(
153+
buildPermissions([LOCAL_CHAIN_ID]),
154+
)
155+
.build(),
156+
restartDevice: true,
157+
testSpecificMock,
158+
},
159+
async () => {
160+
await loginToApp();
161+
await TabBarComponent.tapBrowser();
162+
await Browser.navigateToTestDApp();
163+
164+
// Make sure the dapp is connected to the predefined network in configuration (LOCAL_CHAIN_ID)
165+
// by checking chainId text in the test dapp
166+
await TestDApp.verifyCurrentNetworkText('Chain id ' + LOCAL_CHAIN_ID);
167+
168+
// Change the network to Ethereum Main Network in app
169+
await changeNetworkFromNetworkListModal('Ethereum Main Network');
170+
171+
await TabBarComponent.tapBrowser();
172+
// Assert the dapp is still connected the previously selected network (LOCAL_CHAIN_ID)
173+
await TestDApp.verifyCurrentNetworkText('Chain id ' + LOCAL_CHAIN_ID);
174+
175+
// Now do a transaction
176+
await TestDApp.tapSendEIP1559Button();
177+
178+
// Wait for the confirmation modal to appear
179+
await Assertions.expectElementToBeVisible(
180+
ConfirmationUITypes.ModalConfirmationContainer,
181+
);
182+
183+
// Assert the transaction is happening on the correct network
184+
await Assertions.expectTextDisplayed(LOCAL_CHAIN_NAME);
185+
186+
// Accept confirmation
187+
await ConfirmationFooterActions.tapConfirmButton();
188+
189+
// Change the network to Localhost in app
190+
await changeNetworkFromNetworkListModal(LOCAL_CHAIN_NAME);
191+
192+
// Check activity tab
193+
await TabBarComponent.tapActivity();
194+
await Assertions.expectTextDisplayed('Confirmed');
195+
},
196+
);
197+
},
198+
);
199+
});

e2e/specs/quarantine/per-dapp-selected-network.failing.js

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)