mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 15:50:28 +01:00
5998ae21aa
* feat: disable deposit popover and replace it with global redirect to onramp on pdapp * feat: remove legacy code for hardcoded onramp providers * fix: remove unused visuals and components related to legacy code of deposit popover * fix: remove unused messages * feat: use a custom hook for all onramps related methods and variables * fix: modify the custom hook implementation to include test networks * fix: remove deprecated file buy-url * fix: remove references for deleted deposit logos * fix: network-controller failing unit test * fix: snapshot loading-swaps-quotes-stories-metadata.test.js.snap * fix: storybook tests * fix: remove unused constatns related to buyable onramp chains * fix: remove unused variables and fix eslint * adding unit test for useRamps custom hook * feat: add comment on the proper usage of useRamps within confirm-page-container component * fix: add unit tests for buy button in token-overview page * fix: add unit test for open the buy crypto URL for a buyable chain ID in token page * feat: add unit test coverage for eth-overview page * fix: update locales
83 lines
2.1 KiB
JavaScript
83 lines
2.1 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 GOERLI chain ID', () => {
|
|
const mockChainId = '5';
|
|
const mockBuyURI = 'https://goerli-faucet.slock.it/';
|
|
|
|
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 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`;
|
|
|
|
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,
|
|
});
|
|
});
|
|
});
|