Skip to content

Commit 6ac4967

Browse files
test(perps): fix usePerpsBalanceTokenFilter tests for navigation and approval mocks
1 parent 276592f commit 6ac4967

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

app/components/UI/Perps/hooks/usePerpsBalanceTokenFilter.test.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import {
1010
isHighlightedItemOutsideAssetList,
1111
} from '../../../Views/confirmations/types/token';
1212
import { usePerpsTrading } from './usePerpsTrading';
13-
import { useConfirmNavigation } from '../../../Views/confirmations/hooks/useConfirmNavigation';
1413
import { usePerpsPaymentToken } from './usePerpsPaymentToken';
14+
import Routes from '../../../../constants/navigation/Routes';
15+
import { useNavigation } from '@react-navigation/native';
16+
import useApprovalRequest from '../../../Views/confirmations/hooks/useApprovalRequest';
1517

1618
jest.mock('../../../../../locales/i18n', () => ({
1719
strings: jest.fn((key: string) => key),
@@ -22,8 +24,12 @@ jest.mock(
2224
);
2325
jest.mock('./useIsPerpsBalanceSelected');
2426
jest.mock('./usePerpsTrading');
25-
jest.mock('../../../Views/confirmations/hooks/useConfirmNavigation', () => ({
26-
useConfirmNavigation: jest.fn(),
27+
jest.mock('../../../Views/confirmations/hooks/useApprovalRequest', () => ({
28+
__esModule: true,
29+
default: jest.fn(),
30+
}));
31+
jest.mock('@react-navigation/native', () => ({
32+
useNavigation: jest.fn(),
2733
}));
2834
jest.mock('./usePerpsPaymentToken');
2935
jest.mock('react-redux', () => ({
@@ -53,17 +59,21 @@ const mockUseSelector = useSelector as jest.MockedFunction<typeof useSelector>;
5359
const mockUsePerpsTrading = usePerpsTrading as jest.MockedFunction<
5460
typeof usePerpsTrading
5561
>;
56-
const mockUseConfirmNavigation = useConfirmNavigation as jest.MockedFunction<
57-
typeof useConfirmNavigation
58-
>;
5962
const mockUsePerpsPaymentToken = usePerpsPaymentToken as jest.MockedFunction<
6063
typeof usePerpsPaymentToken
6164
>;
65+
const mockUseNavigation = useNavigation as jest.MockedFunction<
66+
typeof useNavigation
67+
>;
68+
const mockUseApprovalRequest = useApprovalRequest as jest.MockedFunction<
69+
typeof useApprovalRequest
70+
>;
6271

6372
describe('usePerpsBalanceTokenFilter', () => {
6473
const chainId = '0xa4b1';
6574
const mockDepositWithConfirmation = jest.fn().mockResolvedValue(undefined);
66-
const mockNavigateToConfirmation = jest.fn();
75+
const mockNavigate = jest.fn();
76+
const mockOnReject = jest.fn();
6777
const mockOnPerpsPaymentTokenChange = jest.fn();
6878

6979
beforeEach(() => {
@@ -82,9 +92,12 @@ describe('usePerpsBalanceTokenFilter', () => {
8292
mockUsePerpsTrading.mockReturnValue({
8393
depositWithConfirmation: mockDepositWithConfirmation,
8494
} as unknown as ReturnType<typeof usePerpsTrading>);
85-
mockUseConfirmNavigation.mockReturnValue({
86-
navigateToConfirmation: mockNavigateToConfirmation,
87-
} as unknown as ReturnType<typeof useConfirmNavigation>);
95+
mockUseNavigation.mockReturnValue({
96+
navigate: mockNavigate,
97+
} as unknown as ReturnType<typeof useNavigation>);
98+
mockUseApprovalRequest.mockReturnValue({
99+
onReject: mockOnReject,
100+
} as unknown as ReturnType<typeof useApprovalRequest>);
88101
mockUsePerpsPaymentToken.mockReturnValue({
89102
onPaymentTokenChange: mockOnPerpsPaymentTokenChange,
90103
} as unknown as ReturnType<typeof usePerpsPaymentToken>);
@@ -300,7 +313,7 @@ describe('usePerpsBalanceTokenFilter', () => {
300313
expect((output[1] as AssetType).symbol).toBe('USDC');
301314
});
302315

303-
it('calls navigateToConfirmation and depositWithConfirmation when Add funds is pressed', () => {
316+
it('calls onReject, depositWithConfirmation and navigation.navigate when Add funds is pressed', async () => {
304317
mockUseSelector.mockReturnValue({
305318
availableBalance: '500.00',
306319
});
@@ -322,10 +335,13 @@ describe('usePerpsBalanceTokenFilter', () => {
322335
expect(isHighlightedItemOutsideAssetList(highlightedAction)).toBe(true);
323336
if (isHighlightedItemOutsideAssetList(highlightedAction)) {
324337
highlightedAction.actions?.[0]?.onPress();
325-
expect(mockNavigateToConfirmation).toHaveBeenCalledWith({
326-
stack: expect.any(String),
327-
});
338+
expect(mockOnReject).toHaveBeenCalledTimes(1);
328339
expect(mockDepositWithConfirmation).toHaveBeenCalledTimes(1);
340+
await Promise.resolve();
341+
expect(mockNavigate).toHaveBeenCalledWith(
342+
Routes.FULL_SCREEN_CONFIRMATIONS.REDESIGNED_CONFIRMATIONS,
343+
{ showPerpsHeader: true },
344+
);
329345
}
330346
});
331347

0 commit comments

Comments
 (0)