From a66eb73c1f2b740fd052940edcd7f75fc335e5e1 Mon Sep 17 00:00:00 2001 From: Abdurrahman SASTIM Date: Wed, 23 Oct 2024 14:54:07 +0200 Subject: [PATCH] test: fix Speculos add account test --- apps/ledger-live-mobile/e2e/helpers.ts | 2 +- .../e2e/page/accounts/account.page.ts | 2 +- .../e2e/page/accounts/addAccount.drawer.ts | 17 ++++++++--- .../e2e/specs/speculos/addAccount.spec.ts | 30 ++++++++++++++----- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/apps/ledger-live-mobile/e2e/helpers.ts b/apps/ledger-live-mobile/e2e/helpers.ts index afd24499dfba..1bed62603015 100644 --- a/apps/ledger-live-mobile/e2e/helpers.ts +++ b/apps/ledger-live-mobile/e2e/helpers.ts @@ -176,7 +176,7 @@ export async function launchSpeculos(appName: string, proxyPort: number) { setEnv("SPECULOS_PID_OFFSET", speculosPidOffset); const testName = expect.getState().testPath || "unknown"; - const speculosDevice = await startSpeculos(testName, specs[appName]); + const speculosDevice = await startSpeculos(testName, specs[appName.replace(/ /g, "_")]); invariant(speculosDevice, "[E2E Setup] Speculos not started"); const speculosApiPort = speculosDevice.ports.apiPort; diff --git a/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts b/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts index f05bc02ef832..162ce01c330c 100644 --- a/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts +++ b/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts @@ -16,7 +16,7 @@ export default class AccountPage { accountAssetId = (assetName: string) => `account-assets-${assetName}`; async waitForAccountPageToLoad(assetName: string) { - await waitForElementById(this.accountTitleId(assetName)); + await waitForElementById(this.accountTitleId(assetName.toLowerCase())); } async expectAccountBalanceVisible() { diff --git a/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts b/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts index ccc16068d54c..4fe6fb047e88 100644 --- a/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts +++ b/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts @@ -1,12 +1,21 @@ import { expect } from "detox"; -import { getElementById, openDeeplink, tapById, waitForElementById } from "../../helpers"; +import { + getElementById, + openDeeplink, + scrollToId, + tapById, + waitForElementById, +} from "../../helpers"; import { capitalize } from "../../models/currencies"; +import { getEnv } from "@ledgerhq/live-env"; const baseLink = "add-account"; +const isMock = getEnv("MOCK"); export default class AddAccountDrawer { - accountCardId = (id: string) => getElementById(`account-card-${id}`); - accountId = (currency: string, index: number) => `mock:1:${currency}:MOCK_${currency}_${index}:`; + accountCardId = (id: string | RegExp) => getElementById(new RegExp(`account-card-${id}`)); + accountId = (currency: string, index: number) => + isMock ? `mock:1:${currency}:MOCK_${currency}_${index}:` : `js:2:${currency}:xpub.*`; accountTitleId = (accountName: string) => getElementById(`test-id-account-${accountName}`); modalButtonId = "add-accounts-modal-add-button"; currencyRow = (currencyId: string) => `currency-row-${currencyId}`; @@ -24,7 +33,7 @@ export default class AddAccountDrawer { async selectCurrency(currencyId: string) { const id = this.currencyRow(currencyId); - await waitForElementById(id); + await scrollToId(id); await tapById(id); } diff --git a/apps/ledger-live-mobile/e2e/specs/speculos/addAccount.spec.ts b/apps/ledger-live-mobile/e2e/specs/speculos/addAccount.spec.ts index 4465e86e6826..354812363ce8 100644 --- a/apps/ledger-live-mobile/e2e/specs/speculos/addAccount.spec.ts +++ b/apps/ledger-live-mobile/e2e/specs/speculos/addAccount.spec.ts @@ -1,10 +1,23 @@ import { Application } from "../../page"; +import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency"; let app: Application; const currencies = [ - { currency: "bitcoin", nanoApp: "Bitcoin", tmsLink: "B2CQA-101" }, - { currency: "ethereum", nanoApp: "Ethereum", tmsLink: "B2CQA-102" }, + { currency: Currency.BTC, tmsLink: "B2CQA-2499, B2CQA-2644, B2CQA-2672, B2CQA-786" }, + { currency: Currency.ETH, tmsLink: "B2CQA-2503, B2CQA-2645, B2CQA-2673" }, + { currency: Currency.ETC, tmsLink: "B2CQA-2502, B2CQA-2646, B2CQA-2674" }, + { currency: Currency.XRP, tmsLink: "B2CQA-2505, B2CQA-2647, B2CQA-2675" }, + { currency: Currency.DOT, tmsLink: "B2CQA-2504, B2CQA-2648, B2CQA-2676" }, + { currency: Currency.TRX, tmsLink: "B2CQA-2508, B2CQA-2649, B2CQA-2677" }, + { currency: Currency.ADA, tmsLink: "B2CQA-2500, B2CQA-2650, B2CQA-2678" }, + { currency: Currency.XLM, tmsLink: "B2CQA-2506, B2CQA-2651, B2CQA-2679" }, + { currency: Currency.BCH, tmsLink: "B2CQA-2498, B2CQA-2652, B2CQA-2680" }, + { currency: Currency.ALGO, tmsLink: "B2CQA-2497, B2CQA-2653, B2CQA-2681" }, + { currency: Currency.ATOM, tmsLink: "B2CQA-2501, B2CQA-2654, B2CQA-2682" }, + { currency: Currency.XTZ, tmsLink: "B2CQA-2507, B2CQA-2655, B2CQA-2683" }, + { currency: Currency.SOL, tmsLink: "B2CQA-2642, B2CQA-2656, B2CQA-2684" }, + { currency: Currency.TON, tmsLink: "B2CQA-2643, B2CQA-2657, B2CQA-2685" }, ]; describe("Add accounts", () => { @@ -13,21 +26,22 @@ describe("Add accounts", () => { await app.portfolio.waitForPortfolioPageToLoad(); }); - currencies.forEach(({ currency, nanoApp, tmsLink }) => { + currencies.forEach(({ currency, tmsLink }) => { let deviceNumber: number; $TmsLink(tmsLink); - it(`${currency}: add accounts`, async () => { + it(`${currency.name}: add accounts`, async () => { await app.addAccount.openViaDeeplink(); - await app.addAccount.selectCurrency(currency); + await app.common.performSearch(currency.name); + await app.addAccount.selectCurrency(currency.currencyId); - deviceNumber = await app.common.addSpeculos(nanoApp); + deviceNumber = await app.common.addSpeculos(currency.speculosApp.name); await app.addAccount.startAccountsDiscovery(); - await app.addAccount.expectAccountDiscovery(currency, 1); + await app.addAccount.expectAccountDiscovery(currency.currencyId, 1); await app.addAccount.finishAccountsDiscovery(); await app.addAccount.tapSuccessCta(); - await app.account.waitForAccountPageToLoad(currency); + await app.account.waitForAccountPageToLoad(currency.name); await app.account.expectAccountBalanceVisible(); });