2023-03-31 11:30:10 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { screen, fireEvent } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
|
|
import ConfirmAddCustodianToken from './confirm-add-custodian-token';
|
|
|
|
|
2023-07-13 10:42:08 +02:00
|
|
|
const mockedRemoveAddTokenConnectRequest = jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue({ type: 'TYPE' });
|
|
|
|
|
|
|
|
jest.mock('../../../store/institutional/institution-background', () => ({
|
|
|
|
mmiActionsFactory: () => ({
|
|
|
|
removeAddTokenConnectRequest: mockedRemoveAddTokenConnectRequest,
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
2023-03-31 11:30:10 +02:00
|
|
|
describe('Confirm Add Custodian Token', () => {
|
|
|
|
const mockStore = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-31 11:30:10 +02:00
|
|
|
type: 'test',
|
|
|
|
},
|
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
},
|
|
|
|
institutionalFeatures: {
|
|
|
|
connectRequests: [
|
|
|
|
{
|
|
|
|
labels: [
|
|
|
|
{
|
|
|
|
key: 'service',
|
|
|
|
value: 'test',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
origin: 'origin',
|
|
|
|
token: 'testToken',
|
|
|
|
feature: 'custodian',
|
|
|
|
service: 'Jupiter',
|
|
|
|
apiUrl: 'https://',
|
|
|
|
chainId: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
history: {
|
|
|
|
push: '/',
|
|
|
|
mostRecentOverviewPage: '/',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore()(mockStore);
|
|
|
|
|
|
|
|
it('opens confirm add custodian token with correct token', () => {
|
|
|
|
renderWithProvider(<ConfirmAddCustodianToken />, store);
|
|
|
|
|
|
|
|
const tokenContainer = screen.getByText('...testToken');
|
|
|
|
expect(tokenContainer).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the custodian on cancel click', () => {
|
|
|
|
renderWithProvider(<ConfirmAddCustodianToken />, store);
|
|
|
|
|
|
|
|
const cancelButton = screen.getByTestId('cancel-btn');
|
|
|
|
|
|
|
|
fireEvent.click(cancelButton);
|
|
|
|
|
|
|
|
expect(screen.getByText('Custodian')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tries to connect to custodian with empty token', async () => {
|
|
|
|
const customMockedStore = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-31 11:30:10 +02:00
|
|
|
type: 'test',
|
|
|
|
},
|
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
},
|
|
|
|
institutionalFeatures: {
|
|
|
|
connectRequests: [
|
|
|
|
{
|
|
|
|
labels: [
|
|
|
|
{
|
|
|
|
key: 'service',
|
|
|
|
value: 'test',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
origin: 'origin',
|
|
|
|
token: '',
|
|
|
|
feature: 'custodian',
|
|
|
|
service: 'Jupiter',
|
|
|
|
apiUrl: 'https://',
|
|
|
|
chainId: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
history: {
|
|
|
|
push: '/',
|
|
|
|
mostRecentOverviewPage: '/',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const customStore = configureMockStore()(customMockedStore);
|
|
|
|
|
|
|
|
renderWithProvider(<ConfirmAddCustodianToken />, customStore);
|
|
|
|
|
|
|
|
const confirmButton = screen.getByTestId('confirm-btn');
|
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
|
|
|
|
const errorMessage = screen.getByTestId('connect-custodian-token-error');
|
|
|
|
|
|
|
|
expect(errorMessage).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clicks the confirm button and shows the test value', async () => {
|
|
|
|
renderWithProvider(<ConfirmAddCustodianToken />, store);
|
|
|
|
|
|
|
|
const confirmButton = screen.getByTestId('confirm-btn');
|
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
|
|
|
|
expect(screen.getByText('test')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the error area', () => {
|
|
|
|
renderWithProvider(<ConfirmAddCustodianToken />, store);
|
|
|
|
|
|
|
|
const confirmButton = screen.getByTestId('confirm-btn');
|
|
|
|
|
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
|
|
|
|
expect(screen.getByTestId('error-message')).toBeVisible();
|
|
|
|
});
|
|
|
|
});
|