Skip to content

Commit

Permalink
test: adapt addAccount test
Browse files Browse the repository at this point in the history
  • Loading branch information
abdurrahman-ledger committed Oct 31, 2024
1 parent eedbefb commit e6a91fa
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 53 deletions.
8 changes: 8 additions & 0 deletions apps/ledger-live-mobile/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export async function getTextOfElement(id: string | RegExp, index = 0) {
return (!("elements" in attributes) ? attributes.text : attributes.elements[index].text) || "";
}

export async function getIdOfElement(id: RegExp, index = 0) {
const attributes = await getElementById(id, index).getAttributes();
return (
(!("elements" in attributes) ? attributes.identifier : attributes.elements[index].identifier) ||
""
);
}

/**
* Waits for a specified amount of time
* /!\ Do not use it to wait for a specific element, use waitFor instead.
Expand Down
55 changes: 26 additions & 29 deletions apps/ledger-live-mobile/e2e/page/accounts/account.page.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import { getElementById, getTextOfElement, scrollToId, tapByElement } from "../../helpers";
import { expect } from "detox";
import {
currencyParam,
openDeeplink,
waitForElementById,
getElementById,
tapByElement,
} from "../../helpers";

const baseLink = "account";
import jestExpect from "expect";

export default class AccountPage {
accountSettingsButton = () => getElementById("accounts-settings");
assetBalance = () => getElementById("asset-graph-balance");
accountTitleId = (assetName: string) => `accounts-title-${assetName}`;
accountAssetId = (assetName: string) => `account-assets-${assetName}`;

async waitForAccountPageToLoad(assetName: string) {
await waitForElementById(this.accountTitleId(assetName.toLowerCase()));
}
accountGraph = (accountId: string) => getElementById(`account-graph-${accountId}`);
accountBalance = (accountId: string) => getElementById(`account-balance-${accountId}`);
accountSettingsButton = () => getElementById("account-settings-button");
accountAdvancedLogRow = () => getElementById("account-advanced-log-row");
operationHistorySectionId = (accountId: string) => `operations-history-${accountId}`;
accountScreenScrollView = "account-screen-scrollView";
accountAdvancedLogsId = "account-advanced-logs";

async expectAccountBalanceVisible() {
await expect(this.assetBalance()).toBeVisible();
async openAccountSettings() {
await tapByElement(this.accountSettingsButton());
}

async expectAccountBalance(expectedBalance: string) {
await expect(this.assetBalance()).toHaveText(expectedBalance);
async openAccountAdvancedLogs() {
await tapByElement(this.accountAdvancedLogRow());
}

async waitForAccountAssetsToLoad(assetName: string) {
await waitForElementById(this.accountTitleId(assetName));
await waitForElementById(this.accountAssetId(assetName));
async expectOperationHistoryVisible(accountId: string) {
const id = this.operationHistorySectionId(accountId);
await scrollToId(id, this.accountScreenScrollView);
await expect(getElementById(id)).toBeVisible();
}

async openViaDeeplink(currencyLong?: string) {
const link = currencyLong ? baseLink + currencyParam + currencyLong : baseLink;
await openDeeplink(link);
async expectAccountBalanceVisible(accountId: string) {
await expect(this.accountGraph(accountId)).toBeVisible();
await expect(this.accountBalance(accountId)).toBeVisible();
}

async openAccountSettings() {
await tapByElement(this.accountSettingsButton());
async expectAddressIndex(indexNumber: number) {
await this.openAccountSettings();
await this.openAccountAdvancedLogs();
const advancedLogsText = await getTextOfElement(this.accountAdvancedLogsId);
const advancedLogsJson = advancedLogsText ? JSON.parse(advancedLogsText) : null;
jestExpect(advancedLogsJson).toHaveProperty("index", indexNumber);
}
}
35 changes: 31 additions & 4 deletions apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { expect } from "detox";
import {
getElementById,
getIdOfElement,
openDeeplink,
scrollToId,
tapById,
waitForElementById,
} from "../../helpers";
import { getEnv } from "@ledgerhq/live-env";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";

const baseLink = "add-account";
const isMock = getEnv("MOCK");

export default class AddAccountDrawer {
accountCardId = (id: string | RegExp) => getElementById(new RegExp(`account-card-${id}`));
deselectAllButtonId = "add-accounts-deselect-all";
accountCardRegExp = (id = ".*") => new RegExp(`account-card-${id}`);
accountCard = (id: string) => getElementById(this.accountCardRegExp(id));
accountId = (currency: string, index: number) =>
isMock ? `mock:1:${currency}:MOCK_${currency}_${index}:` : `js:2:${currency}:.*`;
accountTitleId = (accountName: string) => getElementById(`test-id-account-${accountName}`);
accountTitleId = (accountName: string, index: number) =>
getElementById(`test-id-account-${accountName}`, index);
modalButtonId = "add-accounts-modal-add-button";
currencyRow = (currencyId: string) => `currency-row-${currencyId}`;
continueButtonId = "add-accounts-continue-button";
Expand All @@ -42,8 +47,8 @@ export default class AddAccountDrawer {

async expectAccountDiscovery(currencyName: string, currencyId: string, index = 0) {
const accountName = `${currencyName} ${index + 1}`;
await expect(this.accountCardId(this.accountId(currencyId, index))).toBeVisible();
await expect(this.accountTitleId(accountName)).toHaveText(accountName);
await expect(this.accountCard(this.accountId(currencyId, index))).toBeVisible();
await expect(this.accountTitleId(accountName, index)).toHaveText(accountName);
}

async finishAccountsDiscovery() {
Expand All @@ -55,4 +60,26 @@ export default class AddAccountDrawer {
await waitForElementById(this.succesCtaId);
await tapById(this.succesCtaId);
}

async addFirstAccount(currency: Currency) {
await this.startAccountsDiscovery();
await this.expectAccountDiscovery(currency.name, currency.currencyId);
await tapById(this.deselectAllButtonId);
await tapById(this.accountCardRegExp(), 0);
const accountId = (await getIdOfElement(this.accountCardRegExp(), 0)).replace(
/^account-card-/,
"",
);
await this.finishAccountsDiscovery();
await this.tapSuccessCta();
return accountId;
}

async addAccount(currency: Currency) {
await this.startAccountsDiscovery();
const accountName = await this.expectAccountDiscovery(currency.name, currency.currencyId);
await this.finishAccountsDiscovery();
await this.tapSuccessCta();
return accountName;
}
}
46 changes: 46 additions & 0 deletions apps/ledger-live-mobile/e2e/page/accounts/assetAccounts.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect } from "detox";
import {
currencyParam,
openDeeplink,
waitForElementById,
getElementById,
scrollToId,
tapById,
} from "../../helpers";

const baseLink = "account";

export default class AssetAccountsPage {
assetBalance = () => getElementById("asset-graph-balance");
titleId = (assetName: string) => `accounts-title-${assetName}`;
accountAssetId = (assetName: string) => `account-assets-${assetName}`;
accountRowId = (accountId: string) => `account-row-${accountId}`;
accountNameRegExp = /account-row-name-.*/;

async waitForAccountPageToLoad(assetName: string) {
await waitForElementById(this.titleId(assetName.toLowerCase()));
}

async expectAccountsBalanceVisible() {
await expect(this.assetBalance()).toBeVisible();
}

async expectAccountsBalance(expectedBalance: string) {
await expect(this.assetBalance()).toHaveText(expectedBalance);
}

async waitForAccountAssetsToLoad(assetName: string) {
await waitForElementById(this.titleId(assetName));
await waitForElementById(this.accountAssetId(assetName));
}

async openViaDeeplink(currencyLong?: string) {
const link = currencyLong ? baseLink + currencyParam + currencyLong : baseLink;
await openDeeplink(link);
}

async goToAccount(accountId: string) {
await scrollToId(this.accountNameRegExp);
await tapById(this.accountRowId(accountId));
}
}
2 changes: 2 additions & 0 deletions apps/ledger-live-mobile/e2e/page/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AssetAccountsPage from "./accounts/assetAccounts.page";
import AccountPage from "./accounts/account.page";
import AccountsPage from "./accounts/accounts.page";
import AddAccountDrawer from "./accounts/addAccount.drawer";
Expand Down Expand Up @@ -30,6 +31,7 @@ import { DeviceLike } from "~/reducers/types";
import { loadAccounts, loadBleState, loadConfig } from "../bridge/server";

export class Application {
public assetAccountsPage = new AssetAccountsPage();
public account = new AccountPage();
public accounts = new AccountsPage();
public addAccount = new AddAccountDrawer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe("Add account from modal", () => {
await deviceAction.selectMockDevice();
await deviceAction.openApp();
await app.addAccount.startAccountsDiscovery();
await app.addAccount.expectAccountDiscovery(capitalize(testedCurrency), testedCurrency, 1);
await app.addAccount.expectAccountDiscovery(capitalize(testedCurrency), testedCurrency, 0);
await app.addAccount.finishAccountsDiscovery();
await app.addAccount.tapSuccessCta();
});

$TmsLink("B2CQA-101");
it("displays Bitcoin accounts page summary", async () => {
await app.account.waitForAccountPageToLoad(testedCurrency);
await app.account.expectAccountBalance(expectedBalance);
await app.assetAccountsPage.waitForAccountPageToLoad(testedCurrency);
await app.assetAccountsPage.expectAccountsBalance(expectedBalance);
});
});
10 changes: 5 additions & 5 deletions apps/ledger-live-mobile/e2e/specs/deeplinks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("DeepLinks Tests", () => {
});

it("should open Account page", async () => {
await app.account.openViaDeeplink();
await app.assetAccountsPage.openViaDeeplink();
await app.accounts.waitForAccountsPageToLoad();
});

Expand All @@ -31,13 +31,13 @@ describe("DeepLinks Tests", () => {
});

it("should open ETH Account Asset page when given currency param", async () => {
await app.account.openViaDeeplink(ethereumLong);
await app.account.waitForAccountAssetsToLoad(ethereumLong);
await app.assetAccountsPage.openViaDeeplink(ethereumLong);
await app.assetAccountsPage.waitForAccountAssetsToLoad(ethereumLong);
});

it("should open BTC Account Asset page when given currency param", async () => {
await app.account.openViaDeeplink(bitcoinLong);
await app.account.waitForAccountAssetsToLoad(bitcoinLong);
await app.assetAccountsPage.openViaDeeplink(bitcoinLong);
await app.assetAccountsPage.waitForAccountAssetsToLoad(bitcoinLong);
});

it("should open Custom Lock Screen page", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export async function runAddAccountTest(currency: Currency, tmsLink: string) {

deviceNumber = await app.common.addSpeculos(currency.speculosApp.name);

await app.addAccount.startAccountsDiscovery();
await app.addAccount.expectAccountDiscovery(currency.name, currency.currencyId);
await app.addAccount.finishAccountsDiscovery();
await app.addAccount.tapSuccessCta();
await app.account.waitForAccountPageToLoad(currency.name);
await app.account.expectAccountBalanceVisible();
const accountId = await app.addAccount.addFirstAccount(currency);
await app.assetAccountsPage.waitForAccountPageToLoad(currency.name);
await app.assetAccountsPage.expectAccountsBalanceVisible();
await app.assetAccountsPage.goToAccount(accountId);
await app.account.expectAccountBalanceVisible(accountId);
await app.account.expectOperationHistoryVisible(accountId);
await app.account.expectAddressIndex(0);
});

afterAll(async () => {
Expand Down
9 changes: 8 additions & 1 deletion apps/ledger-live-mobile/src/components/AccountGraphCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const GraphCardHeader = ({
event="SwitchAccountCurrency"
eventProperties={{ useCounterValue: shouldUseCounterValue }}
onPress={countervalueAvailable ? onSwitchAccountCurrency : undefined}
testID={`account-graph-${account.id}`}
>
<Flex flexDirection="row" alignItems="center" width="100%">
<Box maxWidth={"50%"}>
Expand All @@ -273,7 +274,13 @@ const GraphCardHeader = ({
</Flex>

<Flex flexDirection="row" mb={4}>
<Text variant={"large"} fontWeight={"medium"} color={"neutral.c70"} numberOfLines={1}>
<Text
variant={"large"}
fontWeight={"medium"}
color={"neutral.c70"}
numberOfLines={1}
testID={`account-balance-${account.id}`}
>
{typeof items[1]?.value === "number" ? (
<CurrencyUnitValue {...items[1]} />
) : (
Expand Down
5 changes: 4 additions & 1 deletion apps/ledger-live-mobile/src/components/AccountRowLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Props = {
currencyUnit?: Unit;
countervalueChange?: ValueChange;
name: string;
id: string;
parentAccountName?: string;
tag?: string | null | boolean;
onPress?: TouchableOpacityProps["onPress"];
Expand All @@ -29,6 +30,7 @@ const AccountRowLayout = ({
currency,
currencyUnit,
name,
id,
parentAccountName,
onPress,
topLink,
Expand All @@ -39,7 +41,7 @@ const AccountRowLayout = ({
const { colors, space } = useTheme();

return (
<TouchableOpacity onPress={onPress}>
<TouchableOpacity onPress={onPress} testID={`account-row-${id}`}>
{topLink && (
<Flex
width="1px"
Expand All @@ -60,6 +62,7 @@ const AccountRowLayout = ({
numberOfLines={1}
flexGrow={0}
flexShrink={1}
testID={`account-row-name-${name}`}
>
{name}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ const Header = ({ text, areAllSelected, onSelectAll, onUnselectAll }: HeaderProp
onPress={areAllSelected ? onUnselectAll : onSelectAll}
hitSlop={selectAllHitSlop}
>
<Text fontSize={14} color="neutral.c70">
<Text
fontSize={14}
color="neutral.c70"
testID={`add-accounts-${areAllSelected ? "deselect" : "select"}-all`}
>
{areAllSelected ? (
<Trans i18nKey="selectableAccountsList.deselectAll" />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function AccountHeaderRight() {
)}
<Touchable
event="button_clicked"
testID="account-settings-button"
eventProperties={{
button: "Account Settings",
}}
Expand Down
8 changes: 7 additions & 1 deletion apps/ledger-live-mobile/src/screens/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ const AccountScreenInner = ({
...listHeaderComponents,
...(!isEmpty
? [
<SectionContainer key={"section-container-accounts"} px={6} isLast>
<SectionContainer
key={"section-container-accounts"}
px={6}
isLast
testID={`operations-history-${account.id}`}
>
<SectionTitle title={t("analytics.operations.title")} />
<OperationsHistorySection accounts={[account]} />
</SectionContainer>,
Expand Down Expand Up @@ -195,6 +200,7 @@ const AccountScreenInner = ({
keyExtractor={(_: unknown, index: number) => String(index)}
showsVerticalScrollIndicator={false}
onScroll={handleScroll}
testID={"account-screen-scrollView"}
/>
<AccountHeader
currentPositionY={currentPositionY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const AccountAdvancedLogsRow = ({ navigation, account }: Props) => {
return (
<SettingsRow
event="AccountAdvancedLogsRow"
testID="account-advanced-log-row"
title={<Trans i18nKey="account.settings.advanced.title" />}
arrowRight
onPress={() =>
Expand Down
Loading

0 comments on commit e6a91fa

Please sign in to comment.