Skip to content

Commit

Permalink
feat: confirm/reject permission to approve all
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed May 4, 2023
1 parent 6aadbfc commit 598acb6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
26 changes: 26 additions & 0 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions pages/metamask/notification-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,6 +20,8 @@ module.exports.notificationPageElements = {
allowToSpendButton,
rejectToSpendButton,
selectAllCheckbox,
approveWarningToSpendButton,
rejectWarningToSpendButton,
};

const confirmSignatureRequestButton = `${notificationPage} .request-signature__footer__sign-button`;
Expand Down
2 changes: 2 additions & 0 deletions plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down
12 changes: 12 additions & 0 deletions support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ declare namespace Cypress {
* cy.confirmMetamaskPermissionToSpend('999999999')
*/
confirmMetamaskPermissionToSpend(spendLimit?: string): Chainable<Subject>;
/**
* Confirm metamask permission to access all elements (example: collectibles)
* @example
* cy.confirmMetamaskPermisionToApproveAll()
*/
confirmMetamaskPermisionToApproveAll(): Chainable<Subject>;
/**
* Reject metamask permission to access all elements (example: collectibles)
* @example
* cy.rejectMetamaskPermisionToApproveAll()
*/
rejectMetamaskPermisionToApproveAll(): Chainable<Subject>;
/**
* Reject metamask permission to spend asset
* @example
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/specs/metamask-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 598acb6

Please sign in to comment.