Skip to content

Commit

Permalink
feat: toggles in Cypress API (#1221)
Browse files Browse the repository at this point in the history
* feat: toggles in Cypress API

* Update cypress.config.ts
  • Loading branch information
matstyler authored Sep 19, 2024
1 parent af65604 commit 9a6d448
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 12 deletions.
54 changes: 44 additions & 10 deletions wallets/metamask/src/cypress/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MetaMask as MetaMaskPlaywright } from '../playwright/MetaMask'
import { waitFor } from '../playwright/utils/waitFor'
import HomePageSelectors from '../selectors/pages/HomePage'
import Selectors from '../selectors/pages/HomePage'
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
import TransactionPage from '../selectors/pages/NotificationPage/transactionPage'
import type { GasSettings } from '../type/GasSettings'
import type { Network } from '../type/Network'
Expand Down Expand Up @@ -92,6 +93,12 @@ export default class MetaMask {
return true
}

async resetAccount() {
await this.metamaskPlaywright.resetAccount()

return true
}

async switchNetwork({
networkName,
isTestnet = false
Expand Down Expand Up @@ -235,6 +242,24 @@ export default class MetaMask {
return true
}

// Lock/Unlock

async lock() {
await this.metamaskPlaywright.lock()
await expect(
this.metamaskExtensionPage.locator(this.metamaskPlaywright.lockPage.selectors.submitButton)
).toBeVisible()

return true
}

async unlock() {
await this.metamaskPlaywright.unlock()
await expect(this.metamaskExtensionPage.locator(this.metamaskPlaywright.homePage.selectors.logo)).toBeVisible()

return true
}

// Others

async providePublicEncryptionKey() {
Expand Down Expand Up @@ -335,6 +360,18 @@ export default class MetaMask {
})
}

async toggleShowTestNetworks() {
await this.metamaskPlaywright.toggleShowTestNetworks()

return true
}

async toggleDismissSecretRecoveryPhraseReminder() {
await this.metamaskPlaywright.toggleDismissSecretRecoveryPhraseReminder()

return true
}

async goBackToHomePage() {
await this.metamaskPlaywright.openSettings()

Expand All @@ -343,22 +380,19 @@ export default class MetaMask {
await this.metamaskPlaywright.goBackToHomePage()

await expect(this.metamaskExtensionPage.locator(HomePageSelectors.copyAccountAddressButton)).toBeVisible()
}

// Lock/Unlock
return true
}

async lock() {
await this.metamaskPlaywright.lock()
await expect(
this.metamaskExtensionPage.locator(this.metamaskPlaywright.lockPage.selectors.submitButton)
).toBeVisible()
async openSettings() {
await this.metamaskPlaywright.openSettings()

return true
}

async unlock() {
await this.metamaskPlaywright.unlock()
await expect(this.metamaskExtensionPage.locator(this.metamaskPlaywright.homePage.selectors.logo)).toBeVisible()
async openSidebarMenu(menu: SettingsSidebarMenus) {
await this.metamaskPlaywright.openSidebarMenu(menu)
await expect(this.metamaskExtensionPage.locator(HomePageSelectors.settings.sidebarMenu(menu))).toBeVisible()

return true
}
Expand Down
11 changes: 9 additions & 2 deletions wallets/metamask/src/cypress/configureSynpress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { BrowserContext, Page } from '@playwright/test'
import { ensureRdpPort } from '@synthetixio/synpress-core'
import type { CreateAnvilOptions } from '@viem/anvil'
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
import type { GasSettings } from '../type/GasSettings'
import type { Network } from '../type/Network'
import MetaMask from './MetaMask'
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function configureSynpress(
currentAccountName: string
newAccountName: string
}) => metamask?.renameAccount({ currentAccountName, newAccountName }),
resetAccount: () => metamask?.resetAccount(),

// Network
getNetwork: () => metamask?.getNetwork(),
Expand Down Expand Up @@ -134,9 +136,14 @@ export default function configureSynpress(
lock: () => metamask?.lock(),
unlock: () => metamask?.unlock(),

// Others
// Toggles
toggleShowTestNetworks: () => metamask?.toggleShowTestNetworks(),
toggleDismissSecretRecoveryPhraseReminder: () => metamask?.toggleDismissSecretRecoveryPhraseReminder(),

goBackToHomePage: () => metamask?.goBackToHomePage()
// Others
goBackToHomePage: () => metamask?.goBackToHomePage(),
openSettings: () => metamask?.openSettings(),
openSidebarMenu: (menu: SettingsSidebarMenus) => metamask?.openSidebarMenu(menu)
})

return {
Expand Down
25 changes: 25 additions & 0 deletions wallets/metamask/src/cypress/support/synpressCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// ***********************************************

import type { Anvil, CreateAnvilOptions } from '@viem/anvil'
import type { SettingsSidebarMenus } from '../../selectors/pages/HomePage/settings'
import type { GasSettings } from '../../type/GasSettings'
import type { Network } from '../../type/Network'

Expand All @@ -28,6 +29,7 @@ declare global {
switchAccount(accountName: string): Chainable<void>
renameAccount(currentAccountName: string, newAccountName: string): Chainable<void>
getAccountAddress(): Chainable<string>
resetAccount(): Chainable<void>

switchNetwork(networkName: string, isTestnet?: boolean): Chainable<void>
createAnvilNode(options?: CreateAnvilOptions): Chainable<{
Expand Down Expand Up @@ -64,7 +66,12 @@ declare global {
lock(): Chainable<void>
unlock(): Chainable<void>

toggleShowTestNetworks(): Chainable<void>
toggleDismissSecretRecoveryPhraseReminder(): Chainable<void>

goBackToHomePage(): Chainable<void>
openSettings(): Chainable<void>
openSidebarMenu(menu: SettingsSidebarMenus): Chainable<void>
}
}
}
Expand Down Expand Up @@ -101,6 +108,9 @@ export default function synpressCommands() {
Cypress.Commands.add('getAccountAddress', () => {
return cy.task('getAccountAddress')
})
Cypress.Commands.add('resetAccount', () => {
return cy.task('resetAccount')
})

// Network

Expand Down Expand Up @@ -181,6 +191,15 @@ export default function synpressCommands() {
return cy.task('unlock')
})

// Toggles

Cypress.Commands.add('toggleShowTestNetworks', () => {
return cy.task('toggleShowTestNetworks')
})
Cypress.Commands.add('toggleDismissSecretRecoveryPhraseReminder', () => {
return cy.task('toggleDismissSecretRecoveryPhraseReminder')
})

// Others

Cypress.Commands.add('providePublicEncryptionKey', () => {
Expand Down Expand Up @@ -213,4 +232,10 @@ export default function synpressCommands() {
Cypress.Commands.add('goBackToHomePage', () => {
return cy.task('goBackToHomePage')
})
Cypress.Commands.add('openSettings', () => {
return cy.task('openSettings')
})
Cypress.Commands.add('openSidebarMenu', (menu: SettingsSidebarMenus) => {
return cy.task('openSidebarMenu', menu)
})
}
13 changes: 13 additions & 0 deletions wallets/metamask/test/cypress/resetAccount.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SettingsSidebarMenus } from '../../src/selectors/pages/HomePage/settings'

describe('reset the account', () => {
it('should reset the account', () => {
cy.openSettings().then(() => {
cy.openSidebarMenu(SettingsSidebarMenus.Advanced).then(() => {
cy.resetAccount().then(() => {
cy.goBackToHomePage()
})
})
})
})
})

0 comments on commit 9a6d448

Please sign in to comment.