diff --git a/test/e2e/tests/multiple-transactions.spec.js b/test/e2e/tests/multiple-transactions.spec.js index bc29c3308..d18120575 100644 --- a/test/e2e/tests/multiple-transactions.spec.js +++ b/test/e2e/tests/multiple-transactions.spec.js @@ -1,7 +1,13 @@ -const { convertToHexValue, withFixtures } = require('../helpers'); +const assert = require('assert'); +const { + convertToHexValue, + withFixtures, + openDapp, + regularDelayMs, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); -describe('Confirm transactions', function () { +describe('Multiple transactions', function () { const ganacheOptions = { hardfork: 'london', accounts: [ @@ -12,11 +18,13 @@ describe('Confirm transactions', function () { }, ], }; - it('should be able to confirm multiple transactions', async function () { + + it('creates multiple queued transactions, then confirms', async function () { await withFixtures( { + dapp: true, fixtures: new FixtureBuilder() - .withTransactionControllerMultipleTransactions() + .withPermissionControllerConnectedToTestDapp() .build(), ganacheOptions, title: this.test.title, @@ -26,42 +34,58 @@ describe('Confirm transactions', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - // confirm multiple transactions - await driver.waitForSelector({ - text: 'Reject 4 transactions', - tag: 'a', + // initiates a transaction from the dapp + await openDapp(driver); + // creates first transaction + await driver.clickElement({ + text: 'Send EIP 1559 Transaction', + tag: 'button', }); - await driver.clickElement({ text: 'Confirm', tag: 'button' }); - await driver.waitForSelector({ - text: 'Reject 3 transactions', - tag: 'a', + await driver.waitUntilXWindowHandles(3); + const windowHandles = await driver.getAllWindowHandles(); + const extensionTab = windowHandles[0]; + const dApp = windowHandles[1]; + const confirmation = windowHandles[2]; + + await driver.switchToWindow(dApp); + + // creates second transaction + await driver.clickElement({ + text: 'Send EIP 1559 Transaction', + tag: 'button', }); - await driver.clickElement({ text: 'Confirm', tag: 'button' }); + await driver.switchToWindow(confirmation); + + // confirms second transaction await driver.waitForSelector({ text: 'Reject 2 transactions', tag: 'a', }); await driver.clickElement({ text: 'Confirm', tag: 'button' }); - await driver.waitForElementNotPresent('.loading-overlay__spinner'); + // confirms first transaction await driver.clickElement({ text: 'Confirm', tag: 'button' }); + await driver.waitUntilXWindowHandles(2); + await driver.switchToWindow(extensionTab); + await driver.delay(regularDelayMs); await driver.clickElement('[data-testid="home__activity-tab"]'); - await driver.wait(async () => { - const confirmedTxes = await driver.findElements( - '.transaction-list__completed-transactions .transaction-list-item', - ); - return confirmedTxes.length === 4; - }, 10000); + + const confirmedTxes = await driver.findElements( + '.transaction-list__completed-transactions .transaction-list-item', + ); + + assert.equal(confirmedTxes.length, 2); }, ); }); - it('should be able to reject multiple transactions', async function () { + it('creates multiple queued transactions, then rejects', async function () { await withFixtures( { + dapp: true, fixtures: new FixtureBuilder() - .withTransactionControllerMultipleTransactions() + .withPermissionControllerConnectedToTestDapp() .build(), ganacheOptions, title: this.test.title, @@ -71,27 +95,50 @@ describe('Confirm transactions', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - // confirm multiple transactions - await driver.waitForSelector({ - text: 'Reject 4 transactions', - tag: 'a', + // initiates a transaction from the dapp + await openDapp(driver); + // creates first transaction + await driver.clickElement({ + text: 'Send EIP 1559 Transaction', + tag: 'button', }); - await driver.clickElement({ text: 'Reject', tag: 'button' }); - await driver.waitForSelector({ - text: 'Reject 3 transactions', - tag: 'a', + await driver.waitUntilXWindowHandles(3); + const windowHandles = await driver.getAllWindowHandles(); + const extension = windowHandles[0]; + const confirmation = windowHandles[2]; + await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles); + + // creates second transaction + await driver.clickElement({ + text: 'Send EIP 1559 Transaction', + tag: 'button', }); - await driver.clickElement({ text: 'Reject', tag: 'button' }); + await driver.switchToWindow(confirmation); + + // rejects second transaction await driver.waitForSelector({ text: 'Reject 2 transactions', tag: 'a', }); await driver.clickElement({ text: 'Reject', tag: 'button' }); - await driver.waitForElementNotPresent('.loading-overlay__spinner'); + // rejects first transaction await driver.clickElement({ text: 'Reject', tag: 'button' }); - await driver.waitForSelector('[data-testid="home__activity-tab"]'); + await driver.waitUntilXWindowHandles(2); + await driver.switchToWindow(extension); + await driver.delay(regularDelayMs); + await driver.clickElement('[data-testid="home__activity-tab"]'); + + const isTransactionListEmpty = await driver.isElementPresentAndVisible( + '.transaction-list__empty-text', + ); + assert.equal(isTransactionListEmpty, true); + + // should not be present + await driver.assertElementNotPresent( + '.transaction-list__completed-transactions .transaction-list-item', + ); }, ); });