Skip to content

Commit 90e0e92

Browse files
Merge pull request #10571 from LedgerHQ/feat/swap-test-cases2
Feat/swap test cases2
2 parents 80a3e24 + b68f356 commit 90e0e92

22 files changed

+379
-41
lines changed

apps/ledger-live-mobile/src/components/DeviceAction/rendering.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export function renderConfirmSwap({
286286

287287
<Flex justifyContent={"space-between"} width="100%">
288288
<FieldItem title={t("DeviceAction.swap2.amountSent")}>
289-
<Text>
289+
<Text testID="amountSent">
290290
<CurrencyUnitValue
291291
value={transaction.amount}
292292
unit={unitFrom}
@@ -297,7 +297,7 @@ export function renderConfirmSwap({
297297
</FieldItem>
298298

299299
<FieldItem title={t("DeviceAction.swap2.amountReceived")}>
300-
<Text>
300+
<Text testID="amountReceived">
301301
<CurrencyUnitValue
302302
unit={unitTo}
303303
value={amountExpectedTo ? new BigNumber(amountExpectedTo) : null}
@@ -313,12 +313,12 @@ export function renderConfirmSwap({
313313
<ProviderIcon size="XXS" name={provider} />
314314
</Flex>
315315

316-
<Text>{providerName}</Text>
316+
<Text testID="provider">{providerName}</Text>
317317
</Flex>
318318
</FieldItem>
319319

320320
<FieldItem title={t("DeviceAction.swap2.fees")}>
321-
<Text>
321+
<Text testID="fees">
322322
<CurrencyUnitValue
323323
unit={getFeesUnit(
324324
getFeesCurrency(getMainAccount(exchange.fromAccount, exchange.fromParentAccount)),
@@ -333,14 +333,18 @@ export function renderConfirmSwap({
333333
<FieldItem title={t("DeviceAction.swap2.sourceAccount")}>
334334
<Flex flexDirection="row" alignItems="center">
335335
<CurrencyIcon size={20} currency={getAccountCurrency(exchange.fromAccount)} />
336-
<Text marginLeft={2}>{fromAccountName}</Text>
336+
<Text marginLeft={2} testID="sourceAccount">
337+
{fromAccountName}
338+
</Text>
337339
</Flex>
338340
</FieldItem>
339341

340342
<FieldItem title={t("DeviceAction.swap2.targetAccount")}>
341343
<Flex flexDirection="row" alignItems="center">
342344
<CurrencyIcon size={20} currency={getAccountCurrency(exchange.toAccount)} />
343-
<Text marginLeft={2}>{toAccountName}</Text>
345+
<Text marginLeft={2} testID="targetAccount">
346+
{toAccountName}
347+
</Text>
344348
</Flex>
345349
</FieldItem>
346350
</Flex>

e2e/mobile/helpers/elementHelpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ export const WebElementHelpers = {
222222
},
223223

224224
getWebElementsByIdAndText(id: string, text: string, index = 0): WebElement {
225-
const base = web.element(
226-
by.web.xpath(`//span[@data-testid="${id}" and text()="${text}"]`),
227-
) as IndexedWebElement;
225+
const xpath = id
226+
? `//span[@data-testid="${id}" and text()="${text}"]`
227+
: `//span[text()="${text}"]`;
228+
const base = web.element(by.web.xpath(xpath)) as IndexedWebElement;
228229
return index > 0 ? base.atIndex(index) : base;
229230
},
230231

e2e/mobile/page/liveApps/swapLiveApp.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Provider } from "@ledgerhq/live-common/e2e/enum/Provider";
22
import { allure } from "jest-allure2-reporter/api";
33
import { getMinimumSwapAmount } from "@ledgerhq/live-common/e2e/swap";
4-
import { SwapType } from "@ledgerhq/live-common/e2e/models/Swap";
4+
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
55

66
export default class SwapLiveAppPage {
77
fromSelector = "from-account-coin-selector";
@@ -14,6 +14,10 @@ export default class SwapLiveAppPage {
1414
quoteProviderName = "quote-card-provider-name";
1515
executeSwapButton = "execute-button";
1616
deviceActionErrorDescriptionId = "error-description-deviceAction";
17+
fromAccountErrorId = "from-account-error";
18+
showDetailslink = "show-details-link";
19+
quotesContainerErrorIcon = "quotes-container-error-icon";
20+
insufficientFundsBuyButton = "insufficient-funds-buy-button";
1721

1822
@Step("Wait for swap live app")
1923
async waitForSwapLiveApp() {
@@ -52,6 +56,11 @@ export default class SwapLiveAppPage {
5256
await waitWebElementByTestId(this.numberOfQuotes);
5357
}
5458

59+
@Step("verify quotes are displayed")
60+
async checkQuotes() {
61+
await detoxExpect(getWebElementByTestId(this.numberOfQuotes)).toExist();
62+
}
63+
5564
@Step("Select available provider")
5665
async selectExchange() {
5766
let index = 0;
@@ -82,10 +91,8 @@ export default class SwapLiveAppPage {
8291
}
8392

8493
@Step("Get minimum amount for swap")
85-
async getMinimumAmount(swap: SwapType) {
86-
return (
87-
(await getMinimumSwapAmount(swap.accountToDebit, swap.accountToCredit))?.toString() ?? ""
88-
);
94+
async getMinimumAmount(fromAccount: Account, toAccount: Account) {
95+
return (await getMinimumSwapAmount(fromAccount, toAccount))?.toString() ?? "";
8996
}
9097

9198
@Step("Get provider list")
@@ -136,7 +143,7 @@ export default class SwapLiveAppPage {
136143
await this.checkExchangeButtonHasProviderName(providerList[0]);
137144
}
138145

139-
@Step("Check exchange button has provider name")
146+
@Step("Check exchange button has provider name: $0")
140147
async checkExchangeButtonHasProviderName(provider: string) {
141148
const expectedButtonText = [
142149
Provider.ONE_INCH.uiName,
@@ -192,4 +199,24 @@ export default class SwapLiveAppPage {
192199
}
193200
return quotes;
194201
}
202+
203+
@Step("Verify swap amount error message match: $0")
204+
async verifySwapAmountErrorMessageIsCorrect(expectedMessage: string | RegExp) {
205+
await waitWebElementByTestId(this.fromAccountErrorId);
206+
const errorText: string = await getWebElementText(this.fromAccountErrorId);
207+
if (typeof expectedMessage === "string") {
208+
jestExpect(errorText).toContain(expectedMessage);
209+
} else if (expectedMessage instanceof RegExp) {
210+
jestExpect(errorText).toMatch(expectedMessage);
211+
}
212+
}
213+
214+
@Step("Verify swap CTA banner displayed")
215+
async checkCtaBanner() {
216+
await waitWebElementByTestId(this.showDetailslink);
217+
const showDetailsLink = getWebElementByTestId(this.showDetailslink);
218+
await showDetailsLink.runScript("(el) => el.click()");
219+
await detoxExpect(getWebElementByTestId(this.quotesContainerErrorIcon)).toExist();
220+
await detoxExpect(getWebElementByTestId(this.insufficientFundsBuyButton)).toExist();
221+
}
195222
}

e2e/mobile/page/speculos.page.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
signDelegationTransaction,
77
signSendTransaction,
88
verifyAmountsAndAcceptSwap,
9+
verifyAmountsAndRejectSwap,
910
} from "@ledgerhq/live-common/e2e/speculos";
1011
import { TransactionType } from "@ledgerhq/live-common/e2e/models/Transaction";
1112
import { DelegateType } from "@ledgerhq/live-common/e2e/models/Delegate";
1213
import { AccountType } from "@ledgerhq/live-common/e2e/enum/Account";
1314
import { SwapType } from "@ledgerhq/live-common/e2e/models/Swap";
15+
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
1416

1517
export default class SpeculosPage {
1618
@Step("Verify receive address correctness on device")
@@ -43,9 +45,21 @@ export default class SpeculosPage {
4345
await verifyAmountsAndAcceptSwap(swap, amount);
4446
}
4547

46-
async setExchangeDependencies(swap: SwapType) {
48+
@Step("Verify amounts and reject swap")
49+
async verifyAmountsAndRejectSwap(swap: SwapType, amount: string) {
50+
await verifyAmountsAndRejectSwap(swap, amount);
51+
}
52+
53+
async setExchangeDependencies(swapOrFromAccount: SwapType | Account, toAccount?: Account) {
54+
let accounts: Account[];
55+
if (toAccount) {
56+
accounts = [swapOrFromAccount as Account, toAccount];
57+
} else {
58+
const swap = swapOrFromAccount as SwapType;
59+
accounts = [swap.accountToDebit, swap.accountToCredit];
60+
}
4761
setExchangeDependencies(
48-
[swap.accountToDebit, swap.accountToCredit].map(acc => ({
62+
accounts.map(acc => ({
4963
name: acc.currency.speculosApp.name.replace(/ /g, "_"),
5064
})),
5165
);

e2e/mobile/page/trade/swap.page.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { getMinimumSwapAmount } from "@ledgerhq/live-common/lib/e2e/swap";
21
import { delay, isIos, isSpeculosRemote, openDeeplink } from "../../helpers/commonHelpers";
32
import { SwapType } from "@ledgerhq/live-common/e2e/models/Swap";
4-
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
53

64
export default class SwapPage {
75
baseLink = "swap";
86
confirmSwapOnDeviceDrawerId = "confirm-swap-on-device";
97
swapSuccessTitleId = "swap-success-title";
108
deviceActionLoading = "device-action-loading";
9+
amountReceived = "amountReceived";
10+
fees = "fees";
11+
amountSent = "amountSent";
12+
sourceAccount = "sourceAccount";
13+
targetAccount = "targetAccount";
14+
swapProvider = "provider";
1115

1216
swapFormTab = () => getElementById("swap-form-tab");
1317

@@ -30,6 +34,14 @@ export default class SwapPage {
3034
await waitForElementNotVisible(this.deviceActionLoading);
3135
}
3236

37+
@Step("Verify the amounts and reject swap")
38+
async verifyAmountsAndRejectSwap(swap: SwapType, amount: string) {
39+
await waitForElementById(this.confirmSwapOnDeviceDrawerId);
40+
await app.speculos.verifyAmountsAndRejectSwap(swap, amount);
41+
await this.delayDeviceActionLoadingCheck();
42+
await waitForElementNotVisible(this.deviceActionLoading);
43+
}
44+
3345
@Step("Wait for swap success and continue")
3446
async waitForSuccessAndContinue() {
3547
await waitForElementById(this.swapSuccessTitleId);
@@ -40,8 +52,42 @@ export default class SwapPage {
4052
await delay(isSpeculosRemote() && isIos() ? 45_000 : 20_000);
4153
}
4254

43-
@Step("Check minimum amount for swap")
44-
async getMinimumAmount(accountFrom: Account, accountTo: Account) {
45-
return (await getMinimumSwapAmount(accountFrom, accountTo))?.toString() ?? "";
55+
@Step("Get amount to receive")
56+
async getAmountToReceive() {
57+
return (await getTextOfElement(this.amountReceived)).trim();
58+
}
59+
60+
@Step("Get fees")
61+
async getFees() {
62+
return (await getTextOfElement(this.fees)).trim();
63+
}
64+
65+
@Step("Verify amount to receive: $0")
66+
async verifyAmountToReceive(amount: string) {
67+
const received = (await getTextOfElement(this.amountReceived)).replace(/\s/g, "");
68+
const expected = amount.replace(/\s/g, "");
69+
jestExpect(received).toBe(expected);
70+
}
71+
72+
@Step("Verify amount to send: $0 $1")
73+
async verifyAmountSent(amount: string, currency: string) {
74+
const received = (await getTextOfElement(this.amountSent)).replace(/\s/g, "");
75+
const expected = `${amount} ${currency}`.replace(/\s/g, "");
76+
jestExpect(received).toBe(expected);
77+
}
78+
79+
@Step("Verify source currency: $0")
80+
async verifySourceAccount(sourceCurrency: string) {
81+
jestExpect((await getTextOfElement(this.sourceAccount)).trim()).toMatch(sourceCurrency);
82+
}
83+
84+
@Step("Verify target currency: $0")
85+
async verifyTargetCurrency(targetCurrency: string) {
86+
jestExpect((await getTextOfElement(this.targetAccount)).trim()).toMatch(targetCurrency);
87+
}
88+
89+
@Step("Verify provider: $0")
90+
async verifyProvider(provider: string) {
91+
jestExpect((await getTextOfElement(this.swapProvider)).trim()).toMatch(provider);
4692
}
4793
}

0 commit comments

Comments
 (0)