Skip to content
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

Saved Requests UI Tests #1183

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/app/(sidebar)/endpoints/components/SavedEndpointsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const SavedEndpointsPage = () => {

const HorizonEndpoints = () => {
if (savedEndpointsHorizon.length === 0) {
return "There are no saved Horizon Endpoints";
return `There are no saved Horizon Endpoints on ${network.label} network`;
}

return (
Expand All @@ -163,9 +163,11 @@ export const SavedEndpointsPage = () => {
gap="sm"
key={`horizon-${e.timestamp}`}
addlClassName="PageBody__content"
data-testid="saved-requests-horizon-item"
>
<Input
id={`saved-horizon-${e.timestamp}`}
data-testid="saved-horizon-name"
fieldSize="md"
value={e.name}
readOnly
Expand All @@ -178,13 +180,15 @@ export const SavedEndpointsPage = () => {
setCurrentRequestTimestamp(e.timestamp);
}}
icon={<Icon.Edit05 />}
data-testid="saved-horizon-edit"
/>
}
/>

<div className="Endpoints__urlBar">
<Input
id={`endpoint-url-${e.timestamp}`}
data-testid="saved-horizon-url"
fieldSize="md"
value={e.url}
readOnly
Expand Down Expand Up @@ -255,16 +259,17 @@ export const SavedEndpointsPage = () => {

const RpcEndpoints = () => {
if (savedRpcMethods.length === 0) {
return "There are no saved RPC Methods";
return `There are no saved RPC Methods ${network.label} network`;
}

return (
<Box gap="md">
{savedRpcMethods.map((e, idx) => (
<Box
gap="sm"
key={`horizon-${e.timestamp}`}
key={`rpc-${e.timestamp}`}
addlClassName="PageBody__content"
data-testid="saved-requests-rpc-item"
>
<Box gap="sm" direction="row">
<Badge size="md" variant="secondary">
Expand All @@ -274,6 +279,7 @@ export const SavedEndpointsPage = () => {

<Input
id={`saved-rpc-${e.timestamp}`}
data-testid="saved-rpc-name"
fieldSize="md"
value={e.name}
readOnly
Expand All @@ -286,13 +292,15 @@ export const SavedEndpointsPage = () => {
setCurrentRequestTimestamp(e.timestamp);
}}
icon={<Icon.Edit05 />}
data-testid="saved-rpc-edit"
/>
}
/>

<div className="Endpoints__urlBar">
<Input
id={`endpoint-url-${e.timestamp}`}
data-testid="saved-rpc-url"
fieldSize="md"
value={e.url}
readOnly
Expand Down Expand Up @@ -375,7 +383,10 @@ export const SavedEndpointsPage = () => {
</Box>
{expandedPayloadIndex[idx] ? (
<>
<div className="Endpoints__txTextarea">
<div
className="Endpoints__txTextarea"
data-testid="saved-rpc-payload"
>
<PrettyJsonTextarea json={e.payload} label="Payload" />
</div>
<Box gap="md" direction="row" justify="end">
Expand All @@ -394,7 +405,7 @@ export const SavedEndpointsPage = () => {
};

return (
<Box gap="md">
<Box gap="md" data-testid="saved-requests-container">
<PageCard>
<TabView
heading={{ title: "Saved Requests" }}
Expand Down
86 changes: 86 additions & 0 deletions tests/mock/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,84 @@ const SAVED_ACCOUNTS = [
},
];

const SAVED_HORIZON_ENDPOINTS = [
{
timestamp: 1733173821853,
network: { id: "testnet", label: "Testnet" },
name: "Transactions",
url: "https://horizon-testnet.stellar.org/transactions?limit=5&order=desc",
method: "GET",
route: "/endpoints/transactions",
params: { order: "desc", limit: "5" },
shareableUrl:
"https://lab.stellar.org/endpoints/transactions?$=network$id=testnet&label=Testnet&horizonUrl=https:////horizon-testnet.stellar.org&rpcUrl=https:////soroban-testnet.stellar.org&passphrase=Test%20SDF%20Network%20/;%20September%202015;&endpoints$params$order=desc&limit=5;;",
},
{
timestamp: 1733233624053,
network: { id: "testnet", label: "Testnet" },
name: "Account",
url: "https://horizon-testnet.stellar.org/accounts/GA46LGGOLXJY5OSX6N4LHV4MWDFXNGLK76I4NDNKKYAXRRSKI5AJGMXG",
method: "GET",
route: "/endpoints/accounts/single",
params: {
account_id: "GA46LGGOLXJY5OSX6N4LHV4MWDFXNGLK76I4NDNKKYAXRRSKI5AJGMXG",
},
shareableUrl:
"https://lab.stellar.org/endpoints/accounts/single?$=network$id=testnet&label=Testnet&horizonUrl=https:////horizon-testnet.stellar.org&rpcUrl=https:////soroban-testnet.stellar.org&passphrase=Test%20SDF%20Network%20/;%20September%202015;&endpoints$params$account_id=GA46LGGOLXJY5OSX6N4LHV4MWDFXNGLK76I4NDNKKYAXRRSKI5AJGMXG;;",
},
];

const SAVED_RPC_ENDPOINTS = [
{
timestamp: 1733173721157,
network: { id: "testnet", label: "Testnet" },
name: "Transactions",
url: "https://soroban-testnet.stellar.org",
method: "POST",
route: "/endpoints/rpc/get-transactions",
params: { startLedger: "1268840", limit: "5" },
shareableUrl:
"https://lab.stellar.org/endpoints/rpc/get-transactions?$=network$id=testnet&label=Testnet&horizonUrl=https:////horizon-testnet.stellar.org&rpcUrl=https:////soroban-testnet.stellar.org&passphrase=Test%20SDF%20Network%20/;%20September%202015;&endpoints$params$startLedger=1268840&limit=5;;",
payload: {
jsonrpc: "2.0",
id: 8675309,
method: "getTransactions",
params: {
startLedger: 1268840,
pagination: { limit: 5 },
xdrFormat: "base64",
},
},
rpcMethod: "getTransactions",
},
{
timestamp: 1733233741685,
network: { id: "testnet", label: "Testnet" },
name: "Simulate",
url: "https://soroban-testnet.stellar.org",
method: "POST",
route: "/endpoints/rpc/simulate-transaction",
params: {
tx: "AAAAAgAAAAAYheerp3FCahtW+3qusxzklJhfxMPQJERfPKY0lXnVjQAPQkAADQg/AAAAJAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAABB90WssODNIgi6BHveqzxTRmIpvAFRyVNM+Hm2GVuCcAAAAAAAAAADGfZUR9pNoQGv+u6uGjdcwVF3zlb/mjyN53fUCn+iBGQAAABdIdugAAAAAAAAAAAKVedWNAAAAQA8JEfXRL2BLjcYHYX+6Dloij4OIR44zsu6hd9CSI/rQSgGulcIFmzY0sX4LIxdwCg/3UMOfXFEpGxIsDvaJEQuGVuCcAAAAQBYyy1VZl3iPQBI4hyv4e91Xv9KfM54jWWLVoh2HEjTWzPUsTlo6e2u/zGi+dcZxbNy/1MV9ipZuflVzLHPKlgs=",
resourceConfig: "1714814",
},
shareableUrl:
"https://lab.stellar.org/endpoints/rpc/simulate-transaction?$=network$id=testnet&label=Testnet&horizonUrl=https:////horizon-testnet.stellar.org&rpcUrl=https:////soroban-testnet.stellar.org&passphrase=Test%20SDF%20Network%20/;%20September%202015;&endpoints$params$tx=AAAAAgAAAAAYheerp3FCahtW+3qusxzklJhfxMPQJERfPKY0lXnVjQAPQkAADQg//AAAAJAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAABB90WssODNIgi6BHveqzxTRmIpvAFRyVNM+Hm2GVuCcAAAAAAAAAADGfZUR9pNoQGv+u6uGjdcwVF3zlb//mjyN53fUCn+iBGQAAABdIdugAAAAAAAAAAAKVedWNAAAAQA8JEfXRL2BLjcYHYX+6Dloij4OIR44zsu6hd9CSI//rQSgGulcIFmzY0sX4LIxdwCg//3UMOfXFEpGxIsDvaJEQuGVuCcAAAAQBYyy1VZl3iPQBI4hyv4e91Xv9KfM54jWWLVoh2HEjTWzPUsTlo6e2u//zGi+dcZxbNy//1MV9ipZuflVzLHPKlgs=&resourceConfig=1714814;&saved$activeTab=rpc;;",
payload: {
jsonrpc: "2.0",
id: 8675309,
method: "simulateTransaction",
params: {
transaction:
"AAAAAgAAAAAYheerp3FCahtW+3qusxzklJhfxMPQJERfPKY0lXnVjQAPQkAADQg/AAAAJAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAABB90WssODNIgi6BHveqzxTRmIpvAFRyVNM+Hm2GVuCcAAAAAAAAAADGfZUR9pNoQGv+u6uGjdcwVF3zlb/mjyN53fUCn+iBGQAAABdIdugAAAAAAAAAAAKVedWNAAAAQA8JEfXRL2BLjcYHYX+6Dloij4OIR44zsu6hd9CSI/rQSgGulcIFmzY0sX4LIxdwCg/3UMOfXFEpGxIsDvaJEQuGVuCcAAAAQBYyy1VZl3iPQBI4hyv4e91Xv9KfM54jWWLVoh2HEjTWzPUsTlo6e2u/zGi+dcZxbNy/1MV9ipZuflVzLHPKlgs=",
resourceConfig: { instructionLeeway: 1714814 },
xdrFormat: "base64",
},
},
rpcMethod: "simulateTransaction",
},
];

export const MOCK_LOCAL_STORAGE = {
cookies: [],
origins: [
Expand All @@ -40,6 +118,14 @@ export const MOCK_LOCAL_STORAGE = {
name: "stellar_lab_saved_keypairs",
value: JSON.stringify(SAVED_ACCOUNTS),
},
{
name: "stellar_lab_saved_horizon_endpoints",
value: JSON.stringify(SAVED_HORIZON_ENDPOINTS),
},
{
name: "stellar_lab_saved_rpc_endpoints",
value: JSON.stringify(SAVED_RPC_ENDPOINTS),
},
],
},
],
Expand Down
59 changes: 0 additions & 59 deletions tests/savedKeypairs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ test.describe("Saved Keypairs Page", () => {
});
},
);

// Account 2 Friendbot response
await pageContext.route(
`https://friendbot.stellar.org/?addr=${SAVED_ACCOUNT_2}`,
async (route) => {
await route.fulfill({
status: 200,
contentType: "application/hal+json; charset=utf-8",
});
},
);
});

test("Loads", async () => {
Expand Down Expand Up @@ -105,54 +94,6 @@ test.describe("Saved Keypairs Page", () => {
).toBeVisible();
});

test("Fund unfunded account", async () => {
const keypairItem = pageContext.getByTestId("saved-keypair-item").nth(1);

await expect(keypairItem).toBeVisible();
await expect(keypairItem.getByTestId("saved-keypair-name")).toHaveValue(
"Account 2",
);

const fundButton = pageContext.getByText("Fund with Friendbot");

await expect(fundButton).toBeVisible();

// Wait for the Friendbot response
const friendbotResponse = pageContext.waitForResponse(
(response) =>
response.url().includes(`?addr=${SAVED_ACCOUNT_2}`) &&
response.status() === 200,
);

await fundButton.click();
await friendbotResponse;

// Mock Account 2 response
await pageContext.route(
`*/**/accounts/${SAVED_ACCOUNT_2}`,
async (route) => {
await route.fulfill({
status: 200,
contentType: "application/hal+json; charset=utf-8",
body: JSON.stringify(MOCK_ACCOUNT_1_RESPONSE),
});
},
);

const accountResponse = pageContext.waitForResponse(
(response) =>
response.url().includes(`accounts/${SAVED_ACCOUNT_2}`) &&
response.status() === 200,
);

await accountResponse;

await expect(fundButton).toBeHidden();
await expect(
keypairItem.getByText("Balance: 10000.0000000 XLM", { exact: true }),
).toBeVisible();
});

test("Delete keypair", async () => {
const keypairItem = pageContext.getByTestId("saved-keypair-item").first();
const deleteButton = keypairItem.locator(".Button--error");
Expand Down
Loading
Loading