1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-13 05:07:12 +01:00
metamask-extension/test/e2e/tests/swap-eth.spec.js
Peter Yinusa 0b4532ec1b
E2e test fixtures (#16061)
* remove state.json files

* move file

* Update Readme

* Create fixture builder

* load test fixture

* remove redundant method

* update snap tests

* update stats tests

* update extension tests

* update extension tests

* Update fixture data

* snap test dapp connection

* Update fixture data

* add onboarding fixture

* use onboarding fixture

* reuse import account vault

* remove unnecessary use of class

* use fixture builder in new tests

* switch to function

* update default fixture

* update default fixture

* update test

* update 1559 test fixttures

* update 1559 test fixtures

* update 1559 test fixtures

* dismiss 3box whats new

* remove redundant code

* move docs

* remove unused code

* token detection

* use default timeout

* remove redundant code

* Update fixture builder

hide `Protect your funds` dialog
remove browser environment
remove default network details
hide dismiss seed backup reminder
recursively merges fixture data

* add token to tokencontroller

* remove network details

* add missing identities to preference controller

* remove duplicate properties

* update bip-32 to use fixturebuilder

* alphabetise snap permissions

* update get snaps to use fixturebuilder

* Update test-snap-bip-32.spec.js

wait for window

* add popular network state

* update test

* lint
2022-10-28 09:42:12 +01:00

103 lines
3.9 KiB
JavaScript

const { strict: assert } = require('assert');
const { withFixtures } = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
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: new FixtureBuilder().build(),
ganacheOptions,
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 driver.clickElement({ text: 'Review swap', tag: 'button' });
await driver.waitForSelector('[class*="box--align-items-center"]');
const estimatedEth = await driver.waitForSelector({
css: '[class*="box--align-items-center"]',
text: 'Estimated gas fee',
});
assert.equal(await estimatedEth.getText(), 'Estimated gas fee');
await driver.waitForSelector(
'[class="exchange-rate-display main-quote-summary__exchange-rate-display"]',
);
await driver.waitForSelector(
'[class="fee-card__info-tooltip-container"]',
);
await driver.waitForSelector({
css: '[class="countdown-timer__time"]',
text: '0:24',
});
await driver.clickElement({ text: 'Swap', tag: 'button' });
const sucessfulTransactionMessage = await driver.waitForSelector({
css: '[class="awaiting-swap__header"]',
text: 'Transaction complete',
});
assert.equal(
await sucessfulTransactionMessage.getText(),
'Transaction complete',
);
const sucessfulTransactionToken = await driver.waitForSelector({
css: '[class="awaiting-swap__amount-and-symbol"]',
text: 'DAI',
});
assert.equal(await sucessfulTransactionToken.getText(), 'DAI');
await driver.clickElement({ text: 'Close', tag: 'button' });
await driver.clickElement('[data-testid="home__activity-tab"]');
const swaptotal = await driver.waitForSelector({
css: '[class="transaction-list-item__primary-currency"]',
text: '-2 TESTETH',
});
assert.equal(await swaptotal.getText(), '-2 TESTETH');
const swaptotaltext = await driver.waitForSelector({
css: '[class="list-item__title"]',
text: 'Swap TESTETH to DAI',
});
assert.equal(await swaptotaltext.getText(), 'Swap TESTETH to DAI');
},
);
});
});