From 4b988ff50c6a90bccb2efdb49af7311b96a607f1 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Wed, 24 Apr 2024 23:00:12 +0200 Subject: [PATCH] god bless playwright --- src/app/(sidebar)/account/create/page.tsx | 7 +++++- src/app/(sidebar)/account/fund/page.tsx | 7 +++--- src/components/FriendBot/ErrorMsg.tsx | 5 ++-- src/components/FriendBot/SuccessMsg.tsx | 8 ++++--- tests/fundAccountPage.test.ts | 29 ++++++++++------------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/app/(sidebar)/account/create/page.tsx b/src/app/(sidebar)/account/create/page.tsx index ea1499fd..faf6bce2 100644 --- a/src/app/(sidebar)/account/create/page.tsx +++ b/src/app/(sidebar)/account/create/page.tsx @@ -92,7 +92,12 @@ export default function CreateAccount() {
- diff --git a/src/app/(sidebar)/account/fund/page.tsx b/src/app/(sidebar)/account/fund/page.tsx index 35bada6e..6e98b26f 100644 --- a/src/app/(sidebar)/account/fund/page.tsx +++ b/src/app/(sidebar)/account/fund/page.tsx @@ -79,7 +79,7 @@ export default function FundAccount() {
{ setShowAlert(false); }} diff --git a/src/components/FriendBot/ErrorMsg.tsx b/src/components/FriendBot/ErrorMsg.tsx index da001c97..f08d5d31 100644 --- a/src/components/FriendBot/ErrorMsg.tsx +++ b/src/components/FriendBot/ErrorMsg.tsx @@ -8,8 +8,8 @@ export const ErrorMsg = ({ onClose: () => void | undefined; isVisible: boolean; errorMsg: string | undefined; -}) => { - return isVisible ? ( +}) => + isVisible ? ( ) : null; -}; diff --git a/src/components/FriendBot/SuccessMsg.tsx b/src/components/FriendBot/SuccessMsg.tsx index 2e08cdd6..6eafc7ae 100644 --- a/src/components/FriendBot/SuccessMsg.tsx +++ b/src/components/FriendBot/SuccessMsg.tsx @@ -6,12 +6,14 @@ import { shortenStellarAddress } from "@/helpers/shortenStellarAddress"; export const SuccessMsg = ({ onClose, + publicKey, isVisible, }: { onClose: () => void | undefined; + publicKey: string; isVisible: boolean; }) => { - const { account, network } = useStore(); + const { network } = useStore(); const IS_STELLAR_EXPERT_ENABLED = network.id === "testnet" || network.id === "mainnet"; @@ -24,11 +26,11 @@ export const SuccessMsg = ({ } actionLink={ IS_STELLAR_EXPERT_ENABLED - ? `https://stellar.expert/explorer/${network.id}/account/${account.publicKey}` + ? `https://stellar.expert/explorer/${network.id}/account/${publicKey}` : undefined } onClose={onClose} - title={`Successfully funded ${shortenStellarAddress(account.publicKey!)} on + title={`Successfully funded ${shortenStellarAddress(publicKey)} on ${network.id}`} > {""} diff --git a/tests/fundAccountPage.test.ts b/tests/fundAccountPage.test.ts index f030d576..56c16ae8 100644 --- a/tests/fundAccountPage.test.ts +++ b/tests/fundAccountPage.test.ts @@ -49,7 +49,7 @@ test.describe("[futurenet/testnet] Fund Account Page", () => { test("By default, 'Public Key' input field is empty and buttons are disabled", async ({ page, }) => { - await expect(page.locator("#generate-keypair-publickey")).toHaveValue(""); + await expect(page.locator("#fund-public-key-input")).toHaveValue(""); const getLumenButton = page .getByTestId("fundAccount-buttons") @@ -65,7 +65,7 @@ test.describe("[futurenet/testnet] Fund Account Page", () => { test("Gets an error with an invalid public key in 'Public Key' field", async ({ page, }) => { - const publicKeyInput = page.locator("#generate-keypair-publickey"); + const publicKeyInput = page.locator("#fund-public-key-input"); // Type in an invalid string in 'Public Key' input field await publicKeyInput.fill("XLKDSFJLSKDJF"); @@ -79,28 +79,25 @@ test.describe("[futurenet/testnet] Fund Account Page", () => { test("Successfully funds an account when clicking 'Get lumens' with a valid public key", async ({ page, }) => { - // Get a new public key - const publicKey = - "GDVOT2ALMUF3G54RBHNJUEV6LOAZCQQCARHEVNUPKGMVPWFC4PFN33QR"; - const publicKeyInput = page.locator("#generate-keypair-publickey"); + const publicKeyInput = page.locator("#fund-public-key-input"); const getLumenButton = page .getByTestId("fundAccount-buttons") .getByText("Get lumens"); - // Type in an invalid string in 'Public Key' input field - await publicKeyInput.fill(publicKey); + await publicKeyInput.fill( + "GB6D5E2HRVBD6QIOXCE6ILMUFQT45LMSZSKRZUCL4ZK6Q6GCNMTJ2E3C", + ); await expect(publicKeyInput).toHaveAttribute("aria-invalid", "false"); await expect(getLumenButton).toBeEnabled(); // Mock the friendbot api call await page.route( - "*/**/?addr=GDVOT2ALMUF3G54RBHNJUEV6LOAZCQQCARHEVNUPKGMVPWFC4PFN33QR", + "*/**/?addr=GB6D5E2HRVBD6QIOXCE6ILMUFQT45LMSZSKRZUCL4ZK6Q6GCNMTJ2E3C", async (route) => { await route.fulfill({ status: 200, - contentType: "application/json", - body: JSON.stringify({}), + contentType: "application/hal+json", }); }, ); @@ -113,10 +110,8 @@ test.describe("[futurenet/testnet] Fund Account Page", () => { await getLumenButton.click(); - // Wait for the mocked response await responsePromise; - // Success is visible const alertBox = page.getByText(/Successfully funded/); await expect(alertBox).toBeVisible(); }); @@ -124,7 +119,7 @@ test.describe("[futurenet/testnet] Fund Account Page", () => { test("Gets an error when submitting 'Get lumens' with a public key that's already been funded", async ({ page, }) => { - const publicKeyInput = page.locator("#generate-keypair-publickey"); + const publicKeyInput = page.locator("#fund-public-key-input"); const getLumenButton = page .getByTestId("fundAccount-buttons") .getByText("Get lumens"); @@ -139,12 +134,12 @@ test.describe("[futurenet/testnet] Fund Account Page", () => { // Mock the friendbot api call await page.route( - "*/**/?addr=GDVOT2ALMUF3G54RBHNJUEV6LOAZCQQCARHEVNUPKGMVPWFC4PFN33QR", + "*/**/?addr=GBX6W44ISK6XTBDDJ5ND6KTJHLYEYHMR4SDG635NRARYVJ3G2YXGDT6Y", async (route) => { await route.fulfill({ status: 400, - contentType: "application/json", - body: JSON.stringify({}), + contentType: "application/problem+json", + body: JSON.stringify({ detail: "createAccountAlreadyExist" }), }); }, );