Skip to content

Commit

Permalink
Add functions for opening and closing tx details
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Sep 7, 2023
1 parent a3f8fcc commit 28b054f
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
53 changes: 53 additions & 0 deletions commands/metamask.js
Expand Up @@ -1254,6 +1254,59 @@ const metamask = {
);
return true;
},
async openTransactionDetails(txIndex) {
await switchToMetamaskIfNotActive();
await playwright
.metamaskWindow()
.locator(mainPageElements.tabs.activityButton)
.click();

let visibleTxsCount = await playwright
.metamaskWindow()
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > div`,
)
.count();

while (txIndex >= visibleTxsCount) {
await playwright.metamaskWindow().getByText('View more').click();

visibleTxsCount = await playwright
.metamaskWindow()
.locator(
`${mainPageElements.activityTab.completedTransactionsList} > div`,
)
.count();
}

if (txIndex >= visibleTxsCount) {
throw new Error(
`Transaction with index ${txIndex} is not found. There are only ${visibleTxsCount} transactions.`,
);
}

await playwright
.metamaskWindow()
.locator(mainPageElements.activityTab.completedTransaction(txIndex))
.click();

const isPopupVisible = await playwright
.metamaskWindow()
.locator(mainPageElements.popup.container)
.isVisible();

if (!isPopupVisible) {
throw new Error('Transaction details popup is not visible.');
}

return true;
},
async closeTransactionDetailsPopup() {
await switchToMetamaskIfNotActive();
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
},
async confirmEncryptionPublicKeyRequest() {
const notificationPage = await playwright.switchToMetamaskNotification();
await playwright.waitAndClick(
Expand Down
16 changes: 16 additions & 0 deletions docs/synpress-commands.md
Expand Up @@ -384,6 +384,22 @@ Reject metamask transaction.
rejectMetamaskTransaction(): Chainable<Subject>;
```

#### `cy.openMetamaskTransactionDetails()`

Open metamask transaction details based on the index of the transaction in the list on the activity tab.

```ts
openMetamaskTransactionDetails(txIndex: number): Chainable<Subject>;
```

#### `cy.closeMetamaskTransactionDetailsPopup()`

Close currently open transaction details popup.

```ts
closeMetamaskTransactionDetailsPopup(): Chainable<Subject>;
```

#### `cy.allowMetamaskToAddNetwork()`

Allow site to add new network in metamask.
Expand Down
3 changes: 3 additions & 0 deletions pages/metamask/main-page.js
Expand Up @@ -24,10 +24,13 @@ const tabs = {
const transactionList = '.transaction-list__transactions';
const pendingTransactionsList = `${transactionList} .transaction-list__pending-transactions`;
const completedTransactionsList = `${transactionList} .transaction-list__completed-transactions`;
const completedTransaction = txIndex =>
`${completedTransactionsList} > div:nth-child(${txIndex + 1})`;
const activityTab = {
transactionList,
pendingTransactionsList,
completedTransactionsList,
completedTransaction,
unconfirmedTransaction: `${pendingTransactionsList} .transaction-list-item--unconfirmed`,
confirmedTransaction: `${completedTransactionsList} .transaction-list-item`,
};
Expand Down
2 changes: 2 additions & 0 deletions plugins/index.js
Expand Up @@ -111,6 +111,8 @@ module.exports = (on, config) => {
confirmMetamaskTransactionAndWaitForMining:
metamask.confirmTransactionAndWaitForMining,
rejectMetamaskTransaction: metamask.rejectTransaction,
openMetamaskTransactionDetails: metamask.openTransactionDetails,
closeMetamaskTransactionDetailsPopup: metamask.closeTransactionDetailsPopup,
allowMetamaskToAddNetwork: async ({ waitForEvent }) =>
await metamask.allowToAddNetwork({ waitForEvent }),
rejectMetamaskToAddNetwork: metamask.rejectToAddNetwork,
Expand Down
8 changes: 8 additions & 0 deletions support/commands.js
Expand Up @@ -207,6 +207,14 @@ Cypress.Commands.add('rejectMetamaskTransaction', () => {
return cy.task('rejectMetamaskTransaction');
});

Cypress.Commands.add('openMetamaskTransactionDetails', txIndex => {
return cy.task('openMetamaskTransactionDetails', txIndex);
});

Cypress.Commands.add('closeMetamaskTransactionDetailsPopup', () => {
return cy.task('closeMetamaskTransactionDetailsPopup');
});

Cypress.Commands.add('rejectMetamaskPermisionToApproveAll', () => {
return cy.task('rejectMetamaskPermisionToApproveAll');
});
Expand Down
13 changes: 13 additions & 0 deletions support/index.d.ts
Expand Up @@ -364,6 +364,19 @@ declare namespace Cypress {
* cy.rejectMetamaskTransaction()
*/
rejectMetamaskTransaction(): Chainable<boolean>;
/**
* Open metamask transaction details based on the index of the transaction in the list on the activity tab
* @example
* cy.openMetamaskTransactionDetails(0)
* cy.openMetamaskTransactionDetails(1)
*/
openMetamaskTransactionDetails(txIndex: number): Chainable<Subject>;
/**
* Close metamask transaction details popup
* @example
* cy.closeMetamaskTransactionDetailsPopup()
*/
closeMetamaskTransactionDetailsPopup(): Chainable<boolean>;
/**
* Allow site to add new network in metamask
* @example
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/specs/metamask-spec.js
Expand Up @@ -423,6 +423,24 @@ describe('Metamask', () => {
expect(txData.confirmed).to.be.true;
});
});
it(`openMetamaskTransactionDetails should open transaction details popup`, () => {
// Cannot be tested further with Cypress 😔
cy.openMetamaskTransactionDetails(0).then(
opened => expect(opened).to.be.true,
);
});
it(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => {
cy.closeMetamaskTransactionDetailsPopup().then(
closed => expect(closed).to.be.true,
);
});
it(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => {
// Cannot be tested further with Cypress 😔
cy.openMetamaskTransactionDetails(14);
cy.closeMetamaskTransactionDetailsPopup().then(
closed => expect(closed).to.be.true,
);
});
it(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => {
cy.get('#createToken').click();
cy.confirmMetamaskTransaction().then(txData => {
Expand Down

0 comments on commit 28b054f

Please sign in to comment.