Skip to content

Commit

Permalink
🐛 fix(metamask): Close popup after adding new network
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Nov 27, 2023
1 parent ed74ac1 commit 7328dd9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions wallets/metamask/src/pages/HomePage/actions/addNetwork.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
}
8 changes: 7 additions & 1 deletion wallets/metamask/src/pages/HomePage/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -75,5 +80,6 @@ export default {
networkDropdown,
accountMenu,
recoveryPhraseReminder,
popover
popover,
networkAddedPopover
}
12 changes: 10 additions & 2 deletions wallets/metamask/test/e2e/metamask/addNetwork.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
})

Expand Down

0 comments on commit 7328dd9

Please sign in to comment.