1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00
metamask-extension/ui/hooks/experiences/useRamps.test.js
Pedro Pablo Aste Kompen 37af04374a
feature(on-ramp): update supported networks (#19268)
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
2023-06-02 08:19:03 -04:00

65 lines
1.6 KiB
JavaScript

import { renderHook } from '@testing-library/react-hooks';
import { useSelector } from 'react-redux';
import useRamps from './useRamps';
jest.mock('react-redux');
jest.mock('./../../selectors', () => ({
getCurrentChainId: jest.fn(),
}));
jest.mock('../../../shared/constants/network', () => ({
CHAIN_IDS: {
GOERLI: '5',
SEPOLIA: '10',
MAINNET: '1',
},
}));
describe('useRamps', () => {
beforeAll(() => {
jest.clearAllMocks();
Object.defineProperty(global, 'platform', {
value: {
openTab: jest.fn(),
},
});
});
it('should open the buy crypto URL for SEPOLIA chain ID', () => {
const mockChainId = '10';
const mockBuyURI = 'https://faucet.sepolia.dev/';
useSelector.mockReturnValue(mockChainId);
const openTabSpy = jest.spyOn(global.platform, 'openTab');
const { result } = renderHook(() => useRamps());
expect(typeof result.current.openBuyCryptoInPdapp).toBe('function');
result.current.openBuyCryptoInPdapp();
expect(openTabSpy).toHaveBeenCalledWith({
url: mockBuyURI,
});
});
it('should open the buy crypto URL for MAINNET chain ID', () => {
const mockChainId = '1';
const mockBuyURI = `${process.env.PORTFOLIO_URL}/buy?metamaskEntry=ext_buy_button&metametricsId=1`;
useSelector.mockReturnValue(mockChainId);
const openTabSpy = jest.spyOn(global.platform, 'openTab');
const { result } = renderHook(() => useRamps());
expect(typeof result.current.openBuyCryptoInPdapp).toBe('function');
result.current.openBuyCryptoInPdapp();
expect(openTabSpy).toHaveBeenCalledWith({
url: mockBuyURI,
});
});
});