From df6ba895edbe723a379cec6a370b30cd4ec1477c Mon Sep 17 00:00:00 2001 From: Victor Alber Date: Tue, 3 Dec 2024 17:06:09 +0100 Subject: [PATCH] =?UTF-8?q?test:=20=E2=9C=85=20adding=20e2e=20test=20-=20u?= =?UTF-8?q?ser=20displays=20his=20nft=20collection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/thick-peas-hear.md | 6 ++ .../screens/nft/Gallery/TokensList/Item.tsx | 1 + .../tests/page/account.page.ts | 21 +++---- .../tests/page/drawer/nft.drawer.ts | 48 ++++++--------- apps/ledger-live-desktop/tests/page/index.ts | 2 + .../tests/page/nftGallery.page.ts | 26 ++++++++ .../tests/specs/speculos/nft.spec.ts | 59 ++++++++++++++++--- libs/ledger-live-common/.unimportedrc.json | 1 + 8 files changed, 111 insertions(+), 53 deletions(-) create mode 100644 .changeset/thick-peas-hear.md create mode 100644 apps/ledger-live-desktop/tests/page/nftGallery.page.ts diff --git a/.changeset/thick-peas-hear.md b/.changeset/thick-peas-hear.md new file mode 100644 index 000000000000..81eb5c93b033 --- /dev/null +++ b/.changeset/thick-peas-hear.md @@ -0,0 +1,6 @@ +--- +"ledger-live-desktop": minor +"@ledgerhq/live-common": minor +--- + +Adding New E2E tests diff --git a/apps/ledger-live-desktop/src/renderer/screens/nft/Gallery/TokensList/Item.tsx b/apps/ledger-live-desktop/src/renderer/screens/nft/Gallery/TokensList/Item.tsx index 3e82953ca1d5..1b2920ec8600 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/nft/Gallery/TokensList/Item.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/nft/Gallery/TokensList/Item.tsx @@ -94,6 +94,7 @@ const NftCard = ({ id, mode, account, withContextMenu = false, onHideCollection horizontal={!isGrid} alignItems={!isGrid ? "center" : undefined} onClick={onItemClick} + data-testId={`nft-row-gallery-${nft?.contract}`} > this.page.getByTestId(`token-row-${tokenTicker}`); private addTokenButton = this.page.getByRole("button", { name: "Add token" }); private viewDetailsButton = this.page.getByText("View details"); - private seeGalleryButton = this.page.getByTestId("see-gallery-button"); - private nft = (nftName: string) => this.page.locator(`text=${nftName}`); + private seeGalleryButton = this.page.getByRole("button", { name: "See Gallery" }); private nftOperation = this.page.getByText("NFT Sent"); private nftList = (collectionName: string) => this.page.getByTestId(`nft-row-${collectionName}`); @@ -169,23 +169,18 @@ export class AccountPage extends AppPage { await this.seeGalleryButton.click(); } - @step("Select NFT $0") - async selectNFT(nftName: string) { - await this.nft(nftName).click(); - } - @step("Navigate to NFT operation") async navigateToNFTOperation() { await this.nftOperation.click(); } - @step("Expect NFT list $0 to be visible") + @step("Expect NFT list to be visible") async checkNftListInAccount(account: Account) { - if (account.nft) { - for (const nft of account.nft) { - const nftLocator = this.nftList(nft.collectionName); - await expect(nftLocator).toBeVisible(); - } + invariant(account.nft && account.nft.length > 0, "No NFT found in account"); + + for (const nft of account.nft) { + const nftLocator = this.nftList(nft.collectionName); + await expect(nftLocator).toBeVisible(); } } } diff --git a/apps/ledger-live-desktop/tests/page/drawer/nft.drawer.ts b/apps/ledger-live-desktop/tests/page/drawer/nft.drawer.ts index 96d00d2b1596..6f2513bdb1e1 100644 --- a/apps/ledger-live-desktop/tests/page/drawer/nft.drawer.ts +++ b/apps/ledger-live-desktop/tests/page/drawer/nft.drawer.ts @@ -1,13 +1,16 @@ import { step } from "tests/misc/reporters/step"; import { Drawer } from "tests/component/drawer.component"; import { expect } from "@playwright/test"; +import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; +import axios from "axios"; +import { getEnv } from "@ledgerhq/live-env"; +import invariant from "invariant"; export class NFTDrawer extends Drawer { private nftName = this.page.getByTestId("nft-name-sendDrawer"); private sendButton = this.page.getByTestId("nft-send-button-sendDrawer"); private nftFloorPrice = this.page.getByTestId("nft-floor-price"); private nftOptionsButton = this.page.locator("#accounts-options-button"); - private openInOpenSeaButton = this.page.getByText("Open in Opensea.io"); @step("Verify nft name is visible") async expectNftNameIsVisible(nft: string) { @@ -25,15 +28,15 @@ export class NFTDrawer extends Drawer { } @step("Retrieve NFT floor price value") - async getFloorPriceplayed() { + async getFloorPriceDisplayed() { const floorPrice = await this.nftFloorPrice.textContent(); return floorPrice ? floorPrice?.split(" ")[0] : ""; } @step("Expect nft floor price to be positive") async expectNftFloorPricePositive() { - const floorPrice = await this.getFloorPriceplayed(); - await expect(parseFloat(floorPrice)).toBeGreaterThan(0); + const floorPrice = await this.getFloorPriceDisplayed(); + expect(parseFloat(floorPrice)).toBeGreaterThan(0); } @step("Click on nft options") @@ -41,34 +44,17 @@ export class NFTDrawer extends Drawer { await this.nftOptionsButton.click(); } - @step("Check OpenSea.io") - async checkOpenSea() { - /* - * - * Interception not working... todo: fix it - * - */ + @step("Check Floor price value to be $1") + async verifyFloorPriceValue(account: Account, floorPrice: string) { + const nft = + account.nft?.find(nft => nft.nftContract)?.nftContract ?? + invariant(false, "No valid NFTs founds for this account"); - // console.log("Checking OpenSea.io"); + const { data } = await axios({ + method: "GET", + url: `${getEnv("NFT_ETH_METADATA_SERVICE")}/v1/marketdata/${account.currency.currencyId}/1/contract/${nft}/floor-price`, + }); - // await this.page.route("*", async (route, request) => { - // console.log("Intercepted request URL:", request.url()); - - // const postData = request.postData(); - // if (postData) { - // const payload = JSON.parse(postData); - // console.log("Payload:", JSON.stringify(payload, null, 2)); - - // if (payload.event === "OpenURL") { - // console.log("OpenURL event detected!"); - // expect(payload.url).toContain("opensea.io/assets/ethereum"); - // } else { - // console.log("Non-matching event:", payload.event); - // } - // } - // await route.continue(); - // }); - - await this.openInOpenSeaButton.click(); + expect(data.value).toEqual(parseFloat(floorPrice)); } } diff --git a/apps/ledger-live-desktop/tests/page/index.ts b/apps/ledger-live-desktop/tests/page/index.ts index 4068d1b2bb63..d882b0ee807a 100644 --- a/apps/ledger-live-desktop/tests/page/index.ts +++ b/apps/ledger-live-desktop/tests/page/index.ts @@ -21,6 +21,7 @@ import { AssetDrawer } from "./drawer/asset.drawer"; import { PasswordlockModal } from "./modal/passwordlock.modal"; import { LockscreenPage } from "tests/page/lockscreen.page"; import { NFTDrawer } from "./drawer/nft.drawer"; +import { NftGallery } from "./nftGallery.page"; export class Application extends PageHolder { public account = new AccountPage(this.page); @@ -45,4 +46,5 @@ export class Application extends PageHolder { public password = new PasswordlockModal(this.page); public LockscreenPage = new LockscreenPage(this.page); public nftDrawer = new NFTDrawer(this.page); + public nftGallery = new NftGallery(this.page); } diff --git a/apps/ledger-live-desktop/tests/page/nftGallery.page.ts b/apps/ledger-live-desktop/tests/page/nftGallery.page.ts new file mode 100644 index 000000000000..34228186ab3d --- /dev/null +++ b/apps/ledger-live-desktop/tests/page/nftGallery.page.ts @@ -0,0 +1,26 @@ +import { expect } from "@playwright/test"; +import { step } from "tests/misc/reporters/step"; +import { AppPage } from "tests/page/abstractClasses"; +import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; +import invariant from "invariant"; + +export class NftGallery extends AppPage { + private locateNftInGalleryByName = (nftName: string) => this.page.locator(`text=${nftName}`); + private nftListGallery = (nftContract: string) => + this.page.getByTestId(`nft-row-gallery-${nftContract}`); + + @step("Select NFT $0") + async selectNFT(nftName: string) { + await this.locateNftInGalleryByName(nftName).click(); + } + + @step("Expect NFT list to be visible in gallery") + async verifyNftPresenceInGallery(account: Account) { + invariant(account.nft && account.nft.length > 0, "No NFT found in account"); + + for (const nft of account.nft) { + const nftLocator = this.nftListGallery(nft.nftContract); + await expect(nftLocator).toBeVisible(); + } + } +} diff --git a/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts index 90dca7c6be8d..514af0854fd7 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts @@ -6,6 +6,7 @@ import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; import { addTmsLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; import { commandCLI } from "tests/utils/cliUtils"; +import invariant from "invariant"; test.describe("send NFT to ENS address", () => { const transaction = new NFTTransaction(Account.ETH_1, Account.ETH_MC, Nft.PODIUM, Fee.SLOW); @@ -44,7 +45,7 @@ test.describe("send NFT to ENS address", () => { await app.layout.goToAccounts(); await app.accounts.navigateToAccountByName(transaction.accountToDebit.accountName); await app.account.navigateToNFTGallery(); - await app.account.selectNFT(transaction.nft.nftName); + await app.nftGallery.selectNFT(transaction.nft.nftName); await app.nftDrawer.expectNftNameIsVisible(transaction.nft.nftName); await app.nftDrawer.clickSend(); await app.send.craftNFTTx(transaction); @@ -92,22 +93,25 @@ test.describe("The user can see his NFT floor price", () => { await app.layout.goToAccounts(); await app.accounts.navigateToAccountByName(account.accountName); await app.account.navigateToNFTGallery(); - if (account.nft) { - await app.account.selectNFT(account.nft[0].nftName); - await app.nftDrawer.expectNftNameIsVisible(account.nft[0].nftName); - } + const nft = + account.nft?.find(nft => nft.nftName)?.nftName ?? + invariant(false, "No valid NFTs founds for this account"); + await app.nftGallery.selectNFT(nft); + await app.nftDrawer.expectNftNameIsVisible(nft); await app.nftDrawer.expectNftFloorPriceIsVisible(); + const floorPrice = await app.nftDrawer.getFloorPriceDisplayed(); await app.nftDrawer.expectNftFloorPricePositive(); await app.nftDrawer.clickNftOptions(); - await app.nftDrawer.checkOpenSea(); + await app.nftDrawer.verifyFloorPriceValue(account, floorPrice); }, ); }); const accounts = [ - { account: Account.ETH_1, xrayTicket: "B2CQA-801.1" }, - { account: Account.POL_1, xrayTicket: "B2CQA-801.2" }, + { account: Account.ETH_1, xrayTicket1: "B2CQA-2863", xrayTicket2: "B2CQA-2861" }, + { account: Account.POL_1, xrayTicket1: "B2CQA-2864", xrayTicket2: "B2CQA-2862" }, ]; + for (const account of accounts) { test.describe("The user displays all the nfts from his account", () => { test.use({ @@ -131,7 +135,7 @@ for (const account of accounts) { { annotation: { type: "TMS", - description: "B2CQA-659", + description: account.xrayTicket1, }, }, async ({ app }) => { @@ -143,3 +147,40 @@ for (const account of accounts) { ); }); } + +for (const account of accounts) { + test.describe("The user displays his nft collection", () => { + test.use({ + userdata: "skip-onboarding", + cliCommands: [ + { + command: commandCLI.liveData, + args: { + currency: account.account.currency.currencyId, + index: account.account.index, + appjson: "", + add: true, + }, + }, + ], + speculosApp: account.account.currency.speculosApp, + }); + + test( + `User displays his ${account.account.currency.name} nft collection`, + { + annotation: { + type: "TMS", + description: account.xrayTicket2, + }, + }, + async ({ app }) => { + await addTmsLink(getDescription(test.info().annotations).split(", ")); + await app.layout.goToAccounts(); + await app.accounts.navigateToAccountByName(account.account.accountName); + await app.account.navigateToNFTGallery(); + await app.nftGallery.verifyNftPresenceInGallery(account.account); + }, + ); + }); +} diff --git a/libs/ledger-live-common/.unimportedrc.json b/libs/ledger-live-common/.unimportedrc.json index 27a029333edb..d64d3ed0b4e6 100644 --- a/libs/ledger-live-common/.unimportedrc.json +++ b/libs/ledger-live-common/.unimportedrc.json @@ -311,6 +311,7 @@ "src/deviceSDK/commands/getAppAndVersion.ts", "src/deviceSDK/tasks/genuineCheck.ts", "src/e2e/enum/Account.ts", + "src/e2e/enum/Nft.ts", "src/e2e/enum/AccountType.ts", "src/e2e/enum/AppInfos.ts", "src/e2e/enum/Currency.ts",