Skip to content

Commit

Permalink
god bless playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeesun Kim authored and Jeesun Kim committed Apr 24, 2024
1 parent 39d2aa2 commit 4b988ff
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
7 changes: 6 additions & 1 deletion src/app/(sidebar)/account/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ export default function CreateAccount() {
</Text>
</div>
<div className="Account__CTA" data-testid="createAccount-buttons">
<Button size="md" variant="secondary" onClick={generateKeypair}>
<Button
disabled={isLoading || isFetching}
size="md"
variant="secondary"
onClick={generateKeypair}
>
Generate keypair
</Button>

Expand Down
7 changes: 3 additions & 4 deletions src/app/(sidebar)/account/fund/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function FundAccount() {
</div>

<Input
id="generate-keypair-publickey"
id="fund-public-key-input"
fieldSize="md"
label="Public Key"
value={generatedPublicKey}
Expand Down Expand Up @@ -123,9 +123,8 @@ export default function FundAccount() {
</Card>

<SuccessMsg
isVisible={Boolean(
showAlert && isFetchedAfterMount && isSuccess && account.publicKey,
)}
isVisible={Boolean(showAlert && isFetchedAfterMount && isSuccess)}
publicKey={generatedPublicKey}
onClose={() => {
setShowAlert(false);
}}
Expand Down
5 changes: 2 additions & 3 deletions src/components/FriendBot/ErrorMsg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const ErrorMsg = ({
onClose: () => void | undefined;
isVisible: boolean;
errorMsg: string | undefined;
}) => {
return isVisible ? (
}) =>
isVisible ? (
<Alert
placement="inline"
variant="error"
Expand All @@ -19,4 +19,3 @@ export const ErrorMsg = ({
{""}
</Alert>
) : null;
};
8 changes: 5 additions & 3 deletions src/components/FriendBot/SuccessMsg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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}`}
>
{""}
Expand Down
29 changes: 12 additions & 17 deletions tests/fundAccountPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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");
Expand All @@ -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",
});
},
);
Expand All @@ -113,18 +110,16 @@ test.describe("[futurenet/testnet] Fund Account Page", () => {

await getLumenButton.click();

// Wait for the mocked response
await responsePromise;

// Success <Alert/> is visible
const alertBox = page.getByText(/Successfully funded/);
await expect(alertBox).toBeVisible();
});

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");
Expand All @@ -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" }),
});
},
);
Expand Down

0 comments on commit 4b988ff

Please sign in to comment.