Skip to content

Commit

Permalink
updates tests and tweaks asset detail from master merge
Browse files Browse the repository at this point in the history
  • Loading branch information
aristidesstaffieri committed Jan 10, 2024
1 parent 4a7b525 commit da3ac81
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions extension/src/popup/components/account/AssetDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BigNumber } from "bignumber.js";
import { useTranslation } from "react-i18next";
import { IconButton, Icon, Notification } from "@stellar/design-system";

import { HorizonOperation, AssetType } from "@shared/api/types";
import { HorizonOperation, AssetType, TokenBalance } from "@shared/api/types";
import { NetworkDetails } from "@shared/constants/stellar";
import {
getAvailableBalance,
Expand Down Expand Up @@ -174,7 +174,7 @@ export const AssetDetail = ({
assetDomain={assetDomain}
contractId={
balance && "decimals" in balance
? balance.token.issuer.key
? (balance as TokenBalance).token.issuer.key
: undefined
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export const HistoryItem = ({

try {
const response = await fetch(
`${INDEXER_URL}/token-details/${attrs.contractId}?pub_key=${publicKey}&horizon_url=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`,
`${INDEXER_URL}/token-details/${attrs.contractId}?pub_key=${publicKey}&network=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`,
);

if (!response.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export const Operations = ({
if (!contractId) return;
const fetchContractDecimals = async () => {
const response = await fetch(
`${INDEXER_URL}/token-details/${contractId}?pub_key=${publicKey}&horizon_url=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`,
`${INDEXER_URL}/token-details/${contractId}?pub_key=${publicKey}&network=${networkDetails.network}&soroban_url=${networkDetails.sorobanRpcUrl}`,
);
if (!response.ok) {
throw new Error("failed to fetch token details");
Expand Down
29 changes: 18 additions & 11 deletions extension/src/popup/views/__tests__/ManageAssets.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ const manageAssetsMockBalances = {
} as any) as Balances,
isFunded: true,
subentryCount: 1,
tokensWithNoBalance: [],
};

jest
.spyOn(ApiInternal, "getAccountBalances")
.spyOn(ApiInternal, "getAccountIndexerBalances")
.mockImplementation(() => Promise.resolve(manageAssetsMockBalances));

jest
Expand Down Expand Up @@ -115,16 +116,6 @@ jest.spyOn(ApiInternal, "signFreighterTransaction").mockImplementation(() =>
}),
);

jest
.spyOn(ApiInternal, "submitFreighterTransaction")
.mockImplementation(({ networkDetails }) => {
if (networkDetails.networkName === "Test Net Reject") {
return Promise.reject(Error("Request failed"));
}

return Promise.resolve({});
});

jest.spyOn(UseNetworkFees, "useNetworkFees").mockImplementation(() => ({
recommendedFee: "0.00001",
networkCongestion: UseNetworkFees.NetworkCongestion.MEDIUM,
Expand Down Expand Up @@ -239,6 +230,15 @@ describe("Manage assets", () => {
jest.clearAllMocks();
});

beforeEach(() => {
jest.spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve({
ok: true,
json: async () => ({}),
} as any),
);
});

it("renders manage assets view initial state", async () => {
await initView();

Expand Down Expand Up @@ -338,6 +338,13 @@ describe("Manage assets", () => {
});

it("show error view when removing asset with balance", async () => {
jest.spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve({
ok: false,
json: async () => ({}),
} as any),
);

await initView(true);

expect(screen.getByTestId("AppHeaderPageTitle")).toHaveTextContent(
Expand Down
15 changes: 10 additions & 5 deletions extension/src/popup/views/__tests__/Swap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export const swapMockBalances = {
} as any) as Balances,
isFunded: true,
subentryCount: 1,
tokensWithNoBalance: [],
};

jest
.spyOn(ApiInternal, "getAccountBalances")
.spyOn(ApiInternal, "getAccountIndexerBalances")
.mockImplementation(() => Promise.resolve(swapMockBalances));

jest.spyOn(ApiInternal, "signFreighterTransaction").mockImplementation(() =>
Expand All @@ -66,10 +67,6 @@ jest.spyOn(ApiInternal, "signFreighterTransaction").mockImplementation(() =>
}),
);

jest
.spyOn(ApiInternal, "submitFreighterTransaction")
.mockImplementation(() => Promise.resolve({}));

jest.spyOn(UseNetworkFees, "useNetworkFees").mockImplementation(() => ({
recommendedFee: "0.00001",
networkCongestion: UseNetworkFees.NetworkCongestion.MEDIUM,
Expand Down Expand Up @@ -133,6 +130,14 @@ jest.mock("stellar-sdk", () => {
const publicKey = "GCXRLIZUQNZ3YYJDGX6Z445P7FG5WXT7UILBO5CFIYYM7Z7YTIOELC6O";

describe("Swap", () => {
beforeEach(() => {
jest.spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve({
ok: true,
json: async () => ({}),
} as any),
);
});
beforeEach(async () => {
const history = createMemoryHistory();
history.push(ROUTES.swap);
Expand Down

0 comments on commit da3ac81

Please sign in to comment.