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

✨ feat(metamask): Close all new network popovers #1018

Merged
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
11 changes: 3 additions & 8 deletions wallets/metamask/src/pages/HomePage/actions/addNetwork.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions wallets/metamask/src/pages/HomePage/actions/popups/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './closePopover'
export * from './closeRecoveryPhraseReminder'
export * from './closeNewNetworkInfoPopover'
export * from './closeNetworkAddedPopover'
11 changes: 8 additions & 3 deletions wallets/metamask/src/pages/HomePage/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -81,5 +85,6 @@ export default {
accountMenu,
recoveryPhraseReminder,
popover,
networkAddedPopover
networkAddedPopover,
newNetworkInfoPopover
}