mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 19:10:22 +01:00
37af04374a
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
65 lines
1.6 KiB
JavaScript
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,
|
|
});
|
|
});
|
|
});
|