Skip to content

Commit

Permalink
tests: Refacto subAccount methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VicAlbr committed Jul 29, 2024
1 parent afd4238 commit 2d7b8ed
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 157 deletions.
72 changes: 72 additions & 0 deletions apps/ledger-live-desktop/tests/enum/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,76 @@ export class Account {
"Binance Smart Chain 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);

static readonly ETH_USDT = new Account(
Currency.ETH_USDT,
"Ethereum 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);

static readonly ETH_LIDO = new Account(
Currency.ETH_LIDO,
"Ethereum 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);

static readonly XLM_USCD = new Account(
Currency.XLM_USCD,
"Stellar 1",
"GCAGRZ7XABYSXV7CPFSFWQIUK6XFXECBPWP2SGMVOB2KFWN7YM4TDGSX",
);

static readonly ALGO_USDT_1 = new Account(
Currency.ALGO_USDT,
"Algorand 1",
"HQ6YJWSVG3KVRE56V6UGWMUJLDVNPQUNXJBY7VJ56VMNMGIKVDTC7JEKOU",
);

static readonly ALGO_USDT_2 = new Account(
Currency.ALGO_USDT,
"Algorand 2",
"6TFDU3BYQ2FO32SOYQDTHDW5XKGEYH4FCT34ZQRHFPJRVMLEQWOO2OEUU4",
);

static readonly ALGO_USDT_3 = new Account(
Currency.ALGO_USDT,
"Algorand 3",
"3ASRTAN6KCZCICTIFQ5N2UBOSSBOZ7WFSOI2CJEJ4ESK532RODQZ7KCSOA",
);

static readonly TRX_USDT = new Account(
Currency.TRX_USDT,
"Tron 1",
"TDUKFB9wj3P5f2iNvkRuaDDeWVkTdUVhs1",
);

static readonly TRX_BTT = new Account(
Currency.TRX_BTT,
"Tron 1",
"TDUKFB9wj3P5f2iNvkRuaDDeWVkTdUVhs1",
);

static readonly BSC_BUSD = new Account(
Currency.BSC_BUSD,
"Binance Smart Chain 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);

static readonly BSC_SHIBA = new Account(
Currency.BSC_SHIBA,
"Binance Smart Chain 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);

static readonly MATIC_DAI = new Account(
Currency.MATIC_DAI,
"Polygon 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);

static readonly MATIC_UNI = new Account(
Currency.MATIC_UNI,
"Polygon 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
);
}
97 changes: 97 additions & 0 deletions apps/ledger-live-desktop/tests/enum/Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class Currency {
public readonly deviceLabel: string,
public readonly sendPattern: DeviceLabels[],
public readonly receivePattern: DeviceLabels[],
public readonly tokenName?: string,
public readonly tokenTicker?: string,
) {}
static readonly BTC = new Currency(
"Bitcoin",
Expand Down Expand Up @@ -152,4 +154,99 @@ export class Currency {
[DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
);
static readonly ETH_USDT = new Currency(
"Ethereum",
"ETH",
"Ethereum",
[DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"Tether USD",
"USDT",
);
static readonly ETH_LIDO = new Currency(
"Ethereum",
"ETH",
"Ethereum",
[DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"LIDO Staked ETH",
"STETH",
);
static readonly XLM_USCD = new Currency(
"Stellar",
"XLM",
"Stellar",
[DeviceLabels.SEND, DeviceLabels.DESTINATION, DeviceLabels.FINALIZE, DeviceLabels.CANCEL],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"USDC",
"usdc",
);
static readonly ALGO_USDT = new Currency(
"Algorand",
"ALGO",
"Algorand",
[
DeviceLabels.AMOUT,
DeviceLabels.RECEIVER,
DeviceLabels.CAPS_APPROVE,
DeviceLabels.CAPS_REJECT,
],
[DeviceLabels.ADDRESS, DeviceLabels.CAPS_APPROVE, DeviceLabels.CAPS_REJECT],
"Tether USDt",
"USDT",
);
static readonly TRX_USDT = new Currency(
"Tron",
"TRX",
"Tron",
[DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.SIGN, DeviceLabels.CANCEL],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.CANCEL],
"Tether USD",
"USDT",
);
static readonly TRX_BTT = new Currency(
"Tron",
"TRX",
"Tron",
[DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.SIGN, DeviceLabels.CANCEL],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.CANCEL],
"BitTorrent",
"BTT",
);
static readonly BSC_BUSD = new Currency(
"Binance Smart Chain",
"BNB",
"Binance Smart Chain",
[DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"Binance-Peg BUSD Token",
"BUSD",
);
static readonly BSC_SHIBA = new Currency(
"Binance Smart Chain",
"BNB",
"Binance Smart Chain",
[DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"Shiba Inu",
"SHIB",
);
static readonly MATIC_DAI = new Currency(
"Polygon",
"MATIC",
"Polygon",
[DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"(PoS) Dai Stablecoin",
"DAI",
);
static readonly MATIC_UNI = new Currency(
"Polygon",
"MATIC",
"Polygon",
[DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT],
[DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT],
"Uniswap (PoS)",
"UNI",
);
}
25 changes: 0 additions & 25 deletions apps/ledger-live-desktop/tests/enum/Token.ts

This file was deleted.

16 changes: 1 addition & 15 deletions apps/ledger-live-desktop/tests/models/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { Fee } from "tests/enum/Fee";
import { Account } from "../enum/Account";
import { Token } from "../enum/Token";

export abstract class Transaction {
export class Transaction {
constructor(
public readonly accountToDebit: Account,
public readonly accountToCredit: Account,
public readonly amount: string,
public readonly speed: Fee,
) {}
}
export class BasicTransaction extends Transaction {}
export class TokenTransaction extends Transaction {
constructor(
accountToDebit: Account,
public readonly accountToCredit1: Account,
public readonly accountToCredit2: Account,
amount: string,
speed: Fee,
public readonly token: Token,
) {
super(accountToDebit, accountToCredit1, amount, speed);
}
}
28 changes: 15 additions & 13 deletions apps/ledger-live-desktop/tests/page/account.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { step } from "tests/misc/reporters/step";
import { AppPage } from "tests/page/abstractClasses";
import { Token } from "tests/enum/Token";
import { Account } from "tests/enum/Account";
export class AccountPage extends AppPage {
readonly settingsButton = this.page.getByTestId("account-settings-button");
private settingsDeleteButton = this.page.getByTestId("account-settings-delete-button");
Expand Down Expand Up @@ -33,9 +33,11 @@ export class AccountPage extends AppPage {
private viewDetailsButton = this.page.getByText("View details");

@step("Navigate to token $0")
async navigateToToken(token: Token) {
await expect(this.tokenValue(token.tokenName)).toBeVisible();
await this.tokenValue(token.tokenName).click();
async navigateToToken(SubAccount: Account) {
if (SubAccount.currency.tokenName) {
await expect(this.tokenValue(SubAccount.currency.tokenName)).toBeVisible();
await this.tokenValue(SubAccount.currency.tokenName).click();
}
}

@step("Click `Receive` button")
Expand Down Expand Up @@ -123,8 +125,8 @@ export class AccountPage extends AppPage {
}

@step("Expect token Account to be visible")
async expectTokenAccount(token: Token) {
await expect(this.accountbutton(token.parentAccount.accountName)).toBeVisible();
async expectTokenAccount(Account: Account) {
await expect(this.accountbutton(Account.accountName)).toBeVisible();
}

@step("Expect `show more` button to show more operations")
Expand All @@ -148,15 +150,15 @@ export class AccountPage extends AppPage {
}

@step("Expect token to be present")
async expectTokenToBePresent(token: Token) {
await expect(this.tokenRow(token.tokenTicker)).toBeVisible();
const tokenInfos = await this.tokenRow(token.tokenTicker).innerText();
expect(tokenInfos).toContain(token.tokenName);
expect(tokenInfos).toContain(token.tokenTicker);
async expectTokenToBePresent(SubAccount: Account) {
await expect(this.tokenRow(SubAccount.currency.tokenTicker ?? "")).toBeVisible();
const tokenInfos = await this.tokenRow(SubAccount.currency.tokenTicker ?? "").innerText();
expect(tokenInfos).toContain(SubAccount.currency.tokenName);
expect(tokenInfos).toContain(SubAccount.currency.tokenTicker);
}

@step("navigate to token in account")
async navigateToTokenInAccount(token: Token) {
await this.tokenRow(token.tokenTicker).click();
async navigateToTokenInAccount(SubAccount: Account) {
await this.tokenRow(SubAccount.currency.tokenTicker ?? "").click();
}
}
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/tests/page/drawer/drawer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from "tests/page/abstractClasses";
import { expect } from "@playwright/test";
import { BasicTransaction } from "tests/models/Transaction";
import { Transaction } from "tests/models/Transaction";
import { step } from "tests/misc/reporters/step";

export class Drawer extends Component {
Expand Down Expand Up @@ -32,7 +32,7 @@ export class Drawer extends Component {
}

@step("Verify that the information of the transaction is visible")
async expectReceiverInfos(tx: BasicTransaction) {
async expectReceiverInfos(tx: Transaction) {
await expect(this.addressValue(tx.accountToDebit.address)).toBeVisible();
await expect(this.addressValue(tx.accountToCredit.address)).toBeVisible();
await expect(this.amountValue(tx.amount)).toBeVisible();
Expand Down
27 changes: 15 additions & 12 deletions apps/ledger-live-desktop/tests/page/modal/add.account.modal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { Modal } from "../../component/modal.component";
import { step } from "tests/misc/reporters/step";
import { Token } from "tests/enum/Token";
import { Account } from "tests/enum/Account";

export class AddAccountModal extends Modal {
private selectAccount = this.page.locator("text=Choose a crypto asset"); // FIXME: I need an id
Expand All @@ -13,25 +13,28 @@ export class AddAccountModal extends Modal {
readonly closeButton = this.page.getByTestId("modal-close-button");
private infoBox = this.page.getByTestId("add-token-infoBox");
private successAddLabel = this.page.locator("text=Account added successfully");
private selectTokenNetwork = (token: Token) =>
private selectTokenNetwork = (SubAccount: Account) =>
this.page
.getByRole("option", {
name: `${token.tokenName} (${token.tokenTicker}) ${token.tokenNetwork}`,
name: `${SubAccount.currency.tokenName} (${SubAccount.currency.tokenTicker}) ${SubAccount.currency.uiName}`,
})
.locator("span");
readonly continueButton = this.page.getByTestId("modal-continue-button");

@step("Select token $0")
async selectToken(token: Token) {
async selectToken(SubAccount: Account) {
await this.selectAccount.click();
await this.selectAccountInput.fill(token.tokenName);
if (await this.selectTokenNetwork(token).isVisible()) {
await this.selectTokenNetwork(token).click();
await this.selectAccountInput.fill(SubAccount.currency.tokenName ?? "");
if (await this.selectTokenNetwork(SubAccount).isVisible()) {
await this.selectTokenNetwork(SubAccount).click();
} else {
await this.selectAccountByScrolling(token);
await this.selectAccountByScrolling(SubAccount);
await this.dropdownOptions
.locator(
this.optionWithTextAndFollowingText(token.tokenTicker.toUpperCase(), token.tokenNetwork),
this.optionWithTextAndFollowingText(
SubAccount.currency.tokenTicker?.toUpperCase() ?? "",
SubAccount.currency.uiName,
),
)
.click();
}
Expand All @@ -41,12 +44,12 @@ export class AddAccountModal extends Modal {
}

@step("Select account by scrolling: {0}")
async selectAccountByScrolling(token: Token) {
async selectAccountByScrolling(SubAccount: Account) {
await this.scrollUntilOptionIsDisplayed(
this.dropdownOptionsList,
this.selectTokenNetwork(token),
this.selectTokenNetwork(SubAccount),
);
await this.selectTokenNetwork(token).isVisible();
await this.selectTokenNetwork(SubAccount).isVisible();
}

@step("Select currency $0")
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-desktop/tests/page/modal/receive.modal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { Modal } from "../../component/modal.component";
import { step } from "tests/misc/reporters/step";
import { Token } from "tests/enum/Token";
import { Account } from "tests/enum/Account";

export class ReceiveModal extends Modal {
private skipDeviceButton = this.page.getByTestId("receive-connect-device-skip-device-button");
Expand All @@ -15,9 +15,9 @@ export class ReceiveModal extends Modal {
readonly selectAccountInput = this.page.locator('[placeholder="Search"]');

@step("Select token $0")
async selectToken(token: Token) {
async selectToken(SubAccount: Account) {
await this.selectAccount.click();
await this.selectAccountInput.fill(token.tokenName);
await this.selectAccountInput.fill(SubAccount.currency.tokenName ?? "");
await this.selectAccountInput.press("Enter");
}

Expand Down
Loading

0 comments on commit 2d7b8ed

Please sign in to comment.