Skip to content

Commit

Permalink
feat: Lock API for Cypress (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler authored Sep 16, 2024
1 parent 29efce3 commit 675f983
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
18 changes: 18 additions & 0 deletions wallets/metamask/src/cypress/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,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
}
}
6 changes: 5 additions & 1 deletion wallets/metamask/src/cypress/configureSynpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions wallets/metamask/src/cypress/support/synpressCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ declare global {
confirmTransactionAndWaitForMining(): Chainable<void>
openTransactionDetails(txIndex: number): Chainable<void>
closeTransactionDetails(): Chainable<void>

lock(): Chainable<void>
unlock(): Chainable<void>
}
}
}
Expand Down Expand Up @@ -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')
})
}
5 changes: 5 additions & 0 deletions wallets/metamask/test/cypress/lock.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it('should lock & unlock the wallet without any error', () => {
cy.lock().then(() => {
cy.unlock()
})
})

0 comments on commit 675f983

Please sign in to comment.