-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding tests for create and fund account #808
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4243415
adding tests for create and fund account
abc83ff
add tests for 'Create Account' page
35b04f2
update tests to use a string instead of regex
6183740
hide fund account and update tests
23223ae
remove filtered nav from account page
feca2d0
remove switching to 'mainnet' from 'testnet' for now
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,33 +4,50 @@ import React from "react"; | |
|
||
import { LayoutSidebarContent } from "@/components/layout/LayoutSidebarContent"; | ||
import { Routes } from "@/constants/routes"; | ||
import { useIsTestingNetwork } from "@/hooks/useIsTestingNetwork"; | ||
|
||
// Includes navigation items that should ONLY display | ||
// in TESTNET or FUTURENET | ||
const DEFAULT_ACCOUNT_NAV_ITEMS = [ | ||
{ | ||
route: Routes.ACCOUNT_CREATE, | ||
label: "Create Account", | ||
}, | ||
{ | ||
route: Routes.ACCOUNT_FUND, | ||
label: "Fund Account", | ||
isTestnetOnly: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for filtering on side nav There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We won't need this extra logic for the new update where we're not hiding the nav, right? Just a note for the next PR. 🤓 |
||
}, | ||
{ | ||
route: Routes.ACCOUNT_CREATE_MUXED, | ||
label: "Create Muxed Account", | ||
}, | ||
{ | ||
route: Routes.ACCOUNT_PARSE_MUXED, | ||
label: "Parse Muxed Account", | ||
}, | ||
]; | ||
|
||
export default function AccountTemplate({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const IS_TESTING_NETWORK = useIsTestingNetwork(); | ||
|
||
// Filtered navigation items for MAINNET | ||
const filteredNavItems = DEFAULT_ACCOUNT_NAV_ITEMS.filter( | ||
({ isTestnetOnly }) => !isTestnetOnly, | ||
); | ||
|
||
const navItems = IS_TESTING_NETWORK | ||
? DEFAULT_ACCOUNT_NAV_ITEMS | ||
: filteredNavItems; | ||
|
||
return ( | ||
<LayoutSidebarContent | ||
sidebar={{ | ||
navItems: [ | ||
{ | ||
route: Routes.ACCOUNT_CREATE, | ||
label: "Create Account", | ||
}, | ||
{ | ||
route: Routes.ACCOUNT_FUND, | ||
label: "Fund Account", | ||
}, | ||
{ | ||
route: Routes.ACCOUNT_CREATE_MUXED, | ||
label: "Create Muxed Account", | ||
}, | ||
{ | ||
route: Routes.ACCOUNT_PARSE_MUXED, | ||
label: "Parse Muxed Account", | ||
}, | ||
], | ||
navItems, | ||
}} | ||
> | ||
{children} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useStore } from "@/store/useStore"; | ||
|
||
export const useIsTestingNetwork = (): boolean => { | ||
jeesunikim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { network } = useStore(); | ||
|
||
return network.id === "testnet" || network.id === "futurenet"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test.describe("Create Account Page", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://localhost:3000/account/create"); | ||
}); | ||
|
||
test("Loads", async ({ page }) => { | ||
await expect(page.locator("h1")).toHaveText("Keypair Generator"); | ||
}); | ||
|
||
test("Renders 'Generate keypair' and 'Fund account' button", async ({ | ||
page, | ||
}) => { | ||
const buttonContainer = page.getByTestId("createAccount-buttons"); | ||
expect(buttonContainer.getByText("Generate keypair")).toBeVisible; | ||
expect(buttonContainer.getByText("Fund account with Friendbot")) | ||
.toBeVisible; | ||
}); | ||
|
||
test("Test 'Generate keypair' button", async ({ page }) => { | ||
await page.getByRole("button", { name: "Generate keypair" }).click(); | ||
|
||
await expect( | ||
page.locator("input[id='generate-keypair-publickey']"), | ||
).toHaveValue(/^G/); | ||
await expect( | ||
page.locator("input[id='generate-keypair-secretkey']"), | ||
).toHaveValue(/^S/); | ||
}); | ||
|
||
test("Test 'Fund account' button", async ({ page }) => { | ||
await page | ||
.getByRole("button", { name: "Fund account with Friendbot" }) | ||
.click(); | ||
|
||
await expect(page).toHaveURL(/.*\/account\/fund/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
import { Account, MuxedAccount } from "@stellar/stellar-sdk"; | ||
|
||
test.describe("Create Muxed Account Page", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://localhost:3000/account/muxed-create"); | ||
}); | ||
|
||
test("Loads", async ({ page }) => { | ||
await expect(page.locator("h1")).toHaveText("Create Multiplexed Account"); | ||
}); | ||
|
||
test("Renders 'Base Account G Address' and 'Muxed Account ID' input field", async ({ | ||
page, | ||
}) => { | ||
expect(page.locator("input[id='muxed-public-key']")).toBeVisible; | ||
expect(page.locator("input[id='muxed-account-iD']")).toBeVisible; | ||
jeesunikim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
test("Gets an error with an invalid public key in 'Base Account G Address' field", async ({ | ||
page, | ||
}) => { | ||
const publicKeyInput = page.locator("#muxed-public-key"); | ||
|
||
// Type in an invalid string in 'Public Key' input field | ||
await publicKeyInput.fill("XLKDSFJLSKDJF"); | ||
|
||
await expect(publicKeyInput).toHaveAttribute("aria-invalid", "true"); | ||
await expect( | ||
page.getByText("Base account address should start with G"), | ||
).toBeVisible(); | ||
}); | ||
|
||
test("Gets an error with a non whole number 'Muxed Account ID' field", async ({ | ||
page, | ||
}) => { | ||
const muxedAccountIdInput = page.locator("#muxed-account-id"); | ||
|
||
await muxedAccountIdInput.fill("XLKDSFJLSKDJF"); | ||
|
||
await expect(muxedAccountIdInput).toHaveAttribute("aria-invalid", "true"); | ||
await expect(page.getByText("Expected a whole number")).toBeVisible(); | ||
}); | ||
|
||
test("Successfully creates a muxed account", async ({ page }) => { | ||
const publicKey = | ||
"GDVOT2ALMUF3G54RBHNJUEV6LOAZCQQCARHEVNUPKGMVPWFC4PFN33QR"; | ||
const muxedId = "2"; | ||
const publicKeyInput = page.locator("#muxed-public-key"); | ||
await publicKeyInput.fill(publicKey); | ||
|
||
const muxedAccountIdInput = page.locator("#muxed-account-id"); | ||
await muxedAccountIdInput.fill(muxedId); | ||
|
||
const createButton = page.getByRole("button").getByText("Create"); | ||
|
||
await expect(publicKeyInput).toHaveAttribute("aria-invalid", "false"); | ||
await expect(muxedAccountIdInput).toHaveAttribute("aria-invalid", "false"); | ||
await expect(createButton).toBeEnabled(); | ||
|
||
await createButton.click(); | ||
|
||
await expect(page.getByTestId("createAccount-success")).toBeVisible(); | ||
jeesunikim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const muxedValue = page.locator("input[id='muxed-account-address-result']"); | ||
|
||
const muxedAccount = new MuxedAccount(new Account(publicKey, "0"), muxedId); | ||
|
||
await expect(muxedValue).toHaveValue(muxedAccount.accountId()); | ||
jeesunikim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tried out with adding a middleware.ts to reroute to
404
ifnextUrl
includesmainnet
in params. However, it doesn't always work in all cases. ex. user directly types in/account/fund
in a browser which doesn't populate params until after user lands on the page.another method i tried is
router.push
on the client side but that produced a glitch which wasn't a good ux.so I came up with this. I'll
@
at charles about it after hearing your thoughts!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we shouldn't do anything tricky with the router. This approach is perfectly fine with me, we just need to update the copy to display the correct message. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the copy in the next pr when I make the overall changes following the updates