From f32d57b40f4e6ca997d736606231818221d1b58b Mon Sep 17 00:00:00 2001 From: matstyler Date: Mon, 16 Sep 2024 00:04:58 +0200 Subject: [PATCH] feat: Lock API for Cypress --- wallets/metamask/src/cypress/MetaMask.ts | 18 ++++++++++++++++++ .../metamask/src/cypress/configureSynpress.ts | 6 +++++- .../src/cypress/support/synpressCommands.ts | 10 ++++++++++ wallets/metamask/test/cypress/lock.cy.ts | 5 +++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 wallets/metamask/test/cypress/lock.cy.ts diff --git a/wallets/metamask/src/cypress/MetaMask.ts b/wallets/metamask/src/cypress/MetaMask.ts index 16cded469..bc2abb71d 100644 --- a/wallets/metamask/src/cypress/MetaMask.ts +++ b/wallets/metamask/src/cypress/MetaMask.ts @@ -316,4 +316,22 @@ export default class MetaMask { return false }) } + + // 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 + } } diff --git a/wallets/metamask/src/cypress/configureSynpress.ts b/wallets/metamask/src/cypress/configureSynpress.ts index 464190cf6..81be45bff 100644 --- a/wallets/metamask/src/cypress/configureSynpress.ts +++ b/wallets/metamask/src/cypress/configureSynpress.ts @@ -120,7 +120,11 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr rejectTransaction: () => metamask?.rejectTransaction(), confirmTransactionAndWaitForMining: () => metamask?.confirmTransactionAndWaitForMining(), openTransactionDetails: (txIndex: number) => metamask?.openTransactionDetails(txIndex), - closeTransactionDetails: () => metamask?.closeTransactionDetails() + closeTransactionDetails: () => metamask?.closeTransactionDetails(), + + // Lock/Unlock + lock: () => metamask?.lock(), + unlock: () => metamask?.unlock() }) return { diff --git a/wallets/metamask/src/cypress/support/synpressCommands.ts b/wallets/metamask/src/cypress/support/synpressCommands.ts index 089863af3..68c048dff 100644 --- a/wallets/metamask/src/cypress/support/synpressCommands.ts +++ b/wallets/metamask/src/cypress/support/synpressCommands.ts @@ -57,6 +57,9 @@ declare global { confirmTransactionAndWaitForMining(): Chainable openTransactionDetails(txIndex: number): Chainable closeTransactionDetails(): Chainable + + lock(): Chainable + unlock(): Chainable } } } @@ -184,4 +187,11 @@ export default function synpressCommands() { Cypress.Commands.add('closeTransactionDetails', () => { return cy.task('closeTransactionDetails') }) + + Cypress.Commands.add('lock', () => { + return cy.task('lock') + }) + Cypress.Commands.add('unlock', () => { + return cy.task('unlock') + }) } diff --git a/wallets/metamask/test/cypress/lock.cy.ts b/wallets/metamask/test/cypress/lock.cy.ts new file mode 100644 index 000000000..dbd67aed2 --- /dev/null +++ b/wallets/metamask/test/cypress/lock.cy.ts @@ -0,0 +1,5 @@ +it('should lock & unlock the wallet without any error', () => { + cy.lock().then(() => { + cy.unlock() + }) +})