Skip to content

Commit ae763e9

Browse files
committed
add tests for amount preservation toggle between fiat and token
1 parent cb9fc71 commit ae763e9

1 file changed

Lines changed: 52 additions & 102 deletions

File tree

extension/e2e-tests/sendPayment.test.ts

Lines changed: 52 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect } from "./test-fixtures";
2-
import { Page } from "@playwright/test";
3-
import { login, loginToTestAccount } from "./helpers/login";
2+
import { BrowserContext, Page } from "@playwright/test";
3+
import { login, loginToTestAccount, switchToMainnet } from "./helpers/login";
44
import { TEST_TOKEN_ADDRESS } from "./helpers/test-token";
55
import {
66
stubAccountBalancesE2e,
@@ -23,6 +23,47 @@ function visibleTokenList(page: Page) {
2323
return page.locator('[data-testid="token-list"]:visible').first();
2424
}
2525

26+
async function stubSendTokenPrices(context: BrowserContext) {
27+
await context.route("**/token-prices", async (route) => {
28+
const request = route.request();
29+
let tokenIds = [] as string[];
30+
31+
if (request.method() === "POST") {
32+
try {
33+
const body = await request.postDataJSON();
34+
tokenIds = body.tokens || [];
35+
} catch {
36+
tokenIds = [];
37+
}
38+
}
39+
40+
const data: Record<
41+
string,
42+
{ currentPrice: string; percentagePriceChange24h: string }
43+
> = {
44+
native: {
45+
currentPrice: "0.4079853099738737",
46+
percentagePriceChange24h: "1.022345803068746424",
47+
},
48+
"USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5": {
49+
currentPrice: "1.0000000000000000",
50+
percentagePriceChange24h: "0.0000000000000000",
51+
},
52+
};
53+
54+
for (const id of tokenIds) {
55+
if (!data[id]) {
56+
data[id] = {
57+
currentPrice: "0.4079853099738737",
58+
percentagePriceChange24h: "1.022345803068746424",
59+
};
60+
}
61+
}
62+
63+
await route.fulfill({ json: { data } });
64+
});
65+
}
66+
2667
async function clickVisibleBackButton(page: Page) {
2768
await page.locator('[data-testid="BackButton"]:visible').first().click();
2869
}
@@ -1011,6 +1052,7 @@ test("Send flow change token from amount screen dismisses back", async ({
10111052
await stubAccountBalancesWithUSDC(page);
10121053
};
10131054
await loginToTestAccount({ page, extensionId, context, stubOverrides });
1055+
await switchToMainnet(page);
10141056

10151057
// Navigate to AMOUNT screen
10161058
await page.getByTestId("nav-link-send").click({ force: true });
@@ -1404,58 +1446,15 @@ test("Send workflow: 25% amount is preserved across fiat toggle and review", asy
14041446
context,
14051447
}) => {
14061448
test.slow();
1449+
await stubSendTokenPrices(context);
14071450
const stubOverrides = async () => {
14081451
await stubAccountBalancesWithUSDC(page);
14091452
};
14101453
await loginToTestAccount({ page, extensionId, context, stubOverrides });
1411-
1412-
await page.route("**/token-prices", async (route) => {
1413-
const request = route.request();
1414-
let tokenIds = [] as string[];
1415-
if (request.method() === "POST") {
1416-
try {
1417-
const body = await request.postDataJSON();
1418-
tokenIds = body.tokens || [];
1419-
} catch {
1420-
tokenIds = [];
1421-
}
1422-
}
1423-
1424-
const data: Record<
1425-
string,
1426-
{ currentPrice: string; percentagePriceChange24h: string }
1427-
> = {
1428-
native: {
1429-
currentPrice: "0.4079853099738737",
1430-
percentagePriceChange24h: "1.022345803068746424",
1431-
},
1432-
"USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5": {
1433-
currentPrice: "1.0000000000000000",
1434-
percentagePriceChange24h: "0.0000000000000000",
1435-
},
1436-
};
1437-
1438-
for (const id of tokenIds) {
1439-
data[id] = {
1440-
currentPrice: "0.4079853099738737",
1441-
percentagePriceChange24h: "1.022345803068746424",
1442-
};
1443-
}
1444-
1445-
await route.fulfill({ json: { data } });
1446-
});
1454+
await switchToMainnet(page);
14471455

14481456
await goToTokenAmountStepFromHomeSend(page);
14491457

1450-
await page.getByTestId("send-amount-edit-dest-asset").click();
1451-
await visibleTokenList(page)
1452-
.getByText("USDC", { exact: true })
1453-
.first()
1454-
.click({ force: true });
1455-
await expect(page.getByTestId("send-amount-edit-dest-asset")).toContainText(
1456-
"USDC",
1457-
);
1458-
14591458
// Set amount via percentage button and capture exact value shown in token mode.
14601459
await page.getByRole("button", { name: "25%" }).click({ force: true });
14611460
const amountInput = page.getByTestId("send-amount-amount-input");
@@ -1465,10 +1464,7 @@ test("Send workflow: 25% amount is preserved across fiat toggle and review", asy
14651464

14661465
// Toggle to fiat and back to token.
14671466
const toggleButton = page.locator(".SendAmount__amount-price button").first();
1468-
test.skip(
1469-
(await toggleButton.count()) === 0,
1470-
"Fiat toggle unavailable in current network/test harness",
1471-
);
1467+
await expect(toggleButton).toHaveCount(1, { timeout: 15000 });
14721468
await expect(toggleButton).toBeVisible({ timeout: 10000 });
14731469
await toggleButton.click({ force: true });
14741470
await page.waitForTimeout(500);
@@ -1485,7 +1481,7 @@ test("Send workflow: 25% amount is preserved across fiat toggle and review", asy
14851481

14861482
await expect(page.getByText("You are sending")).toBeVisible();
14871483
await expect(page.getByTestId("review-tx-send-amount")).toContainText(
1488-
`${amountBeforeToggle.replace(/,/g, "")} USDC`,
1484+
`${amountBeforeToggle.replace(/,/g, "")} XLM`,
14891485
);
14901486
});
14911487

@@ -1495,58 +1491,15 @@ test("Send workflow: typed token amount is preserved across fiat toggle and revi
14951491
context,
14961492
}) => {
14971493
test.slow();
1494+
await stubSendTokenPrices(context);
14981495
const stubOverrides = async () => {
14991496
await stubAccountBalancesWithUSDC(page);
15001497
};
15011498
await loginToTestAccount({ page, extensionId, context, stubOverrides });
1502-
1503-
await page.route("**/token-prices", async (route) => {
1504-
const request = route.request();
1505-
let tokenIds = [] as string[];
1506-
if (request.method() === "POST") {
1507-
try {
1508-
const body = await request.postDataJSON();
1509-
tokenIds = body.tokens || [];
1510-
} catch {
1511-
tokenIds = [];
1512-
}
1513-
}
1514-
1515-
const data: Record<
1516-
string,
1517-
{ currentPrice: string; percentagePriceChange24h: string }
1518-
> = {
1519-
native: {
1520-
currentPrice: "0.4079853099738737",
1521-
percentagePriceChange24h: "1.022345803068746424",
1522-
},
1523-
"USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5": {
1524-
currentPrice: "1.0000000000000000",
1525-
percentagePriceChange24h: "0.0000000000000000",
1526-
},
1527-
};
1528-
1529-
for (const id of tokenIds) {
1530-
data[id] = {
1531-
currentPrice: "0.4079853099738737",
1532-
percentagePriceChange24h: "1.022345803068746424",
1533-
};
1534-
}
1535-
1536-
await route.fulfill({ json: { data } });
1537-
});
1499+
await switchToMainnet(page);
15381500

15391501
await goToTokenAmountStepFromHomeSend(page);
15401502

1541-
await page.getByTestId("send-amount-edit-dest-asset").click();
1542-
await visibleTokenList(page)
1543-
.getByText("USDC", { exact: true })
1544-
.first()
1545-
.click({ force: true });
1546-
await expect(page.getByTestId("send-amount-edit-dest-asset")).toContainText(
1547-
"USDC",
1548-
);
1549-
15501503
const amountInput = page.getByTestId("send-amount-amount-input");
15511504
await expect(amountInput).toBeVisible();
15521505

@@ -1555,10 +1508,7 @@ test("Send workflow: typed token amount is preserved across fiat toggle and revi
15551508

15561509
// Toggle to fiat and back.
15571510
const toggleButton = page.locator(".SendAmount__amount-price button").first();
1558-
test.skip(
1559-
(await toggleButton.count()) === 0,
1560-
"Fiat toggle unavailable in current network/test harness",
1561-
);
1511+
await expect(toggleButton).toHaveCount(1, { timeout: 15000 });
15621512
await expect(toggleButton).toBeVisible({ timeout: 10000 });
15631513
await toggleButton.click({ force: true });
15641514
await page.waitForTimeout(500);
@@ -1575,7 +1525,7 @@ test("Send workflow: typed token amount is preserved across fiat toggle and revi
15751525

15761526
await expect(page.getByText("You are sending")).toBeVisible();
15771527
await expect(page.getByTestId("review-tx-send-amount")).toContainText(
1578-
"11 USDC",
1528+
"11 XLM",
15791529
);
15801530
await expect(page.getByTestId("SubmitAction")).toBeVisible({
15811531
timeout: 15000,

0 commit comments

Comments
 (0)