Skip to content

Commit

Permalink
Saved Requests UI Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quietbits committed Dec 3, 2024
1 parent 4c3ca39 commit 4187e2b
Show file tree
Hide file tree
Showing 3 changed files with 367 additions and 5 deletions.
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
132 changes: 132 additions & 0 deletions tests/mock/localStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
export const SAVED_ACCOUNT_1 =
"GA46LGGOLXJY5OSX6N4LHV4MWDFXNGLK76I4NDNKKYAXRRSKI5AJGMXG";
export const SAVED_ACCOUNT_1_SECRET =
"SADVGAH3VA3NGZ5VLX2ZICV7JQAINB2ZJZYOPMBXUNI3YRLGWLOA2OFY";
export const SAVED_ACCOUNT_2 =
"GD4F2N2OM2IM4MI6F6J5GVENQLNRVCYEE6XFN36MJOU5MOVFUYYSPBYG";
export const SAVED_ACCOUNT_2_SECRET =
"SDVMTXXSUJG6GKFCETCKFV6FCGE7C5FYKBCV4AMD4N3SRYCDSA53KEG4";

const SAVED_ACCOUNTS = [
{
timestamp: 1732287853955,
network: {
id: "testnet",
label: "Testnet",
},
name: "Account 1",
publicKey: SAVED_ACCOUNT_1,
secretKey: SAVED_ACCOUNT_1_SECRET,
},
{
timestamp: 1731083842367,
network: {
id: "testnet",
label: "Testnet",
},
name: "Account 2",
publicKey: SAVED_ACCOUNT_2,
secretKey: SAVED_ACCOUNT_2_SECRET,
},
];

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: [
{
origin: "http://localhost:3000",
localStorage: [
{
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),
},
],
},
],
};
Loading

0 comments on commit 4187e2b

Please sign in to comment.