Skip to content

Commit

Permalink
fix: switch networks
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler committed Oct 15, 2024
1 parent e8c402d commit 2293e1a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
19 changes: 19 additions & 0 deletions examples/metamask/test/playwright/addNetwork.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { testWithSynpress } from '@synthetixio/synpress'
import { metaMaskFixtures } from '@synthetixio/synpress/playwright'
import basicSetup from '../wallet-setup/basic.setup'

const test = testWithSynpress(metaMaskFixtures(basicSetup))

const { expect } = test

test('should add a custom network to MetaMask', async ({ metamask, page }) => {
// Add the custom network
await metamask.addNetwork({
name: 'Optimism',
rpcUrl: 'https://mainnet.optimism.io',
chainId: 10,
symbol: 'ETH'
})

await expect(page.locator('#chainId')).toHaveText('0xa')
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ export async function closeNetworkAddedPopover(page: Page) {

// TODO: Extract & make configurable
await clickLocatorIfCondition(switchNetworkButtonLocator, () => switchNetworkButtonLocator.isVisible(), 1_000)

const switchCompleteCloseButtonLocator = page.locator(Selectors.networkAddedPopover.switchCompleteCloseButton)

await clickLocatorIfCondition(
switchCompleteCloseButtonLocator,
() => switchCompleteCloseButtonLocator.isVisible(),
1_000
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export async function toggleShowTestNetworks(page: Page) {
await page.locator(Selectors.networkDropdown.dropdownButton).click()

await toggle(page.locator(Selectors.networkDropdown.showTestNetworksToggle))

await page.locator(Selectors.networkDropdown.closeNetworkPopupButton).click()
}
7 changes: 5 additions & 2 deletions wallets/metamask/src/selectors/pages/HomePage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const popover = {

const networkAddedPopover = {
switchToNetworkButton: '.home__new-network-added__switch-to-button',
dismissButton: '.home__new-network-added button.btn-secondary'
dismissButton: '.home__new-network-added button.btn-secondary',
switchCompleteCloseButton: '.popover-header .box.popover-header__title button.mm-box.mm-button-icon'
}

const newNetworkInfoPopover = {
Expand All @@ -75,7 +76,9 @@ const networkDropdown = {
showTestNetworksToggle: `${networkDropdownContainer} > section > div > label.toggle-button`,
addNetworkButton: `${networkDropdownContainer} div.mm-box.mm-box--padding-4 > button`,
toggleOff: `${networkDropdownContainer} label.toggle-button.toggle-button--off`,
toggleOn: `${networkDropdownContainer} label.toggle-button.toggle-button--on`
toggleOn: `${networkDropdownContainer} label.toggle-button.toggle-button--on`,
closeNetworkPopupButton:
'.mm-modal-header button.mm-button-icon.mm-box--color-icon-default.mm-box--background-color-transparent.mm-box--rounded-lg'
}

const tabContainer = '.tabs__content'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ test('should toggle the "Show test networks" option from the networks dropdown',

await metamask.toggleShowTestNetworks()

await metamaskPage.locator(Selectors.networkDropdown.dropdownButton).click()

// We have to wait for the toggle to be "toggled". This is a hacky workaround, unfortunately.
await expect(metamaskPage.locator(Selectors.networkDropdown.showTestNetworksToggle)).toHaveClass(/toggle-button--on/)

Expand Down

0 comments on commit 2293e1a

Please sign in to comment.