From d01fe4dfc3dd4e40a8d6c76aa619d95b64e47b84 Mon Sep 17 00:00:00 2001 From: Abdurrahman SASTIM Date: Wed, 30 Oct 2024 23:10:45 +0100 Subject: [PATCH] test: adapt addAccount test --- apps/ledger-live-mobile/e2e/helpers.ts | 8 +++ .../e2e/page/accounts/account.page.ts | 55 +++++++++---------- .../e2e/page/accounts/addAccount.drawer.ts | 35 ++++++++++-- .../e2e/page/accounts/assetAccounts.page.ts | 46 ++++++++++++++++ apps/ledger-live-mobile/e2e/page/index.ts | 2 + .../e2e/specs/addAccounts/addAccount.spec.ts | 6 +- .../e2e/specs/deeplinks.spec.ts | 10 ++-- .../specs/speculos/addAccount/AddAccount.ts | 13 +++-- .../src/components/AccountGraphCard.tsx | 9 ++- .../src/components/AccountRowLayout.tsx | 5 +- .../src/components/SelectableAccountsList.tsx | 6 +- .../screens/Account/AccountHeaderRight.tsx | 1 + .../src/screens/Account/index.tsx | 8 ++- .../AccountAdvancedLogsRow.tsx | 1 + .../screens/AccountSettings/AdvancedLogs.tsx | 4 +- .../src/screens/Accounts/AccountRow.tsx | 1 + .../Accounts/ReadOnly/ReadOnlyAccountRow.tsx | 1 + 17 files changed, 158 insertions(+), 53 deletions(-) create mode 100644 apps/ledger-live-mobile/e2e/page/accounts/assetAccounts.page.ts diff --git a/apps/ledger-live-mobile/e2e/helpers.ts b/apps/ledger-live-mobile/e2e/helpers.ts index 7eb6f1562a6c..bdc5d54f1eb3 100644 --- a/apps/ledger-live-mobile/e2e/helpers.ts +++ b/apps/ledger-live-mobile/e2e/helpers.ts @@ -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. diff --git a/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts b/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts index 162ce01c330c..ee615ad96899 100644 --- a/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts +++ b/apps/ledger-live-mobile/e2e/page/accounts/account.page.ts @@ -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); } } diff --git a/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts b/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts index 0d004f4e20a4..7beee70730a6 100644 --- a/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts +++ b/apps/ledger-live-mobile/e2e/page/accounts/addAccount.drawer.ts @@ -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"; @@ -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() { @@ -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; + } } diff --git a/apps/ledger-live-mobile/e2e/page/accounts/assetAccounts.page.ts b/apps/ledger-live-mobile/e2e/page/accounts/assetAccounts.page.ts new file mode 100644 index 000000000000..f6766bc5f7a5 --- /dev/null +++ b/apps/ledger-live-mobile/e2e/page/accounts/assetAccounts.page.ts @@ -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)); + } +} diff --git a/apps/ledger-live-mobile/e2e/page/index.ts b/apps/ledger-live-mobile/e2e/page/index.ts index 67b420e9d432..6b1931070996 100644 --- a/apps/ledger-live-mobile/e2e/page/index.ts +++ b/apps/ledger-live-mobile/e2e/page/index.ts @@ -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"; @@ -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(); diff --git a/apps/ledger-live-mobile/e2e/specs/addAccounts/addAccount.spec.ts b/apps/ledger-live-mobile/e2e/specs/addAccounts/addAccount.spec.ts index 54f4c26841ed..eaa0b0205d2b 100644 --- a/apps/ledger-live-mobile/e2e/specs/addAccounts/addAccount.spec.ts +++ b/apps/ledger-live-mobile/e2e/specs/addAccounts/addAccount.spec.ts @@ -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); }); }); diff --git a/apps/ledger-live-mobile/e2e/specs/deeplinks.spec.ts b/apps/ledger-live-mobile/e2e/specs/deeplinks.spec.ts index 9fb095c879b6..17510172774e 100644 --- a/apps/ledger-live-mobile/e2e/specs/deeplinks.spec.ts +++ b/apps/ledger-live-mobile/e2e/specs/deeplinks.spec.ts @@ -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(); }); @@ -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 () => { diff --git a/apps/ledger-live-mobile/e2e/specs/speculos/addAccount/AddAccount.ts b/apps/ledger-live-mobile/e2e/specs/speculos/addAccount/AddAccount.ts index 4fe283ea9d06..4988db590a03 100644 --- a/apps/ledger-live-mobile/e2e/specs/speculos/addAccount/AddAccount.ts +++ b/apps/ledger-live-mobile/e2e/specs/speculos/addAccount/AddAccount.ts @@ -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 () => { diff --git a/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx b/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx index 588384f494f2..23adfaa331c4 100644 --- a/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx +++ b/apps/ledger-live-mobile/src/components/AccountGraphCard.tsx @@ -258,6 +258,7 @@ const GraphCardHeader = ({ event="SwitchAccountCurrency" eventProperties={{ useCounterValue: shouldUseCounterValue }} onPress={countervalueAvailable ? onSwitchAccountCurrency : undefined} + testID={`account-graph-${account.id}`} > @@ -273,7 +274,13 @@ const GraphCardHeader = ({ - + {typeof items[1]?.value === "number" ? ( ) : ( diff --git a/apps/ledger-live-mobile/src/components/AccountRowLayout.tsx b/apps/ledger-live-mobile/src/components/AccountRowLayout.tsx index 4b3e6b1391ab..01d5efd5ff16 100644 --- a/apps/ledger-live-mobile/src/components/AccountRowLayout.tsx +++ b/apps/ledger-live-mobile/src/components/AccountRowLayout.tsx @@ -14,6 +14,7 @@ type Props = { currencyUnit?: Unit; countervalueChange?: ValueChange; name: string; + id: string; parentAccountName?: string; tag?: string | null | boolean; onPress?: TouchableOpacityProps["onPress"]; @@ -29,6 +30,7 @@ const AccountRowLayout = ({ currency, currencyUnit, name, + id, parentAccountName, onPress, topLink, @@ -39,7 +41,7 @@ const AccountRowLayout = ({ const { colors, space } = useTheme(); return ( - + {topLink && ( {name} diff --git a/apps/ledger-live-mobile/src/components/SelectableAccountsList.tsx b/apps/ledger-live-mobile/src/components/SelectableAccountsList.tsx index 79d5aab3ecd7..b4a0bfaf616f 100644 --- a/apps/ledger-live-mobile/src/components/SelectableAccountsList.tsx +++ b/apps/ledger-live-mobile/src/components/SelectableAccountsList.tsx @@ -335,7 +335,11 @@ const Header = ({ text, areAllSelected, onSelectAll, onUnselectAll }: HeaderProp onPress={areAllSelected ? onUnselectAll : onSelectAll} hitSlop={selectAllHitSlop} > - + {areAllSelected ? ( ) : ( diff --git a/apps/ledger-live-mobile/src/screens/Account/AccountHeaderRight.tsx b/apps/ledger-live-mobile/src/screens/Account/AccountHeaderRight.tsx index 7583dc446c95..dffadbe646f2 100644 --- a/apps/ledger-live-mobile/src/screens/Account/AccountHeaderRight.tsx +++ b/apps/ledger-live-mobile/src/screens/Account/AccountHeaderRight.tsx @@ -73,6 +73,7 @@ export default function AccountHeaderRight() { )} + , @@ -195,6 +200,7 @@ const AccountScreenInner = ({ keyExtractor={(_: unknown, index: number) => String(index)} showsVerticalScrollIndicator={false} onScroll={handleScroll} + testID={"account-screen-scrollView"} /> { return ( } arrowRight onPress={() => diff --git a/apps/ledger-live-mobile/src/screens/AccountSettings/AdvancedLogs.tsx b/apps/ledger-live-mobile/src/screens/AccountSettings/AdvancedLogs.tsx index 57b7775d6527..f576b67831a1 100644 --- a/apps/ledger-live-mobile/src/screens/AccountSettings/AdvancedLogs.tsx +++ b/apps/ledger-live-mobile/src/screens/AccountSettings/AdvancedLogs.tsx @@ -26,7 +26,7 @@ export default function AdvancedLogs({ route }: NavigationProps) { const { t } = useTranslation(); const usefulData = { xpub: (isAccount(account) && account?.xpub) || undefined, - index: (isAccount(account) && account?.index) || undefined, + index: isAccount(account) && "index" in account ? account.index : undefined, freshAddressPath: (isAccount(account) && account?.freshAddressPath) || undefined, id: account?.id || undefined, blockHeight: (isAccount(account) && account?.blockHeight) || undefined, @@ -69,7 +69,7 @@ export default function AdvancedLogs({ route }: NavigationProps) { time: readableDate, })} - + {JSON.stringify(usefulData, null, 2)} diff --git a/apps/ledger-live-mobile/src/screens/Accounts/AccountRow.tsx b/apps/ledger-live-mobile/src/screens/Accounts/AccountRow.tsx index 1b7a7398f310..16fd862b8a8b 100644 --- a/apps/ledger-live-mobile/src/screens/Accounts/AccountRow.tsx +++ b/apps/ledger-live-mobile/src/screens/Accounts/AccountRow.tsx @@ -110,6 +110,7 @@ const AccountRow = ({ currencyUnit={unit} balance={account.balance} name={name} + id={accountId} countervalueChange={countervalueChange} tag={tag} topLink={topLink} diff --git a/apps/ledger-live-mobile/src/screens/Accounts/ReadOnly/ReadOnlyAccountRow.tsx b/apps/ledger-live-mobile/src/screens/Accounts/ReadOnly/ReadOnlyAccountRow.tsx index 8d4094dbb378..00599683bcc1 100644 --- a/apps/ledger-live-mobile/src/screens/Accounts/ReadOnly/ReadOnlyAccountRow.tsx +++ b/apps/ledger-live-mobile/src/screens/Accounts/ReadOnly/ReadOnlyAccountRow.tsx @@ -31,6 +31,7 @@ const ReadOnlyAccountRow = ({ navigation, currency, screen }: Props) => { currencyUnit={units[0]} balance={new BigNumber(0)} name={name} + id={id} progress={0} /> );