Skip to content

Commit

Permalink
Merge pull request #8800 from LedgerHQ/support/QAA-405
Browse files Browse the repository at this point in the history
[QAA] Update Swap tests to always choose valid provider
  • Loading branch information
VicAlbr authored Jan 6, 2025
2 parents 2ea3206 + 4364a11 commit 77105fd
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 233 deletions.
6 changes: 6 additions & 0 deletions .changeset/tame-geese-thank.md
Original file line number Diff line number Diff line change
@@ -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
48 changes: 28 additions & 20 deletions apps/ledger-live-desktop/src/renderer/reducers/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.nanoS,
};
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.nanoS,
},
];
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;
}
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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")
Expand Down
46 changes: 29 additions & 17 deletions apps/ledger-live-desktop/tests/page/swap.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -116,16 +110,34 @@ 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;
});

for (const providerName of providersWithoutKYC) {
const provider = Object.values(Provider).find(p => p.uiName === providerName);
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();

return providerName;
}
}

throw new Error("No valid providers found");
}

async waitForExchangeToBeAvailable() {
Expand All @@ -135,7 +147,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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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);
}
},
);
});
Expand Down
5 changes: 2 additions & 3 deletions apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}
},
Expand Down
Loading

0 comments on commit 77105fd

Please sign in to comment.