1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00
metamask-extension/ui/pages/institutional/compliance-feature-page/compliance-feature-page.test.js
Mark Stacey d1cea85f33
Rename provider to providerConfig (#18907)
* Rename `provider` to `providerConfig`

The network controller `provider` state has been renamed to
 `providerConfig`. This better reflects what this state is, and makes
this controller more closely aligned with the core network controller.

All references to the provider configuration have been updated to
prefer `providerConfig` over `provider`, to make the distinction clear
between a provider and provider config.

Closes #18902

* Add migration
2023-05-02 13:23:20 -02:30

108 lines
2.9 KiB
JavaScript

import React from 'react';
import sinon from 'sinon';
import configureMockStore from 'redux-mock-store';
import { fireEvent, waitFor } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import ComplianceFeaturePage from '.';
const mockedDeleteComplianceAuthData = jest
.fn()
.mockReturnValue({ type: 'TYPE' });
jest.mock('../../../store/institutional/institution-background', () => ({
mmiActionsFactory: () => ({
deleteComplianceAuthData: mockedDeleteComplianceAuthData,
}),
}));
describe('Compliance Feature, connect', function () {
const mockStore = {
metamask: {
providerConfig: {
type: 'test',
},
institutionalFeatures: {
complianceProjectId: '',
},
preferences: {
useNativeCurrencyAsPrimaryCurrency: true,
},
},
};
it('shows compliance feature button as activated', () => {
const customMockStore = {
...mockStore,
metamask: {
...mockStore.metamask,
institutionalFeatures: {
complianceProjectId: '123',
complianceClientId: '123',
reportsInProgress: {},
},
},
};
const store = configureMockStore()(customMockStore);
const { getByText, getByTestId } = renderWithProvider(
<ComplianceFeaturePage />,
store,
);
expect(getByTestId('activated-label')).toBeVisible();
expect(getByText('Active')).toBeInTheDocument();
});
it('shows ComplianceSettings when feature is not activated', () => {
const store = configureMockStore()(mockStore);
const { getByTestId } = renderWithProvider(
<ComplianceFeaturePage />,
store,
);
expect(getByTestId('institutional-content')).toBeVisible();
});
it('opens new tab on Open Codefi Compliance click', async () => {
global.platform = { openTab: sinon.spy() };
const store = configureMockStore()(mockStore);
const { queryByTestId } = renderWithProvider(
<ComplianceFeaturePage />,
store,
);
const startBtn = queryByTestId('start-compliance');
fireEvent.click(startBtn);
await waitFor(() => {
expect(global.platform.openTab.calledOnce).toStrictEqual(true);
});
});
it('calls deleteComplianceAuthData on disconnect click', async () => {
const customMockStore = {
...mockStore,
metamask: {
...mockStore.metamask,
institutionalFeatures: {
complianceProjectId: '123',
complianceClientId: '123',
reportsInProgress: {},
},
},
};
const store = configureMockStore()(customMockStore);
const { getByTestId } = renderWithProvider(
<ComplianceFeaturePage />,
store,
);
const disconnectBtn = getByTestId('disconnect-compliance');
fireEvent.click(disconnectBtn);
expect(mockedDeleteComplianceAuthData).toHaveBeenCalled();
});
});