diff --git a/commands/metamask.js b/commands/metamask.js index b32c62856..105c96ab8 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -1077,6 +1077,32 @@ const metamask = { ); return true; }, + async confirmPermisionToApproveAll() { + const notificationPage = await playwright.switchToMetamaskNotification(); + await playwright.waitAndClick( + notificationPageElements.allowToSpendButton, + notificationPage, + ); + await playwright.waitAndClick( + notificationPageElements.approveWarningToSpendButton, + notificationPage, + { waitForEvent: 'close' }, + ); + return true; + }, + async rejectPermisionToApproveAll() { + const notificationPage = await playwright.switchToMetamaskNotification(); + await playwright.waitAndClick( + notificationPageElements.allowToSpendButton, + notificationPage, + ); + await playwright.waitAndClick( + notificationPageElements.rejectWarningToSpendButton, + notificationPage, + { waitForEvent: 'close' }, + ); + return true; + }, async allowToAddNetwork({ waitForEvent } = {}) { const notificationPage = await playwright.switchToMetamaskNotification(); if (waitForEvent) { diff --git a/pages/metamask/notification-page.js b/pages/metamask/notification-page.js index 8c7ca6e7d..55fb461fd 100644 --- a/pages/metamask/notification-page.js +++ b/pages/metamask/notification-page.js @@ -7,6 +7,9 @@ const customSpendingLimitInput = `${notificationPage} [data-testid="custom-spend const allowToSpendButton = `${notificationPage} [data-testid="page-container-footer-next"]`; const rejectToSpendButton = `${notificationPage} [data-testid="page-container-footer-cancel"]`; const selectAllCheckbox = `${notificationPage} .choose-account-list__header-check-box`; +const approveWarningToSpendButton = `${notificationPage} .set-approval-for-all-warning__footer__approve-button`; +const rejectWarningToSpendButton = `${notificationPage} .btn-secondary.set-approval-for-all-warning__footer__cancel-button`; + module.exports.notificationPageElements = { notificationPage, notificationAppContent, @@ -17,6 +20,8 @@ module.exports.notificationPageElements = { allowToSpendButton, rejectToSpendButton, selectAllCheckbox, + approveWarningToSpendButton, + rejectWarningToSpendButton, }; const confirmSignatureRequestButton = `${notificationPage} .request-signature__footer__sign-button`; diff --git a/plugins/index.js b/plugins/index.js index 07411d5ff..a9aba2636 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -218,6 +218,8 @@ module.exports = (on, config) => { const rejected = await metamask.rejectPermissionToSpend(); return rejected; }, + confirmMetamaskPermisionToApproveAll: metamask.confirmPermisionToApproveAll, + rejectMetamaskPermisionToApproveAll: metamask.rejectPermisionToApproveAll, acceptMetamaskAccess: async options => { const accepted = await metamask.acceptAccess(options); return accepted; diff --git a/support/commands.js b/support/commands.js index ff65c56b1..9ad89749a 100644 --- a/support/commands.js +++ b/support/commands.js @@ -192,6 +192,14 @@ Cypress.Commands.add('rejectMetamaskTransaction', () => { return cy.task('rejectMetamaskTransaction'); }); +Cypress.Commands.add('rejectMetamaskPermisionToApproveAll', () => { + return cy.task('rejectMetamaskPermisionToApproveAll'); +}); + +Cypress.Commands.add('confirmMetamaskPermisionToApproveAll', () => { + return cy.task('confirmMetamaskPermisionToApproveAll'); +}); + Cypress.Commands.add('allowMetamaskToAddNetwork', waitForEvent => { return cy.task('allowMetamaskToAddNetwork', { waitForEvent }); }); diff --git a/support/index.d.ts b/support/index.d.ts index 08bba15c0..9c176d11d 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -247,6 +247,18 @@ declare namespace Cypress { * cy.confirmMetamaskPermissionToSpend('999999999') */ confirmMetamaskPermissionToSpend(spendLimit?: string): Chainable; + /** + * Confirm metamask permission to access all elements (example: collectibles) + * @example + * cy.confirmMetamaskPermisionToApproveAll() + */ + confirmMetamaskPermisionToApproveAll(): Chainable; + /** + * Reject metamask permission to access all elements (example: collectibles) + * @example + * cy.rejectMetamaskPermisionToApproveAll() + */ + rejectMetamaskPermisionToApproveAll(): Chainable; /** * Reject metamask permission to spend asset * @example diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/metamask-spec.js index 782942798..73030b159 100644 --- a/tests/e2e/specs/metamask-spec.js +++ b/tests/e2e/specs/metamask-spec.js @@ -103,6 +103,22 @@ describe('Metamask', () => { expect(network.isTestnet).to.be.true; }); }); + it(`rejectMetamaskPermisionToApproveAll should reject permission to approve all collectibles upon warning`, () => { + cy.get('#deployCollectiblesButton').click(); + cy.confirmMetamaskTransaction(); + cy.get('#mintButton').click(); + cy.confirmMetamaskTransaction(); + cy.get('#setApprovalForAllButton').click(); + cy.rejectMetamaskPermisionToApproveAll().then(rejected => { + expect(rejected).to.be.true; + }); + }); + it(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all collectibles`, () => { + cy.get('#setApprovalForAllButton').click(); + cy.confirmMetamaskPermisionToApproveAll().then(confirmed => { + expect(confirmed).to.be.true; + }); + }); it(`changeMetamaskNetwork should change network using custom network name`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil').then(networkChanged => {