2023-03-23 11:08:33 +01:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { fireEvent, screen } from '@testing-library/react';
|
|
|
|
import { detectNewTokens } from '../../../store/actions';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2023-06-28 15:37:03 +02:00
|
|
|
import { ImportTokenLink } from '.';
|
2023-03-23 11:08:33 +01:00
|
|
|
|
|
|
|
const mockPushHistory = jest.fn();
|
|
|
|
|
|
|
|
jest.mock('react-router-dom', () => {
|
|
|
|
const original = jest.requireActual('react-router-dom');
|
|
|
|
return {
|
|
|
|
...original,
|
|
|
|
useLocation: jest.fn(() => ({ search: '' })),
|
|
|
|
useHistory: () => ({
|
|
|
|
push: mockPushHistory,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions.ts', () => ({
|
2023-08-14 18:08:59 +02:00
|
|
|
detectNewTokens: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => ({ type: 'DETECT_TOKENS' })),
|
|
|
|
showImportTokensModal: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => ({ type: 'UI_IMPORT_TOKENS_POPOVER_OPEN' })),
|
2023-03-23 11:08:33 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('Import Token Link', () => {
|
|
|
|
it('should match snapshot for goerli chainId', () => {
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-23 11:08:33 +01:00
|
|
|
chainId: '0x5',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
const { container } = renderWithProvider(<ImportTokenLink />, store);
|
2023-03-23 11:08:33 +01:00
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should match snapshot for mainnet chainId', () => {
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-23 11:08:33 +01:00
|
|
|
chainId: '0x1',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
const { container } = renderWithProvider(<ImportTokenLink />, store);
|
2023-03-23 11:08:33 +01:00
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detectNewTokens when clicking refresh', () => {
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-23 11:08:33 +01:00
|
|
|
chainId: '0x5',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
renderWithProvider(<ImportTokenLink />, store);
|
2023-03-23 11:08:33 +01:00
|
|
|
|
|
|
|
const refreshList = screen.getByTestId('refresh-list-button');
|
|
|
|
fireEvent.click(refreshList);
|
|
|
|
|
|
|
|
expect(detectNewTokens).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should push import token route', () => {
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-23 11:08:33 +01:00
|
|
|
chainId: '0x5',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore()(mockState);
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
renderWithProvider(<ImportTokenLink />, store);
|
2023-03-23 11:08:33 +01:00
|
|
|
|
|
|
|
const importToken = screen.getByTestId('import-token-button');
|
|
|
|
fireEvent.click(importToken);
|
|
|
|
|
2023-08-14 18:08:59 +02:00
|
|
|
expect(screen.getByText('Import tokens')).toBeInTheDocument();
|
2023-03-23 11:08:33 +01:00
|
|
|
});
|
|
|
|
});
|