From 25765a33cb3911516b0614a2014901a7770d4f3f Mon Sep 17 00:00:00 2001 From: Victor Alber Date: Fri, 3 Jan 2025 15:29:00 +0100 Subject: [PATCH 1/3] =?UTF-8?q?test:=20=E2=9C=85=20Updating=20method=20to?= =?UTF-8?q?=20get=20the=20provider=20-=20E2E=20Swap=20Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/drawer/swap.confirmation.drawer.ts | 3 +- .../tests/page/swap.page.ts | 44 ++-- .../tests/specs/speculos/swap.spec.ts | 196 +++--------------- libs/ledger-live-common/src/e2e/enum/Swap.ts | 11 +- .../ledger-live-common/src/e2e/models/Swap.ts | 8 - 5 files changed, 65 insertions(+), 197 deletions(-) diff --git a/apps/ledger-live-desktop/tests/page/drawer/swap.confirmation.drawer.ts b/apps/ledger-live-desktop/tests/page/drawer/swap.confirmation.drawer.ts index 39cb5f4cb6e0..1407e97d242e 100644 --- a/apps/ledger-live-desktop/tests/page/drawer/swap.confirmation.drawer.ts +++ b/apps/ledger-live-desktop/tests/page/drawer/swap.confirmation.drawer.ts @@ -1,7 +1,6 @@ import { expect } from "@playwright/test"; import { step } from "tests/misc/reporters/step"; import { Drawer } from "tests/component/drawer.component"; -import { capitalizeFirstLetter } from "tests/utils/textParserUtils"; export class SwapConfirmationDrawer extends Drawer { private amountSent = this.page.getByTestId("amountSent"); @@ -26,7 +25,7 @@ export class SwapConfirmationDrawer extends Drawer { @step("Verify provider: $0") async verifyProvider(provider: string) { - await expect(this.swapProvider).toHaveText(capitalizeFirstLetter(provider)); + await expect(this.swapProvider).toHaveText(provider); } @step("Verify source currency: $0") diff --git a/apps/ledger-live-desktop/tests/page/swap.page.ts b/apps/ledger-live-desktop/tests/page/swap.page.ts index 31dd99f1d718..27cb34a754f7 100644 --- a/apps/ledger-live-desktop/tests/page/swap.page.ts +++ b/apps/ledger-live-desktop/tests/page/swap.page.ts @@ -2,9 +2,9 @@ import { AppPage } from "tests/page/abstractClasses"; import { waitFor } from "../utils/waitFor"; import { step } from "tests/misc/reporters/step"; import { ElectronApplication, expect } from "@playwright/test"; -import { capitalizeFirstLetter } from "tests/utils/textParserUtils"; import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; import { ChooseAssetDrawer } from "tests/page/drawer/choose.asset.drawer"; +import { Provider } from "@ledgerhq/live-common/e2e/enum/Swap"; export class SwapPage extends AppPage { private currencyByName = (accountName: string) => this.page.getByText(accountName); // TODO: this is rubbish. Changed this @@ -35,12 +35,6 @@ export class SwapPage extends AppPage { private advancedFeesSelector = this.page.getByTestId("advanced-fee-mode-selector"); private customFeeTextbox = this.page.getByTestId("currency-textbox"); - // Quote Components - private quoteContainer = (providerName: string, exchangeType: string) => - this.page.getByTestId(`quote-container-${providerName}-${exchangeType}`); - private quoteSelector = (providerName: string, rate: string) => - `quote-container-${providerName}-${rate}`; - // Exchange Button Component private exchangeButton = this.page.getByTestId("exchange-button"); @@ -116,16 +110,32 @@ export class SwapPage extends AppPage { await this.customFeeTextbox.fill(amount); } - @step("Select exchange quote $0 with rate $1") - async selectExchangeQuote(providerName: string, exchangeType: "fixed" | "float") { - await this.quoteContainer(providerName, exchangeType).click(); - } - - @step("Select exchange quote with provider $1") - async selectQuote(electronApp: ElectronApplication, providerName: string, rate: string) { + @step("Select available provider") + async selectExchange(electronApp: ElectronApplication) { const [, webview] = electronApp.windows(); - await expect(webview.getByTestId(this.quoteSelector(providerName, rate))).toBeEnabled(); - await webview.getByTestId(this.quoteSelector(providerName, rate)).click(); + await expect(webview.getByTestId("number-of-quotes")).toBeVisible(); + const providersList = await webview + .locator("//span[@data-testid='quote-card-provider-name']") + .allTextContents(); + + const providersWithoutKYC = providersList.filter(providerName => { + const provider = Object.values(Provider).find(p => p.uiName === providerName); + return provider && !provider.kyc; + }); + + const nativeProviders = providersWithoutKYC.filter(providerName => { + const provider = Object.values(Provider).find(p => p.uiName === providerName); + return provider && provider.isNative; + }); + + for (const providerName of nativeProviders) { + const providerSelected = webview + .locator(`//span[@data-testid='quote-card-provider-name' and text()='${providerName}']`) + .first(); + await providerSelected.isVisible(); + await providerSelected.click(); + return providerName; + } } async waitForExchangeToBeAvailable() { @@ -135,7 +145,7 @@ export class SwapPage extends AppPage { @step("Click Exchange button") async clickExchangeButton(electronApp: ElectronApplication, provider: string) { const [, webview] = electronApp.windows(); - await webview.getByText(`Swap with ${capitalizeFirstLetter(provider)}`).click(); + await webview.getByText(`Swap with ${provider}`).click(); } async confirmExchange() { diff --git a/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts index 90aadb26c7af..36be1cf6ea52 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts @@ -4,7 +4,6 @@ import { AppInfos } from "@ledgerhq/live-common/e2e/enum/AppInfos"; import { setExchangeDependencies } from "@ledgerhq/live-common/e2e/speculos"; import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; import { Swap } from "@ledgerhq/live-common/e2e/models/Swap"; -import { Provider, Rate } from "@ledgerhq/live-common/e2e/enum/Swap"; import { addTmsLink } from "tests/utils/allureUtils"; import { getDescription } from "tests/utils/customJsonReporter"; import { Application } from "tests/page"; @@ -14,168 +13,63 @@ const app: AppInfos = AppInfos.EXCHANGE; const swaps = [ { - swap: new Swap( - Account.ETH_1, - Account.BTC_NATIVE_SEGWIT_1, - "0.02", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_1, Account.BTC_NATIVE_SEGWIT_1, "0.02", Fee.MEDIUM), xrayTicket: "B2CQA-2750", }, { - swap: new Swap( - Account.BTC_NATIVE_SEGWIT_1, - Account.ETH_1, - "0.00067", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.BTC_NATIVE_SEGWIT_1, Account.ETH_1, "0.00067", Fee.MEDIUM), xrayTicket: "B2CQA-2744, B2CQA-2432", }, { - swap: new Swap( - Account.ETH_USDT_1, - Account.ETH_1, - "40", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDT_1, Account.ETH_1, "40", Fee.MEDIUM), xrayTicket: "B2CQA-2752, B2CQA-2048", }, { - swap: new Swap( - Account.ETH_1, - Account.SOL_1, - "0.018", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_1, Account.SOL_1, "0.018", Fee.MEDIUM), xrayTicket: "B2CQA-2748", }, { - swap: new Swap( - Account.ETH_1, - Account.ETH_USDT_1, - "0.02", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_1, Account.ETH_USDT_1, "0.02", Fee.MEDIUM), xrayTicket: "B2CQA-2749", }, { - swap: new Swap( - Account.BTC_NATIVE_SEGWIT_1, - Account.SOL_1, - "0.0006", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.BTC_NATIVE_SEGWIT_1, Account.SOL_1, "0.0006", Fee.MEDIUM), xrayTicket: "B2CQA-2747", }, { - swap: new Swap( - Account.BTC_NATIVE_SEGWIT_1, - Account.ETH_USDT_1, - "0.0006", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.BTC_NATIVE_SEGWIT_1, Account.ETH_USDT_1, "0.0006", Fee.MEDIUM), xrayTicket: "B2CQA-2746", }, { - swap: new Swap( - Account.ETH_USDT_1, - Account.BTC_NATIVE_SEGWIT_1, - "40", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDT_1, Account.BTC_NATIVE_SEGWIT_1, "40", Fee.MEDIUM), xrayTicket: "B2CQA-2753", }, { - swap: new Swap( - Account.ETH_USDT_1, - Account.SOL_1, - "40", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDT_1, Account.SOL_1, "40", Fee.MEDIUM), xrayTicket: "B2CQA-2751", }, { - swap: new Swap( - Account.SOL_1, - Account.ETH_1, - "0.25", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.SOL_1, Account.ETH_1, "0.25", Fee.MEDIUM), xrayTicket: "B2CQA-2775", }, { - swap: new Swap( - Account.SOL_1, - Account.BTC_NATIVE_SEGWIT_1, - "0.25", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.SOL_1, Account.BTC_NATIVE_SEGWIT_1, "0.25", Fee.MEDIUM), xrayTicket: "B2CQA-2776", }, { - swap: new Swap( - Account.SOL_1, - Account.ETH_USDT_1, - "0.25", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.SOL_1, Account.ETH_USDT_1, "0.25", Fee.MEDIUM), xrayTicket: "B2CQA-2777", }, { - swap: new Swap( - Account.ETH_USDC_1, - Account.ETH_1, - "65", - Fee.MEDIUM, - Provider.EXODUS, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDC_1, Account.ETH_1, "65", Fee.MEDIUM), xrayTicket: "B2CQA-2830", }, { - swap: new Swap( - Account.ETH_USDC_1, - Account.SOL_1, - "45", - Fee.MEDIUM, - Provider.EXODUS, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDC_1, Account.SOL_1, "45", Fee.MEDIUM), xrayTicket: "B2CQA-2831", }, { - swap: new Swap( - Account.ETH_USDC_1, - Account.BTC_NATIVE_SEGWIT_1, - "65", - Fee.MEDIUM, - Provider.EXODUS, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDC_1, Account.BTC_NATIVE_SEGWIT_1, "65", Fee.MEDIUM), xrayTicket: "B2CQA-2832", }, ]; @@ -229,8 +123,8 @@ for (const { swap, xrayTicket } of swaps) { await addTmsLink(getDescription(test.info().annotations, "TMS").split(", ")); await performSwapUntilQuoteSelectionStep(app, electronApp, swap); - await app.swap.selectQuote(electronApp, swap.provider.name, swap.rate); - await performSwapUntilDeviceVerificationStep(app, electronApp, swap); + const selectedProvider = await app.swap.selectExchange(electronApp); + await performSwapUntilDeviceVerificationStep(app, electronApp, swap, selectedProvider); await app.speculos.verifyAmountsAndAcceptSwap(swap); await app.swapDrawer.verifyExchangeCompletedTextContent(swap.accountToCredit.currency.name); }, @@ -240,14 +134,7 @@ for (const { swap, xrayTicket } of swaps) { const rejectedSwaps = [ { - swap: new Swap( - Account.ETH_1, - Account.BTC_NATIVE_SEGWIT_1, - "0.02", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_1, Account.BTC_NATIVE_SEGWIT_1, "0.02", Fee.MEDIUM), xrayTicket: "B2CQA-600, B2CQA-2212", }, ]; @@ -293,8 +180,8 @@ for (const { swap, xrayTicket } of rejectedSwaps) { await addTmsLink(getDescription(test.info().annotations, "TMS").split(", ")); await performSwapUntilQuoteSelectionStep(app, electronApp, swap); - await app.swap.selectQuote(electronApp, swap.provider.name, swap.rate); - await performSwapUntilDeviceVerificationStep(app, electronApp, swap); + const selectedProvider = await app.swap.selectExchange(electronApp); + await performSwapUntilDeviceVerificationStep(app, electronApp, swap, selectedProvider); await app.speculos.verifyAmountsAndRejectSwap(swap); await app.swapDrawer.verifyExchangeErrorTextContent("Operation denied on device"); }, @@ -304,40 +191,19 @@ for (const { swap, xrayTicket } of rejectedSwaps) { const tooLowAmountForQuoteSwaps = [ { - swap: new Swap( - Account.ETH_1, - Account.BTC_NATIVE_SEGWIT_1, - "0.001", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_1, Account.BTC_NATIVE_SEGWIT_1, "0.001", Fee.MEDIUM), xrayTicket: "B2CQA-2755", }, { - swap: new Swap( - Account.BTC_NATIVE_SEGWIT_1, - Account.ETH_1, - "0.00001", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.BTC_NATIVE_SEGWIT_1, Account.ETH_1, "0.00001", Fee.MEDIUM), xrayTicket: "B2CQA-2758", }, { - swap: new Swap( - Account.ETH_USDT_1, - Account.ETH_1, - "150", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.ETH_USDT_1, Account.ETH_1, "150", Fee.MEDIUM), xrayTicket: "B2CQA-2759", }, { - swap: new Swap(Account.TRX_1, Account.ETH_1, "77", Fee.MEDIUM, Provider.CHANGELLY, Rate.FLOAT), + swap: new Swap(Account.TRX_1, Account.ETH_1, "77", Fee.MEDIUM), xrayTicket: "B2CQA-2739", }, ]; @@ -422,14 +288,7 @@ for (const { swap, xrayTicket } of tooLowAmountForQuoteSwaps) { } const swapEntryPoint = { - swap: new Swap( - Account.BTC_NATIVE_SEGWIT_1, - Account.ETH_1, - "0.0006", - Fee.MEDIUM, - Provider.CHANGELLY, - Rate.FLOAT, - ), + swap: new Swap(Account.BTC_NATIVE_SEGWIT_1, Account.ETH_1, "0.0006", Fee.MEDIUM), }; test.describe("Swap flow from different entry point", () => { @@ -600,8 +459,9 @@ async function performSwapUntilDeviceVerificationStep( app: Application, electronApp: ElectronApplication, swap: Swap, + selectedProvider: any, ) { - await app.swap.clickExchangeButton(electronApp, swap.provider.uiName); + await app.swap.clickExchangeButton(electronApp, selectedProvider); const amountTo = await app.swapDrawer.getAmountToReceive(); const fees = await app.swapDrawer.getFees(); @@ -613,5 +473,5 @@ async function performSwapUntilDeviceVerificationStep( await app.swapDrawer.verifyAmountSent(swap.amount, swap.accountToDebit.currency.ticker); await app.swapDrawer.verifySourceAccount(swap.accountToDebit.currency.name); await app.swapDrawer.verifyTargetCurrency(swap.accountToCredit.currency.name); - await app.swapDrawer.verifyProvider(swap.provider.name); + await app.swapDrawer.verifyProvider(selectedProvider); } diff --git a/libs/ledger-live-common/src/e2e/enum/Swap.ts b/libs/ledger-live-common/src/e2e/enum/Swap.ts index 83a99c2e371f..0ffd755ab2cb 100644 --- a/libs/ledger-live-common/src/e2e/enum/Swap.ts +++ b/libs/ledger-live-common/src/e2e/enum/Swap.ts @@ -2,9 +2,16 @@ export class Provider { constructor( public readonly name: string, public readonly uiName: string, + public readonly kyc: boolean, + public readonly isNative: boolean, ) {} - static readonly CHANGELLY = new Provider("changelly", "Changelly"); - static readonly EXODUS = new Provider("exodus", "Exodus"); + static readonly CHANGELLY = new Provider("changelly", "Changelly", false, true); + static readonly EXODUS = new Provider("exodus", "Exodus", false, true); + static readonly ONE_INCH = new Provider("1inch", "1inch", false, false); + static readonly PARASWAP = new Provider("paraswap", "Paraswap", false, false); + static readonly MOONPAY = new Provider("moonpay", "MoonPay", true, false); + static readonly THORCHAIN = new Provider("thorchain", "THORChain", false, true); + static readonly UNISWAP = new Provider("uniswap", "Uniswap", false, false); } export enum Rate { diff --git a/libs/ledger-live-common/src/e2e/models/Swap.ts b/libs/ledger-live-common/src/e2e/models/Swap.ts index e9c266f080de..6c341b2141dd 100644 --- a/libs/ledger-live-common/src/e2e/models/Swap.ts +++ b/libs/ledger-live-common/src/e2e/models/Swap.ts @@ -1,25 +1,17 @@ import { Transaction } from "./Transaction"; import { Fee } from "../enum/Fee"; import { Account } from "../enum/Account"; -import { Provider, Rate } from "../enum/Swap"; export class Swap extends Transaction { - provider: Provider; - rate: Rate; - constructor( accountToDebit: Account, accountToCredit: Account, amount: string, speed: Fee, - provider: Provider, - rate: Rate, public amountToReceive?: string, public feesAmount?: string, ) { super(accountToDebit, accountToCredit, amount, speed); - this.provider = provider; - this.rate = rate; } public setAmountToReceive(value: string) { From 76cf3d6cdacc1705f5ced53a7d205270fee3ad36 Mon Sep 17 00:00:00 2001 From: Victor Alber Date: Mon, 6 Jan 2025 14:51:48 +0100 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=E2=9C=A8=20Updating=20getCurrentDe?= =?UTF-8?q?vice=20to=20have=20nanoSP=20for=20e2e=20testing=20+=20update=20?= =?UTF-8?q?transaxction=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ledger-live-desktop/src/renderer/reducers/devices.ts | 4 ++-- .../ledger-live-desktop/tests/page/drawer/send.drawer.ts | 3 ++- .../tests/specs/speculos/delegate.spec.ts | 9 ++++++--- .../tests/specs/speculos/send.tx.spec.ts | 5 ++--- .../e2e/enum/{OperationType.ts => TransactionStatus.ts} | 4 +++- 5 files changed, 15 insertions(+), 10 deletions(-) rename libs/ledger-live-common/src/e2e/enum/{OperationType.ts => TransactionStatus.ts} (61%) diff --git a/apps/ledger-live-desktop/src/renderer/reducers/devices.ts b/apps/ledger-live-desktop/src/renderer/reducers/devices.ts index b16e975ae758..9a881132af22 100644 --- a/apps/ledger-live-desktop/src/renderer/reducers/devices.ts +++ b/apps/ledger-live-desktop/src/renderer/reducers/devices.ts @@ -78,7 +78,7 @@ export function getCurrentDevice(state: { devices: DevicesState; settings: Setti return { deviceId: "", wired: true, - modelId: DeviceModelId.nanoS, + modelId: DeviceModelId.nanoSP, }; } return state.devices.currentDevice; @@ -90,7 +90,7 @@ export function getDevices(state: { devices: DevicesState }) { { deviceId: "", wired: true, - modelId: DeviceModelId.nanoS, + modelId: DeviceModelId.nanoSP, }, ]; } diff --git a/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts b/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts index 584aa255fced..9ed7a1eed8b4 100644 --- a/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts +++ b/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts @@ -2,6 +2,7 @@ import { step } from "tests/misc/reporters/step"; import { Drawer } from "tests/component/drawer.component"; import { expect } from "@playwright/test"; import { NFTTransaction, Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; +import { TransactionStatus } from "@ledgerhq/live-common/e2e/enum/TransactionStatus"; export class SendDrawer extends Drawer { private addressValue = (address: string) => @@ -24,7 +25,7 @@ export class SendDrawer extends Drawer { @step("Verify Send NFT information") async expectNftInfos(tx: NFTTransaction) { const transactionType = await this.transactionType.textContent(); - expect(transactionType).toMatch("Sending"); + expect(transactionType).toMatch(TransactionStatus.SENDING); const NFTName = await this.nftName.textContent(); expect(NFTName).toBe(tx.nft.nftName); const address = await this.addressValue(tx.accountToCredit.address).textContent(); diff --git a/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts index 347202f83a3a..864784d870ec 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts @@ -5,6 +5,7 @@ import { addTmsLink, addBugLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; import { CLI } from "tests/utils/cliUtils"; import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency"; +import { getEnv } from "@ledgerhq/live-env"; const e2eDelegationAccounts = [ { @@ -106,9 +107,11 @@ test.describe("Delegate flows", () => { await app.delegateDrawer.amountValueIsVisible(); await app.drawer.close(); - await app.layout.syncAccounts(); - await app.account.clickOnLastOperation(); - await app.delegateDrawer.expectDelegationInfos(account.delegate); + if (!getEnv("DISABLE_TRANSACTION_BROADCAST")) { + await app.layout.syncAccounts(); + await app.account.clickOnLastOperation(); + await app.delegateDrawer.expectDelegationInfos(account.delegate); + } }, ); }); diff --git a/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts index 5901aa174c4e..9bd7c46fc4f5 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts @@ -1,7 +1,7 @@ import { test } from "../../fixtures/common"; import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; -import { OperationType } from "@ledgerhq/live-common/e2e/enum/OperationType"; +import { TransactionStatus } from "@ledgerhq/live-common/e2e/enum/TransactionStatus"; import { Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; import { addTmsLink, addBugLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; @@ -273,7 +273,6 @@ test.describe("Send flows", () => { transaction.transaction.accountToCredit.address, ); await app.drawer.close(); - // Todo: Update method => Check the receiver account only when we broadcast if (!getEnv("DISABLE_TRANSACTION_BROADCAST")) { await app.layout.goToAccounts(); await app.accounts.clickSyncBtnForAccount( @@ -282,7 +281,7 @@ test.describe("Send flows", () => { await app.accounts.navigateToAccountByName( transaction.transaction.accountToCredit.accountName, ); - await app.account.selectAndClickOnLastOperation(OperationType.RECEIVED); + await app.account.selectAndClickOnLastOperation(TransactionStatus.RECEIVED); await app.sendDrawer.expectReceiverInfos(transaction.transaction); } }, diff --git a/libs/ledger-live-common/src/e2e/enum/OperationType.ts b/libs/ledger-live-common/src/e2e/enum/TransactionStatus.ts similarity index 61% rename from libs/ledger-live-common/src/e2e/enum/OperationType.ts rename to libs/ledger-live-common/src/e2e/enum/TransactionStatus.ts index 34e9399b4113..7ecf46ec15b2 100644 --- a/libs/ledger-live-common/src/e2e/enum/OperationType.ts +++ b/libs/ledger-live-common/src/e2e/enum/TransactionStatus.ts @@ -1,7 +1,9 @@ -export enum OperationType { +export enum TransactionStatus { RECEIVED = "Received", DELEGATED = "Delegated", NFT_RECEIVED = "NFT Received", SENT = "Sent", FEES = "Fees", + STAKED = "Staked", + SENDING = "Sending", } From 4364a11a6c77a68ae140e7b45835e5b2d3429051 Mon Sep 17 00:00:00 2001 From: Victor Alber Date: Mon, 6 Jan 2025 15:04:50 +0100 Subject: [PATCH 3/3] add changeset + unimported --- .changeset/tame-geese-thank.md | 6 +++ .../src/renderer/reducers/devices.ts | 48 +++++++++++-------- .../tests/page/swap.page.ts | 22 +++++---- libs/ledger-live-common/.unimportedrc.json | 11 ++--- 4 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 .changeset/tame-geese-thank.md diff --git a/.changeset/tame-geese-thank.md b/.changeset/tame-geese-thank.md new file mode 100644 index 000000000000..c46f8c20d7df --- /dev/null +++ b/.changeset/tame-geese-thank.md @@ -0,0 +1,6 @@ +--- +"ledger-live-desktop": minor +"@ledgerhq/live-common": minor +--- + +test: Refactoring of the Swap Enum + updating Provider Selection + Updating device for e2e tests diff --git a/apps/ledger-live-desktop/src/renderer/reducers/devices.ts b/apps/ledger-live-desktop/src/renderer/reducers/devices.ts index 9a881132af22..b34fd4678c43 100644 --- a/apps/ledger-live-desktop/src/renderer/reducers/devices.ts +++ b/apps/ledger-live-desktop/src/renderer/reducers/devices.ts @@ -69,30 +69,38 @@ export function getCurrentDevice(state: { devices: DevicesState; settings: Setti }; } - if ( - getEnv("DEVICE_PROXY_URL") || - getEnv("SPECULOS_API_PORT") || - (getEnv("MOCK") && !getEnv("MOCK_NO_BYPASS")) - ) { - // bypass the listen devices (we should remove modelId here by instead get it at open time if needed) - return { - deviceId: "", - wired: true, - modelId: DeviceModelId.nanoSP, - }; + const envConditions = [ + { condition: getEnv("DEVICE_PROXY_URL"), modelId: DeviceModelId.nanoS }, + { condition: getEnv("MOCK") && !getEnv("MOCK_NO_BYPASS"), modelId: DeviceModelId.nanoS }, + { condition: getEnv("SPECULOS_API_PORT"), modelId: DeviceModelId.nanoSP }, + ]; + + for (const { condition, modelId } of envConditions) { + if (condition) { + return { + deviceId: "", + wired: true, + modelId, + }; + } } return state.devices.currentDevice; } export function getDevices(state: { devices: DevicesState }) { - if (getEnv("DEVICE_PROXY_URL") || getEnv("SPECULOS_API_PORT")) { - // bypass the listen devices - return [ - { - deviceId: "", - wired: true, - modelId: DeviceModelId.nanoSP, - }, - ]; + const envConditions = [ + { condition: getEnv("DEVICE_PROXY_URL"), modelId: DeviceModelId.nanoS }, + { condition: getEnv("SPECULOS_API_PORT"), modelId: DeviceModelId.nanoSP }, + ]; + for (const { condition, modelId } of envConditions) { + if (condition) { + return [ + { + deviceId: "", + wired: true, + modelId, + }, + ]; + } } return state.devices.devices; } diff --git a/apps/ledger-live-desktop/tests/page/swap.page.ts b/apps/ledger-live-desktop/tests/page/swap.page.ts index 27cb34a754f7..46c18281e2fb 100644 --- a/apps/ledger-live-desktop/tests/page/swap.page.ts +++ b/apps/ledger-live-desktop/tests/page/swap.page.ts @@ -123,19 +123,21 @@ export class SwapPage extends AppPage { return provider && !provider.kyc; }); - const nativeProviders = providersWithoutKYC.filter(providerName => { + for (const providerName of providersWithoutKYC) { const provider = Object.values(Provider).find(p => p.uiName === providerName); - return provider && provider.isNative; - }); + if (provider && provider.isNative) { + const providerLocator = webview + .locator(`//span[@data-testid='quote-card-provider-name' and text()='${providerName}']`) + .first(); + + await providerLocator.isVisible(); + await providerLocator.click(); - for (const providerName of nativeProviders) { - const providerSelected = webview - .locator(`//span[@data-testid='quote-card-provider-name' and text()='${providerName}']`) - .first(); - await providerSelected.isVisible(); - await providerSelected.click(); - return providerName; + return providerName; + } } + + throw new Error("No valid providers found"); } async waitForExchangeToBeAvailable() { diff --git a/libs/ledger-live-common/.unimportedrc.json b/libs/ledger-live-common/.unimportedrc.json index e7165b50150f..0d6b52c0d02c 100644 --- a/libs/ledger-live-common/.unimportedrc.json +++ b/libs/ledger-live-common/.unimportedrc.json @@ -285,12 +285,7 @@ "src/wallet-api/version.ts", "src/errors/transactionBroadcastErrors.ts" ], - "extensions": [ - ".ts", - ".js", - ".jsx", - ".tsx" - ], + "extensions": [".ts", ".js", ".jsx", ".tsx"], "ignorePatterns": [ "**/node_modules/**", "**/__tests__/**", @@ -327,7 +322,7 @@ "src/e2e/enum/DeviceLabels.ts", "src/e2e/enum/Fee.ts", "src/e2e/enum/Nft.ts", - "src/e2e/enum/OperationType.ts", + "src/e2e/enum/TransactionStatus.ts", "src/e2e/enum/Swap.ts", "src/exchange/swap/const/blockchain.ts", "src/families/cardano/logic.ts", @@ -437,4 +432,4 @@ "use-sync-external-store/shim", "whatwg-fetch" ] -} \ No newline at end of file +}