Skip to content

Commit

Permalink
Merge pull request #7544 from LedgerHQ/test/qaa-102-portfolio
Browse files Browse the repository at this point in the history
[QAA-102] [LLD] Cover portfolio test cases
  • Loading branch information
ypolishchuk-ledger authored Aug 8, 2024
2 parents 3073b82 + e40ac44 commit 95572e2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
5 changes: 3 additions & 2 deletions apps/ledger-live-desktop/tests/fixtures/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { getEnv, setEnv } from "@ledgerhq/live-env";
import { startSpeculos, stopSpeculos, specs } from "../utils/speculos";

import { Application } from "tests/page";
import { generateUUID, safeAppendFile } from "tests/utils/fileUtils";
import { safeAppendFile } from "tests/utils/fileUtils";
import { launchApp } from "tests/utils/electronUtils";
import { captureArtifacts } from "tests/utils/allureUtils";
import { Currency } from "tests/enum/Currency";
import { randomUUID } from "crypto";

type TestFixtures = {
lang: string;
Expand Down Expand Up @@ -49,7 +50,7 @@ export const test = base.extend<TestFixtures>({
},

userdataDestinationPath: async ({}, use) => {
await use(path.join(__dirname, "../artifacts/userdata", generateUUID()));
await use(path.join(__dirname, "../artifacts/userdata", randomUUID()));
},
userdataOriginalFile: async ({ userdata }, use) => {
await use(path.join(__dirname, "../userdata/", `${userdata}.json`));
Expand Down
49 changes: 49 additions & 0 deletions apps/ledger-live-desktop/tests/page/portfolio.page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { step } from "tests/misc/reporters/step";
import { AppPage } from "tests/page/abstractClasses";
import { expect } from "@playwright/test";

export class PortfolioPage extends AppPage {
readonly emptyStateTitle = this.page.getByTestId("portfolio-empty-state-title");
private addAccountButton = this.page.getByTestId("portfolio-empty-state-add-account-button");
private buySellEntryButton = this.page.getByTestId("buy-sell-entry-button");
private swapEntryButton = this.page.getByTestId("swap-entry-button");
private stakeEntryButton = this.page.getByTestId("stake-entry-button");
private chart = this.page.getByTestId("chart-container");
private marketPerformanceWidget = this.page.getByTestId("market-performance-widget");
private swapButton = this.marketPerformanceWidget.getByRole("button", { name: "Swap" });
private buyButton = this.marketPerformanceWidget.getByRole("button", { name: "Buy" });
private assetAllocationTitle = this.page.getByText("Asset allocation");
private trendTitle = this.marketPerformanceWidget.getByText("1W trend");
private assetRowElements = this.page.locator("[data-testid^='asset-row-']");
private showAllButton = this.page.getByText("Show all");
private assetRow = (currency: string) =>
this.page.getByTestId(`asset-row-${currency.toLowerCase()}`);
Expand All @@ -15,6 +24,46 @@ export class PortfolioPage extends AppPage {
await this.addAccountButton.click();
}

@step("Check 'Buy/Sell' button visibility")
async checkBuySellButtonVisibility() {
await expect(this.buySellEntryButton).toBeVisible();
}

@step("Check 'Swap' button visibility")
async checkSwapButtonVisibility() {
await expect(this.swapEntryButton).toBeVisible();
}

@step("Check 'Stake' button visibility")
async checkStakeButtonVisibility() {
await expect(this.stakeEntryButton).toBeVisible();
}

@step("Check chart visibility")
async checkChartVisibility() {
await expect(this.chart).toBeVisible();
}

@step("Check market performance trend visibility")
async checkMarketPerformanceTrendVisibility() {
await expect(this.marketPerformanceWidget).toBeVisible();
await expect(this.trendTitle).toBeVisible();
await expect(this.buyButton).toBeVisible();
await expect(this.swapButton).toBeVisible();
}

@step("Check asset allocation section")
async checkAssetAllocationSection() {
await expect(this.assetAllocationTitle).toBeVisible();
await expect(this.assetRowElements).toHaveCount(6);
await expect(this.showAllButton).toBeVisible();
await this.showAllButton.click();
// Wait for the number of asset row elements to increase after clicking on show more button
await this.page.waitForFunction(() => {
return document.querySelectorAll("[data-testid^='asset-row-']").length > 6;
});
}

async startBuyFlow() {
await this.buySellEntryButton.click();
}
Expand Down
25 changes: 25 additions & 0 deletions apps/ledger-live-desktop/tests/specs/speculos/portfolio.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test } from "../../fixtures/common";

test.describe("Portfolio", () => {
test.use({
userdata: "speculos-tests-app",
});
test(
"Charts are displayed when user added his accounts",
{
annotation: {
type: "TMS",
description: "B2CQA-927, B2CQA-928",
},
},
async ({ app }) => {
await app.layout.goToPortfolio();
await app.portfolio.checkBuySellButtonVisibility();
await app.portfolio.checkStakeButtonVisibility();
await app.portfolio.checkSwapButtonVisibility();
await app.portfolio.checkChartVisibility();
await app.portfolio.checkMarketPerformanceTrendVisibility();
await app.portfolio.checkAssetAllocationSection();
},
);
});
5 changes: 0 additions & 5 deletions apps/ledger-live-desktop/tests/utils/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import crypto from "crypto";
import { appendFile } from "fs/promises";

export function generateUUID(): string {
return crypto.randomBytes(16).toString("hex");
}

export async function safeAppendFile(filePath: string, data: string) {
try {
await appendFile(filePath, data);
Expand Down

0 comments on commit 95572e2

Please sign in to comment.