From 7b4414aeb2818f54c2312845e361c4502a5123fb Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Thu, 30 Nov 2023 00:02:14 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(metamask):=20Close=20all=20new?= =?UTF-8?q?=20network=20popovers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metamask/src/pages/HomePage/actions/addNetwork.ts | 11 +++-------- .../actions/popups/closeNetworkAddedPopover.ts | 11 +++++++++++ .../actions/popups/closeNewNetworkInfoPopover.ts | 10 ++++++++++ .../src/pages/HomePage/actions/popups/closePopover.ts | 3 ++- .../src/pages/HomePage/actions/popups/index.ts | 2 ++ .../metamask/src/pages/HomePage/selectors/index.ts | 11 ++++++++--- 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 wallets/metamask/src/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts create mode 100644 wallets/metamask/src/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts b/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts index cf4913673..bb48ff19c 100644 --- a/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts +++ b/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts @@ -1,9 +1,8 @@ import type { Page } from '@playwright/test' import { z } from 'zod' -import { clickLocatorIfCondition } from '../../../utils/clickLocatorIfCondition' import { waitFor } from '../../../utils/waitFor' import Selectors from '../selectors' -import { closePopover } from './popups' +import { closeNetworkAddedPopover, closeNewNetworkInfoPopover } from './popups' const Network = z.object({ name: z.string(), @@ -51,11 +50,7 @@ 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) + await closeNetworkAddedPopover(page) - // Closes the "You have switched to X. Things to keep in mind..." popup. - await closePopover(page) + await closeNewNetworkInfoPopover(page) } diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts b/wallets/metamask/src/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts new file mode 100644 index 000000000..cedc39d9d --- /dev/null +++ b/wallets/metamask/src/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts @@ -0,0 +1,11 @@ +import type { Page } from '@playwright/test' +import { clickLocatorIfCondition } from '../../../../utils/clickLocatorIfCondition' +import Selectors from '../../selectors' + +// Note: The "Dismiss" button does NOTHING and the network is ALWAYS automatically switched. +export async function closeNetworkAddedPopover(page: Page) { + const switchNetworkButtonLocator = page.locator(Selectors.networkAddedPopover.switchToNetworkButton) + + // TODO: Extract & make configurable + await clickLocatorIfCondition(switchNetworkButtonLocator, () => switchNetworkButtonLocator.isVisible(), 1_000) +} diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts b/wallets/metamask/src/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts new file mode 100644 index 000000000..c8ebdcf31 --- /dev/null +++ b/wallets/metamask/src/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts @@ -0,0 +1,10 @@ +import type { Page } from '@playwright/test' +import { clickLocatorIfCondition } from '../../../../utils/clickLocatorIfCondition' +import Selectors from '../../selectors' + +export async function closeNewNetworkInfoPopover(page: Page) { + const gotItButtonLocator = page.locator(Selectors.newNetworkInfoPopover.gotItButton) + + // TODO: Extract & make configurable + await clickLocatorIfCondition(gotItButtonLocator, () => gotItButtonLocator.isVisible(), 1_000) +} diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closePopover.ts b/wallets/metamask/src/pages/HomePage/actions/popups/closePopover.ts index 8d3f9e28e..dba4a03f1 100644 --- a/wallets/metamask/src/pages/HomePage/actions/popups/closePopover.ts +++ b/wallets/metamask/src/pages/HomePage/actions/popups/closePopover.ts @@ -4,7 +4,8 @@ import Selectors from '../../selectors' // Closes the popover with news, rainbows, unicorns, and other stuff. export async function closePopover(page: Page) { - const closeButtonLocator = page.locator(Selectors.popover.closeButton) + // We're using `first()` here just in case there are multiple popovers, which happens sometimes. + const closeButtonLocator = page.locator(Selectors.popover.closeButton).first() // TODO: Extract & make configurable await clickLocatorIfCondition(closeButtonLocator, () => closeButtonLocator.isVisible(), 1_000) diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/index.ts b/wallets/metamask/src/pages/HomePage/actions/popups/index.ts index 2c83dc704..bdee5a034 100644 --- a/wallets/metamask/src/pages/HomePage/actions/popups/index.ts +++ b/wallets/metamask/src/pages/HomePage/actions/popups/index.ts @@ -1,2 +1,4 @@ export * from './closePopover' export * from './closeRecoveryPhraseReminder' +export * from './closeNewNetworkInfoPopover' +export * from './closeNetworkAddedPopover' diff --git a/wallets/metamask/src/pages/HomePage/selectors/index.ts b/wallets/metamask/src/pages/HomePage/selectors/index.ts index 19ab85eff..083b9abde 100644 --- a/wallets/metamask/src/pages/HomePage/selectors/index.ts +++ b/wallets/metamask/src/pages/HomePage/selectors/index.ts @@ -38,8 +38,12 @@ const popover = { } const networkAddedPopover = { - switchToNetworkButton: `${popoverContainer} button.btn-primary`, - dismissButton: `${popoverContainer} button.btn-secondary` + switchToNetworkButton: '.home__new-network-added button.btn-primary', + dismissButton: '.home__new-network-added button.btn-secondary' +} + +const newNetworkInfoPopover = { + gotItButton: '.new-network-info__wrapper button.btn-primary' } const recoveryPhraseReminder = { @@ -81,5 +85,6 @@ export default { accountMenu, recoveryPhraseReminder, popover, - networkAddedPopover + networkAddedPopover, + newNetworkInfoPopover }