mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
c52d2131d3
* Added confirm add institutional feature page * Finished implementing component * Added all institutional ducks * Fixed tests * Removed ducks and console log * Fixed snapshots * Fixed messages json * Changed method name and using useEffect * Replace useEffect hook with a simple if statement to check if connectRequest exists and add null return statement to avoid warnings * Remove unneeded dependency * Added back useEffect and added a extra check to return null if connectRequest is false * Fixed eslint problem * Fixed all issues commented in the pr
123 lines
3.3 KiB
JavaScript
123 lines
3.3 KiB
JavaScript
import React from 'react';
|
|
import { fireEvent, screen } from '@testing-library/react';
|
|
import configureMockStore from 'redux-mock-store';
|
|
import thunk from 'redux-thunk';
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
import ConfirmAddInstitutionalFeature from '.';
|
|
|
|
const mockRemoveConnectInstitutionalFeature = jest
|
|
.fn()
|
|
.mockReturnValue({ type: 'TYPE' });
|
|
|
|
let mockSetComplianceAuthData = jest.fn().mockReturnValue({ type: 'TYPE' });
|
|
|
|
jest.mock('../../../store/institutional/institution-background', () => ({
|
|
mmiActionsFactory: () => ({
|
|
setComplianceAuthData: mockSetComplianceAuthData,
|
|
removeConnectInstitutionalFeature: mockRemoveConnectInstitutionalFeature,
|
|
}),
|
|
}));
|
|
|
|
const connectRequests = [
|
|
{
|
|
labels: [
|
|
{
|
|
key: 'service',
|
|
value: 'test',
|
|
},
|
|
],
|
|
origin: 'origin',
|
|
token: {
|
|
projectName: 'projectName',
|
|
projectId: 'projectId',
|
|
clientId: 'clientId',
|
|
},
|
|
},
|
|
];
|
|
|
|
const props = {
|
|
history: {
|
|
push: jest.fn(),
|
|
},
|
|
};
|
|
|
|
const render = ({ newState } = {}) => {
|
|
const state = {
|
|
...mockState,
|
|
metamask: {
|
|
provider: {
|
|
type: 'test',
|
|
},
|
|
institutionalFeatures: {
|
|
complianceProjectId: '',
|
|
connectRequests,
|
|
},
|
|
preferences: {
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
},
|
|
...newState,
|
|
},
|
|
};
|
|
const middlewares = [thunk];
|
|
const mockStore = configureMockStore(middlewares);
|
|
const store = mockStore(state);
|
|
|
|
return renderWithProvider(
|
|
<ConfirmAddInstitutionalFeature {...props} />,
|
|
store,
|
|
);
|
|
};
|
|
|
|
describe('Confirm Add Institutional Feature', function () {
|
|
it('opens confirm institutional sucessfully', () => {
|
|
const { container } = render();
|
|
expect(container).toMatchSnapshot();
|
|
expect(
|
|
screen.getByText(`Id: ${connectRequests[0].token.projectId}`),
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it('runs removeConnectInstitutionalFeature on cancel click', () => {
|
|
render();
|
|
fireEvent.click(screen.queryByText('Cancel'));
|
|
expect(mockRemoveConnectInstitutionalFeature).toHaveBeenCalledTimes(1);
|
|
expect(mockRemoveConnectInstitutionalFeature).toHaveBeenCalledWith({
|
|
origin: connectRequests[0].origin,
|
|
projectId: connectRequests[0].token.projectId,
|
|
});
|
|
expect(props.history.push).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('runs setComplianceAuthData on confirm click', () => {
|
|
render();
|
|
fireEvent.click(screen.queryByText('Confirm'));
|
|
expect(mockSetComplianceAuthData).toHaveBeenCalledTimes(1);
|
|
expect(mockSetComplianceAuthData).toHaveBeenCalledWith({
|
|
clientId: connectRequests[0].token.clientId,
|
|
projectId: connectRequests[0].token.projectId,
|
|
});
|
|
});
|
|
|
|
it('handles error', () => {
|
|
mockSetComplianceAuthData = jest
|
|
.fn()
|
|
.mockReturnValue(new Error('Async error message'));
|
|
const { queryByTestId } = render();
|
|
fireEvent.click(screen.queryByText('Confirm'));
|
|
expect(queryByTestId('connect-error-message')).toBeInTheDocument();
|
|
});
|
|
|
|
it('does not render without connectRequest', () => {
|
|
const newState = {
|
|
institutionalFeatures: {
|
|
connectRequests: [],
|
|
},
|
|
};
|
|
const { queryByTestId } = render({ newState });
|
|
expect(
|
|
queryByTestId('confirm-add-institutional-feature'),
|
|
).not.toBeInTheDocument();
|
|
});
|
|
});
|