From a24419092d1f160bbea535afb33cbf6e708ef808 Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Sat, 15 Jun 2024 07:08:42 +0100 Subject: [PATCH] fix: fix lint issues --- test/e2e/accounts/account-custom-name.spec.ts | 12 ++++++++--- test/e2e/helpers.js | 18 ++++++++++------- test/e2e/tests/account/add-account.spec.js | 15 +++++++------- test/e2e/tests/metrics/dapp-viewed.spec.js | 20 +++++++++++-------- test/e2e/tests/metrics/unlock-wallet.spec.js | 2 +- .../tests/multichain/connection-page.spec.js | 8 ++++++-- .../tests/multichain/permission-page.spec.js | 4 +++- .../tests/swap-send/swap-send-erc20.spec.ts | 5 ++--- test/e2e/tests/tokens/nft/import-nft.spec.js | 12 +++++------ 9 files changed, 57 insertions(+), 39 deletions(-) diff --git a/test/e2e/accounts/account-custom-name.spec.ts b/test/e2e/accounts/account-custom-name.spec.ts index f4516427a827..66444f82a153 100644 --- a/test/e2e/accounts/account-custom-name.spec.ts +++ b/test/e2e/accounts/account-custom-name.spec.ts @@ -7,6 +7,7 @@ import { } from '../helpers'; import FixtureBuilder from '../fixture-builder'; import { Driver } from '../webdriver/driver'; +import { Ganache } from '../seeder/ganache'; const newAccountLabel = 'Custom name'; const anotherAccountLabel = '2nd custom name'; @@ -18,9 +19,14 @@ describe('Account Custom Name Persistence', function (this: Suite) { fixtures: new FixtureBuilder().build(), title: this.test?.fullTitle(), }, - async ({ driver }: { driver: Driver, ganacheServer }) => { + async ({ + driver, + ganacheServer, + }: { + driver: Driver; + ganacheServer: Ganache; + }) => { await unlockWallet(driver); - // Change account label for existing account await driver.clickElement( '[data-testid="account-options-menu-button"]', @@ -47,7 +53,7 @@ describe('Account Custom Name Persistence', function (this: Suite) { ); await driver.fill('[placeholder="Account 2"]', anotherAccountLabel); await driver.clickElement({ text: 'Create', tag: 'button' }); - await locateAccountBalanceDOM(driver, ganacheServer); + await locateAccountBalanceDOM(driver); // Verify initial custom account label after freshly added account was active const accountOneSelector = await findAnotherAccountFromAccountList( diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 636f42738dbc..f3ab5f59d3c0 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -859,14 +859,18 @@ const TEST_SEED_PHRASE = const TEST_SEED_PHRASE_TWO = 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent'; -// Usually happens when onboarded to make sure the state is retrieved from metamaskState properly, or a success login, or after txn is made +// Usually happens when onboarded to make sure the state is retrieved from metamaskState properly, or after txn is made const locateAccountBalanceDOM = async (driver, ganacheServer) => { - const balance = await ganacheServer.getBalance(); - - await driver.waitForSelector({ - css: '[data-testid="eth-overview__primary-currency"]', - text: `${balance} ETH`, - }); + const balanceSelector = '[data-testid="eth-overview__primary-currency"]'; + if (ganacheServer) { + const balance = await ganacheServer.getBalance(); + await driver.waitForSelector({ + css: balanceSelector, + text: `${balance} ETH`, + }); + } else { + await driver.findElement(balanceSelector); + } }; const WALLET_PASSWORD = 'correct horse battery staple'; diff --git a/test/e2e/tests/account/add-account.spec.js b/test/e2e/tests/account/add-account.spec.js index 9003591c7387..fb653b0a3d67 100644 --- a/test/e2e/tests/account/add-account.spec.js +++ b/test/e2e/tests/account/add-account.spec.js @@ -6,6 +6,7 @@ const { sendTransaction, findAnotherAccountFromAccountList, locateAccountBalanceDOM, + logInWithBalanceValidation, regularDelayMs, unlockWallet, WALLET_PASSWORD, @@ -67,7 +68,7 @@ describe('Add account', function () { WALLET_PASSWORD, ); - // Check address of 1st account + // Check address of 1st accoun await locateAccountBalanceDOM(driver, ganacheServer); await driver.findElement('[data-testid="app-header-copy-button"]'); @@ -83,7 +84,7 @@ describe('Add account', function () { await driver.clickElement({ text: 'Create', tag: 'button' }); // Check address of 2nd account - await locateAccountBalanceDOM(driver, ganacheServer); + await locateAccountBalanceDOM(driver); await driver.findElement('[data-testid="app-header-copy-button"]'); // Log into the account with balance(account 1) @@ -94,7 +95,7 @@ describe('Add account', function () { 1, 'Account 1', ); - await locateAccountBalanceDOM(driver, ganacheServer); + await locateAccountBalanceDOM(driver); await driver.clickElement(accountOneSelector); await sendTransaction(driver, secondAccount, '2.8'); @@ -127,7 +128,7 @@ describe('Add account', function () { // Land in 1st account home page await driver.findElement('.home__main-view'); - await locateAccountBalanceDOM(driver, ganacheServer); + await locateAccountBalanceDOM(driver); // Check address of 1st account await driver.findElement('[data-testid="app-header-copy-button"]'); @@ -155,7 +156,7 @@ describe('Add account', function () { title: this.test.fullTitle(), }, async ({ driver, ganacheServer }) => { - await unlockWallet(driver); + await logInWithBalanceValidation(driver); await driver.clickElement('[data-testid="account-menu-icon"]'); await driver.clickElement( @@ -168,7 +169,7 @@ describe('Add account', function () { await driver.clickElement({ text: 'Create', tag: 'button' }); // Wait for 2nd account to be created - await locateAccountBalanceDOM(driver, ganacheServer); + await locateAccountBalanceDOM(driver); await driver.findElement({ css: '[data-testid="account-menu-icon"]', text: '2nd account', @@ -201,7 +202,7 @@ describe('Add account', function () { ); // Wait for 3rd account to be created - await locateAccountBalanceDOM(driver, ganacheServer); + await locateAccountBalanceDOM(driver); await driver.findElement({ css: '[data-testid="account-menu-icon"]', text: 'Account 3', diff --git a/test/e2e/tests/metrics/dapp-viewed.spec.js b/test/e2e/tests/metrics/dapp-viewed.spec.js index 25ee982c4228..f88d7b754bf5 100644 --- a/test/e2e/tests/metrics/dapp-viewed.spec.js +++ b/test/e2e/tests/metrics/dapp-viewed.spec.js @@ -6,8 +6,8 @@ const { getEventPayloads, openDapp, logInWithBalanceValidation, - locateAccountBalanceDOM, WINDOW_TITLES, + defaultGanacheOptions, } = require('../../helpers'); const FixtureBuilder = require('../../fixture-builder'); const { @@ -40,8 +40,7 @@ async function mockPermissionApprovedEndpoint(mockServer) { }); } -async function createTwoAccounts(driver, ganacheServer) { - await locateAccountBalanceDOM(driver, ganacheServer); +async function createTwoAccounts(driver) { await driver.clickElement('[data-testid="account-menu-icon"]'); await driver.clickElement( '[data-testid="multichain-account-menu-popover-action-button"]', @@ -108,10 +107,10 @@ describe('Dapp viewed Event @no-mmi', function () { .build(), title: this.test.fullTitle(), testSpecificMock: mockSegment, + ganacheOptions: defaultGanacheOptions, }, - async ({ driver, mockedEndpoint: mockedEndpoints }) => { - await unlockWallet(driver); - + async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => { + await logInWithBalanceValidation(driver, ganacheServer); await connectToDapp(driver); await waitForDappConnected(driver); const events = await getEventPayloads(driver, mockedEndpoints); @@ -143,6 +142,7 @@ describe('Dapp viewed Event @no-mmi', function () { .build(), title: this.test.fullTitle(), testSpecificMock: mockSegment, + ganacheOptions: defaultGanacheOptions, }, async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); @@ -180,6 +180,7 @@ describe('Dapp viewed Event @no-mmi', function () { .build(), title: this.test.fullTitle(), testSpecificMock: mockSegment, + ganacheOptions: defaultGanacheOptions, }, async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); @@ -222,6 +223,7 @@ describe('Dapp viewed Event @no-mmi', function () { .build(), title: this.test.fullTitle(), testSpecificMock: mockSegment, + ganacheOptions: defaultGanacheOptions, }, async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); @@ -257,12 +259,13 @@ describe('Dapp viewed Event @no-mmi', function () { }) .build(), title: this.test.fullTitle(), + ganacheOptions: defaultGanacheOptions, testSpecificMock: mockSegment, }, async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => { - await unlockWallet(driver); + await logInWithBalanceValidation(driver, ganacheServer); // create 2nd account - await createTwoAccounts(driver, ganacheServer); + await createTwoAccounts(driver); // Connect to dapp with two accounts await openDapp(driver); await driver.clickElement({ @@ -312,6 +315,7 @@ describe('Dapp viewed Event @no-mmi', function () { .build(), title: this.test.fullTitle(), testSpecificMock: mockSegment, + ganacheOptions: defaultGanacheOptions, }, async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); diff --git a/test/e2e/tests/metrics/unlock-wallet.spec.js b/test/e2e/tests/metrics/unlock-wallet.spec.js index 229033e19347..24b69c710667 100644 --- a/test/e2e/tests/metrics/unlock-wallet.spec.js +++ b/test/e2e/tests/metrics/unlock-wallet.spec.js @@ -35,7 +35,7 @@ describe('Unlock wallet', function () { title: this.test.fullTitle(), testSpecificMock: mockSegment, }, - async ({ driver, mockedEndpoint, ganacheServer}) => { + async ({ driver, mockedEndpoint, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); const events = await getEventPayloads(driver, mockedEndpoint); const sortedEvents = sortEventsByTime(events); diff --git a/test/e2e/tests/multichain/connection-page.spec.js b/test/e2e/tests/multichain/connection-page.spec.js index 353bc881fcdc..e5594de82840 100644 --- a/test/e2e/tests/multichain/connection-page.spec.js +++ b/test/e2e/tests/multichain/connection-page.spec.js @@ -1,10 +1,11 @@ const { strict: assert } = require('assert'); const { withFixtures, - unlockWallet, WINDOW_TITLES, connectToDapp, logInWithBalanceValidation, + locateAccountBalanceDOM, + defaultGanacheOptions, } = require('../../helpers'); const FixtureBuilder = require('../../fixture-builder'); @@ -18,6 +19,7 @@ describe('Connections page', function () { dapp: true, fixtures: new FixtureBuilder().build(), title: this.test.fullTitle(), + ganacheOptions: defaultGanacheOptions, }, async ({ driver, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); @@ -90,12 +92,14 @@ describe('Connections page', function () { }, ); }); + it('should connect more accounts when already connected to a dapp', async function () { await withFixtures( { dapp: true, fixtures: new FixtureBuilder().build(), title: this.test.fullTitle(), + ganacheOptions: defaultGanacheOptions, }, async ({ driver, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); @@ -133,7 +137,7 @@ describe('Connections page', function () { ); await driver.fill('[placeholder="Account 3"]', accountLabel3); await driver.clickElement({ text: 'Create', tag: 'button' }); - await logInWithBalanceValidation(driver, ganacheServer); + await locateAccountBalanceDOM(driver); await driver.clickElement( '[data-testid ="account-options-menu-button"]', ); diff --git a/test/e2e/tests/multichain/permission-page.spec.js b/test/e2e/tests/multichain/permission-page.spec.js index 3198d719f293..5ae3f71b6046 100644 --- a/test/e2e/tests/multichain/permission-page.spec.js +++ b/test/e2e/tests/multichain/permission-page.spec.js @@ -1,10 +1,10 @@ const { strict: assert } = require('assert'); const { withFixtures, - unlockWallet, WINDOW_TITLES, connectToDapp, logInWithBalanceValidation, + defaultGanacheOptions, } = require('../../helpers'); const FixtureBuilder = require('../../fixture-builder'); @@ -15,6 +15,7 @@ describe('Permissions Page', function () { dapp: true, fixtures: new FixtureBuilder().build(), title: this.test.fullTitle(), + ganacheOptions: defaultGanacheOptions, }, async ({ driver, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); @@ -50,6 +51,7 @@ describe('Permissions Page', function () { dapp: true, fixtures: new FixtureBuilder().build(), title: this.test.fullTitle(), + ganacheOptions: defaultGanacheOptions, }, async ({ driver, ganacheServer }) => { await logInWithBalanceValidation(driver, ganacheServer); diff --git a/test/e2e/tests/swap-send/swap-send-erc20.spec.ts b/test/e2e/tests/swap-send/swap-send-erc20.spec.ts index 10b18592f42b..e8b416b9604e 100644 --- a/test/e2e/tests/swap-send/swap-send-erc20.spec.ts +++ b/test/e2e/tests/swap-send/swap-send-erc20.spec.ts @@ -4,6 +4,7 @@ import { openActionMenuAndStartSendFlow, logInWithBalanceValidation, } from '../../helpers'; +import { Driver } from '../../webdriver/driver'; import type { Ganache } from '../../seeder/ganache'; import { NATIVE_TOKEN_SYMBOL, @@ -27,9 +28,7 @@ describe('Swap-Send ERC20', function () { driver, ganacheServer, }: { - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - driver: any; + driver: Driver; ganacheServer: Ganache; }) => { const swapSendPage = new SwapSendPage(driver); diff --git a/test/e2e/tests/tokens/nft/import-nft.spec.js b/test/e2e/tests/tokens/nft/import-nft.spec.js index cbb5295c9433..ed3d9056e599 100644 --- a/test/e2e/tests/tokens/nft/import-nft.spec.js +++ b/test/e2e/tests/tokens/nft/import-nft.spec.js @@ -109,24 +109,22 @@ describe('Import NFT', function () { ); await driver.clickElement({ text: 'Add a new account', tag: 'button' }); - // set account name - await driver.fill('[placeholder="Account 2"]', '2nd account'); - await driver.delay(400); + // By clicking creating button without filling in the account name + // the default name would be set as Account 2 await driver.clickElement({ text: 'Create', tag: 'button' }); await driver.isElementPresent({ tag: 'span', - text: '2nd account', + text: 'Account 2', }); - const accountOneSelector = await findAnotherAccountFromAccountList( driver, 1, 'Account 1', ); - await locateAccountBalanceDOM(driver, ganacheServer); - await driver.clickElement(accountOneSelector); + await driver.clickElement(accountOneSelector); + await locateAccountBalanceDOM(driver, ganacheServer); const nftIsStillDisplayed = await driver.isElementPresentAndVisible({ css: 'h5', text: 'TestDappNFTs',