diff --git a/test/e2e/swaps/shared.js b/test/e2e/swaps/shared.js new file mode 100644 index 000000000000..34464c573e8f --- /dev/null +++ b/test/e2e/swaps/shared.js @@ -0,0 +1,52 @@ +const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: 25000000000000000000, + }, + ], +}; + +const defaultFixturesOptions = { + fixtures: 'special-settings', + failOnConsoleError: false, + ganacheOptions, +}; + +const loadSwaps = async (driver) => { + await driver.navigate(); + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + await driver.clickElement( + '.wallet-overview__buttons .icon-button:nth-child(3)', + ); +}; + +const buildQuote = async (driver, options) => { + await driver.clickElement( + '[class*="dropdown-search-list"] + div[class*="MuiFormControl-root MuiTextField-root"]', + ); + await driver.fill('input[placeholder*="0"]', options.amount); + await driver.clickElement( + '[class="dropdown-search-list__closed-primary-label dropdown-search-list__select-default"]', + ); + await driver.wait(async () => { + const tokens = await driver.findElements('.searchable-item-list__item'); + return tokens.length > 1; + }, 10000); + await driver.clickElement('.searchable-item-list__labels'); + await driver.clickElement('.dropdown-input-pair__to'); + await driver.clickElement('[placeholder="Search name or paste address"]'); + await driver.fill( + '[placeholder="Search name or paste address"]', + options.swapTo, + ); + await driver.clickElement('.searchable-item-list__primary-label'); +}; + +module.exports = { + defaultFixturesOptions, + loadSwaps, + buildQuote, +}; diff --git a/test/e2e/tests/swap-eth.spec.js b/test/e2e/swaps/swap-eth.spec.js similarity index 59% rename from test/e2e/tests/swap-eth.spec.js rename to test/e2e/swaps/swap-eth.spec.js index 771a5e050ba4..db967a933170 100644 --- a/test/e2e/tests/swap-eth.spec.js +++ b/test/e2e/swaps/swap-eth.spec.js @@ -1,57 +1,21 @@ const { strict: assert } = require('assert'); + const { withFixtures } = require('../helpers'); +const { defaultFixturesOptions, loadSwaps, buildQuote } = require('./shared'); describe('Swap Eth for another Token', function () { - const ganacheOptions = { - accounts: [ - { - secretKey: - '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', - balance: 25000000000000000000, - }, - ], - }; it('Completes a Swap between Eth and Matic', async function () { await withFixtures( { - fixtures: 'special-settings', - ganacheOptions, + ...defaultFixturesOptions, title: this.test.title, - failOnConsoleError: false, - driverOptions: { - timeOut: 20000, - }, }, async ({ driver }) => { - await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); - await driver.clickElement( - '.wallet-overview__buttons .icon-button:nth-child(3)', - ); - await driver.clickElement( - '[class*="dropdown-search-list"] + div[class*="MuiFormControl-root MuiTextField-root"]', - ); - await driver.fill('input[placeholder*="0"]', '2'); - await driver.clickElement( - '[class*="dropdown-search-list"] + div[class*="MuiFormControl-root MuiTextField-root"]', - ); - await driver.clickElement( - '[class="dropdown-search-list__closed-primary-label dropdown-search-list__select-default"]', - ); - await driver.clickElement( - '[placeholder="Search name or paste address"]', - ); - await driver.fill( - '[placeholder="Search name or paste address"]', - 'DAI', - ); - await driver.waitForSelector( - '[class="searchable-item-list__primary-label"]', - ); - await driver.clickElement( - '[class="searchable-item-list__primary-label"]', - ); + await loadSwaps(driver); + await buildQuote(driver, { + amount: 2, + swapTo: 'DAI', + }); await driver.clickElement({ text: 'Review swap', tag: 'button' }); await driver.waitForSelector('[class*="box--align-items-center"]'); const estimatedEth = await driver.waitForSelector({ diff --git a/test/e2e/tests/swaps-notifications.spec.js b/test/e2e/swaps/swaps-notifications.spec.js similarity index 75% rename from test/e2e/tests/swaps-notifications.spec.js rename to test/e2e/swaps/swaps-notifications.spec.js index 40f68ed1c10f..c5db9605c993 100644 --- a/test/e2e/tests/swaps-notifications.spec.js +++ b/test/e2e/swaps/swaps-notifications.spec.js @@ -1,55 +1,9 @@ const { strict: assert } = require('assert'); const { withFixtures } = require('../helpers'); +const { defaultFixturesOptions, loadSwaps, buildQuote } = require('./shared'); describe('Swaps - notifications', function () { - const ganacheOptions = { - accounts: [ - { - secretKey: - '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', - balance: 25000000000000000000, - }, - ], - }; - - const defaultFixturesOptions = { - fixtures: 'special-settings', - failOnConsoleError: false, - ganacheOptions, - }; - - const loadSwaps = async (driver) => { - await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); - await driver.clickElement( - '.wallet-overview__buttons .icon-button:nth-child(3)', - ); - }; - - const buildQuote = async (driver, options) => { - await driver.clickElement( - '[class*="dropdown-search-list"] + div[class*="MuiFormControl-root MuiTextField-root"]', - ); - await driver.fill('input[placeholder*="0"]', options.amount); - await driver.clickElement( - '[class="dropdown-search-list__closed-primary-label dropdown-search-list__select-default"]', - ); - await driver.wait(async () => { - const tokens = await driver.findElements('.searchable-item-list__item'); - return tokens.length > 1; - }, 10000); - await driver.clickElement('.searchable-item-list__labels'); - await driver.clickElement('.dropdown-input-pair__to'); - await driver.clickElement('[placeholder="Search name or paste address"]'); - await driver.fill( - '[placeholder="Search name or paste address"]', - options.swapTo, - ); - await driver.clickElement('.searchable-item-list__primary-label'); - }; - it('tests notifications for verified token on 1 source and price difference', async function () { await withFixtures( {