From 7328dd9457da619f9cceb2f15a83655226ce5c29 Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Mon, 27 Nov 2023 05:13:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(metamask):=20Close=20popup?= =?UTF-8?q?=20after=20adding=20new=20network?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/HomePage/actions/addNetwork.ts | 6 ++++++ .../metamask/src/pages/HomePage/selectors/index.ts | 8 +++++++- .../metamask/test/e2e/metamask/addNetwork.spec.ts | 12 ++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts b/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts index 3f09f4484..e315cb9ab 100644 --- a/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts +++ b/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts @@ -1,5 +1,6 @@ import type { Page } from '@playwright/test' import { z } from 'zod' +import { clickLocatorIfCondition } from '../../../utils/closePopup' import { waitFor } from '../../../utils/waitFor' import Selectors from '../selectors' @@ -48,4 +49,9 @@ export async function addNetwork(page: Page, network: Network) { } await page.locator(Selectors.settings.networks.newNetworkForm.saveButton).click() + + // Closes the "Network added successfully!" popup. + // Note: The "Dismiss" button does NOTHING and the network is ALWAYS automatically switched. + const switchToNetworkButtonLocator = page.locator(Selectors.networkAddedPopover.switchToNetworkButton) + await clickLocatorIfCondition(switchToNetworkButtonLocator, () => switchToNetworkButtonLocator.isVisible(), 1_000) } diff --git a/wallets/metamask/src/pages/HomePage/selectors/index.ts b/wallets/metamask/src/pages/HomePage/selectors/index.ts index 42697657a..19ab85eff 100644 --- a/wallets/metamask/src/pages/HomePage/selectors/index.ts +++ b/wallets/metamask/src/pages/HomePage/selectors/index.ts @@ -37,6 +37,11 @@ const popover = { closeButton: `${popoverContainer} ${createDataTestSelector('popover-close')}` } +const networkAddedPopover = { + switchToNetworkButton: `${popoverContainer} button.btn-primary`, + dismissButton: `${popoverContainer} button.btn-secondary` +} + const recoveryPhraseReminder = { gotItButton: '.recovery-phrase-reminder button.btn-primary' } @@ -75,5 +80,6 @@ export default { networkDropdown, accountMenu, recoveryPhraseReminder, - popover + popover, + networkAddedPopover } diff --git a/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts b/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts index 347f59526..336b0c14e 100644 --- a/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts +++ b/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts @@ -1,7 +1,8 @@ import { testWithSynpress } from 'fixtures' +import { z } from 'zod' import { MetaMask, unlockForFixture } from '../../../src' +import { waitFor } from '../../../src/utils/waitFor' -import { z } from 'zod' import basicSetup from '../wallet-setup/basic.setup' const test = testWithSynpress(basicSetup, unlockForFixture) @@ -16,11 +17,18 @@ const network = { blockExplorerUrl: 'https://optimistic.etherscan.io' } -test('should add network', async ({ context, metamaskPage }) => { +test('should add network and close network added popup', async ({ context, metamaskPage }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) await metamask.addNetwork(network) + const isNetworkAddedPopupVisible = await waitFor( + () => metamaskPage.locator(metamask.homePage.selectors.networkAddedPopover.switchToNetworkButton).isVisible(), + 1_000, + false + ) + expect(isNetworkAddedPopupVisible).toBe(false) + await expect(metamaskPage.locator(metamask.homePage.selectors.currentNetwork)).toHaveText(network.name) })