-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add support for showing test networks (#1003)
- Loading branch information
1 parent
603abe9
commit 4360605
Showing
12 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './lock' | ||
export * from './importWalletFromPrivateKey' | ||
export * from './switchAccount' | ||
export * from './settings' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
import type { SettingsSidebarMenus } from '../selectors/settings' | ||
|
||
async function openSettings(page: Page) { | ||
await page.locator(Selectors.accountMenu.accountMenuButton).click() | ||
await page.locator(Selectors.accountMenu.settingsButton).click() | ||
} | ||
|
||
async function openSidebarMenu(page: Page, menu: SettingsSidebarMenus) { | ||
await page.locator(Selectors.settings.sidebarMenu(menu)).click() | ||
} | ||
|
||
async function toggleShowTestNetworks(page: Page) { | ||
// .nth(0) -> Show conversion on test networks | ||
// .nth(1) -> Show test networks | ||
await page.locator(Selectors.settings.advanced.showTestNetworksToggle).nth(1).click() | ||
} | ||
|
||
const advanced = { | ||
toggleShowTestNetworks | ||
} | ||
|
||
export const settings = { | ||
openSettings, | ||
openSidebarMenu, | ||
advanced | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' | ||
|
||
export enum SettingsSidebarMenus { | ||
General = 1, | ||
Advanced = 2, | ||
Contacts = 3, | ||
SecurityAndPrivacy = 4, | ||
Alerts = 5, | ||
Networks = 6, | ||
Experimental = 7, | ||
About = 8 | ||
} | ||
const sidebarMenu = (menu: SettingsSidebarMenus) => | ||
`.settings-page__content__tabs .tab-bar__tab.pointer:nth-of-type(${menu})` | ||
|
||
const advanced = { | ||
showTestNetworksToggle: `${createDataTestSelector('advanced-setting-show-testnet-conversion')} .toggle-button` | ||
} | ||
|
||
export default { | ||
SettingsSidebarMenus, | ||
sidebarMenu, | ||
advanced | ||
} |
20 changes: 20 additions & 0 deletions
20
wallets/metamask/test/e2e/metamask/goBackToHomePage.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { expect } = test | ||
|
||
test('should go back to the home page', async ({ context, metamaskPage }) => { | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) | ||
|
||
await metamask.openSettings() | ||
|
||
await expect(metamaskPage.locator(metamask.homePage.selectors.account)).not.toBeVisible() | ||
|
||
await metamask.goBackToHomePage() | ||
|
||
await expect(metamaskPage.locator(metamask.homePage.selectors.account)).toBeVisible() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { expect } = test | ||
|
||
test('should open settings', async ({ context, metamaskPage }) => { | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) | ||
|
||
await metamask.openSettings() | ||
|
||
const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus | ||
await expect( | ||
metamaskPage.locator(metamask.homePage.selectors.settings.sidebarMenu(SidebarMenus.General)) | ||
).toBeVisible() | ||
}) |
25 changes: 25 additions & 0 deletions
25
wallets/metamask/test/e2e/metamask/openSidebarMenu.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { expect } = test | ||
|
||
test('should open correct menu from the sidebar', async ({ context, metamaskPage }) => { | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) | ||
|
||
await metamask.openSettings() | ||
|
||
await expect( | ||
metamaskPage.locator(metamask.homePage.selectors.settings.advanced.showTestNetworksToggle).last() | ||
).not.toBeVisible() | ||
|
||
const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus | ||
await metamask.openSidebarMenu(SidebarMenus.Advanced) | ||
|
||
await expect( | ||
metamaskPage.locator(metamask.homePage.selectors.settings.advanced.showTestNetworksToggle).last() | ||
).toBeVisible() | ||
}) |
38 changes: 38 additions & 0 deletions
38
wallets/metamask/test/e2e/metamask/toggleShowTestNetworks.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import Selectors from '../../../src/pages/HomePage/selectors' | ||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(basicSetup, unlockForFixture) | ||
|
||
const { expect } = test | ||
|
||
test('should toggle the "show test networks" option', async ({ context, metamaskPage }) => { | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) | ||
|
||
await metamaskPage.locator(metamask.homePage.selectors.networkDropdown.dropdownButton).click() | ||
|
||
const networksCountBefore = await metamaskPage.locator(metamask.homePage.selectors.networkDropdown.networks).count() | ||
|
||
// We're closing the network dropdown with this. | ||
await metamask.goBackToHomePage() | ||
|
||
await metamask.openSettings() | ||
|
||
const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus | ||
await metamask.openSidebarMenu(SidebarMenus.Advanced) | ||
|
||
await metamask.toggleShowTestNetworks() | ||
|
||
// We have to wait for the toggle to be "toggled". This is a hacky workaround, unfortunately. | ||
await expect(metamaskPage.locator(Selectors.settings.advanced.showTestNetworksToggle).nth(1)).toHaveClass( | ||
/toggle-button--on/ | ||
) | ||
|
||
await metamaskPage.locator(metamask.homePage.selectors.networkDropdown.dropdownButton).click() | ||
|
||
const networksCountAfter = await metamaskPage.locator(metamask.homePage.selectors.networkDropdown.networks).count() | ||
|
||
expect(networksCountAfter).toBeGreaterThan(networksCountBefore) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters