Skip to content
Open
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
5 changes: 4 additions & 1 deletion __tests__/components/screens/HomeScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ jest.mock("ducks/balances", () => ({

jest.mock("ducks/prices", () => ({
usePricesStore: jest.fn(() => ({
prices: {},
pricesByNetwork: {},
sourceByNetwork: {},
isLoading: false,
error: null,
lastUpdated: null,
fetchPricesForBalances: jest.fn(),
})),
usePricesForNetwork: jest.fn(() => ({})),
}));

jest.mock("ducks/collectibles", () => ({
Expand Down Expand Up @@ -230,6 +232,7 @@ jest.mock("hooks/useTotalBalance", () => ({
useTotalBalance: jest.fn(() => ({
formattedBalance: "$350.75",
totalBalance: "350.75",
hasFiatTotal: true,
})),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BigNumber from "bignumber.js";
import SwapAmountScreen from "components/screens/SwapScreen/screens/SwapAmountScreen";
import Icon from "components/sds/Icon";
import { AnalyticsEvent } from "config/analyticsConfig";
import { NETWORKS } from "config/constants";
import { SWAP_ROUTES, SwapStackParamList } from "config/routes";
import { useSwapStore } from "ducks/swap";
import { renderWithProviders } from "helpers/testUtils";
Expand Down Expand Up @@ -273,11 +274,13 @@ const mockPrices: Record<
jest.mock("ducks/prices", () => ({
usePricesStore: (selector?: (s: unknown) => unknown): unknown => {
const state = {
prices: mockPrices,
pricesByNetwork: {},
sourceByNetwork: {},
fetchPricesForTokenIds: mockFetchPricesForTokenIds,
};
return selector ? selector(state) : state;
},
usePricesForNetwork: () => mockPrices,
}));
// Cache the return value so account / spendableAmount memos stay stable across
// re-renders — otherwise the amountError useEffect can re-fire forever when
Expand Down Expand Up @@ -899,6 +902,8 @@ describe("SwapAmountScreen", () => {
"yXLM:GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
"FTT:GBDQOFC6SKCNBHPLZ7NXQ6MCKFIYUUFVOWYGNWQCXC2F4AYZ27EUWYWH",
],
network: NETWORKS.PUBLIC,
useV2: true,
});
});

Expand Down
6 changes: 4 additions & 2 deletions __tests__/ducks/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,8 @@ describe("auth duck", () => {

// Verify setState was called with correct reset values
expect(usePricesStore.setState).toHaveBeenCalledWith({
prices: {},
pricesByNetwork: {},
sourceByNetwork: {},
isLoading: false,
error: null,
lastUpdated: null,
Expand Down Expand Up @@ -1927,7 +1928,8 @@ describe("auth duck", () => {

const pricesCall = (usePricesStore.setState as jest.Mock).mock
.calls[0]?.[0];
expect(pricesCall?.prices).toEqual({});
expect(pricesCall?.pricesByNetwork).toEqual({});
expect(pricesCall?.sourceByNetwork).toEqual({});
expect(pricesCall?.lastUpdated).toBeNull();
});

Expand Down
34 changes: 23 additions & 11 deletions __tests__/ducks/balances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jest.mock("ducks/prices", () => ({
usePricesStore: {
getState: jest.fn().mockReturnValue({
fetchPricesForBalances: jest.fn(),
prices: {},
pricesByNetwork: {},
sourceByNetwork: {},
error: null,
isLoading: false,
lastUpdated: null,
Expand All @@ -49,7 +50,9 @@ describe("balances duck", () => {
>;
const mockGetItem = jest.fn();

// Helper function to create a mock prices store state
// Helper function to create a mock prices store state. The `prices` override
// is exposed under every network so `pricesByNetwork[params.network]` resolves
// regardless of which network a test uses.
const createMockPricesStore = (
overrides: Partial<{
fetchPricesForBalances: jest.Mock;
Expand All @@ -58,14 +61,22 @@ describe("balances duck", () => {
isLoading: boolean;
lastUpdated: number | null;
}> = {},
) => ({
fetchPricesForBalances: jest.fn().mockResolvedValue(undefined),
prices: {},
error: null,
isLoading: false,
lastUpdated: null,
...overrides,
});
) => {
const { prices = {}, ...rest } = overrides;
return {
fetchPricesForBalances: jest.fn().mockResolvedValue(undefined),
pricesByNetwork: {
[NETWORKS.PUBLIC]: prices,
[NETWORKS.TESTNET]: prices,
[NETWORKS.FUTURENET]: prices,
},
sourceByNetwork: {},
error: null,
isLoading: false,
lastUpdated: null,
...rest,
};
};

// Mock data
const mockNativeBalance: NativeBalance = {
Expand Down Expand Up @@ -286,7 +297,8 @@ describe("balances duck", () => {
mockFetchBalances.mockResolvedValueOnce({ balances: {} });
(usePricesStore.getState as jest.Mock).mockReturnValue({
fetchPricesForBalances: jest.fn().mockResolvedValue(undefined),
prices: {},
pricesByNetwork: {},
sourceByNetwork: {},
error: null,
isLoading: false,
lastUpdated: null,
Expand Down
Loading
Loading