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

fix: Switch networks #1232

Merged
merged 8 commits into from
Oct 15, 2024
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
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
Loading