1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/ui/components/institutional/interactive-replacement-token-notification/interactive-replacement-token-notification.test.js
Albert Olivé 47fe542273
[MMI] Review interactive replacement token flow (#19974)
* Sending showCustodyConfirmLink as a prop and fixing other issues

* Upgraded MMI extension monrepo and trying to fix the issue

* prevents deeplink from closing

* Fixed styles of Custody view and changed the place of it

* Fixed CI issues

* fixing eslint issues

* Update LavaMoat policies

* fixing tests

* Fixed test

* updated snapshots

* Improving IRT flow

* Fixing everything

* Finish fixing all issues

* Fixed institutional entity done page styles

* Fixing boxes

* Fixed issue with checkbox

* Fixed tests and styles

* Removed duplicated lodash

* updated snapshot

* Fixing tests

* Removed unused test

* Fixed snapshot

* Fixed snapshot

---------

Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
2023-07-13 18:27:49 +02:00

155 lines
4.4 KiB
JavaScript

import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { screen, fireEvent } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { sha256 } from '../../../../shared/modules/hash.utils';
import { KeyringType } from '../../../../shared/constants/keyring';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import InteractiveReplacementTokenNotification from './interactive-replacement-token-notification';
jest.mock('../../../../shared/modules/hash.utils');
const mockedGetCustodianToken = jest
.fn()
.mockReturnValue({ type: 'Custody', payload: 'token' });
const mockedGetAllCustodianAccountsWithToken = jest.fn().mockReturnValue({
type: 'TYPE',
payload: [
{
address: '0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281',
authDetails: { refreshToken: 'def' },
},
],
});
jest.mock('../../../store/institutional/institution-background', () => ({
mmiActionsFactory: () => ({
getCustodianToken: mockedGetCustodianToken,
getAllCustodianAccountsWithToken: mockedGetAllCustodianAccountsWithToken,
}),
}));
jest.mock('../../../store/institutional/institution-actions', () => ({
showInteractiveReplacementTokenModal: jest
.fn()
.mockReturnValue({ type: 'TYPE' }),
}));
describe('Interactive Replacement Token Notification', () => {
const selectedAddress = '0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281';
const identities = {
'0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281': {
address: '0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281',
name: 'Custodian A',
},
};
const mockStore = {
metamask: {
providerConfig: {
type: 'test',
},
selectedAddress,
identities,
isUnlocked: false,
interactiveReplacementToken: { oldRefreshToken: 'abc' },
preferences: {
useNativeCurrencyAsPrimaryCurrency: true,
},
keyrings: [
{
type: KeyringType.imported,
accounts: ['0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281', '0x2'],
},
{
type: KeyringType.ledger,
accounts: [],
},
],
},
};
it('should not render if show notification is false', () => {
const store = configureMockStore([thunk])(mockStore);
renderWithProvider(<InteractiveReplacementTokenNotification />, store);
expect(
screen.queryByTestId('interactive-replacement-token-notification'),
).not.toBeInTheDocument();
});
it('should render if show notification is true and click on learn more', async () => {
const customMockStore = {
...mockStore,
metamask: {
...mockStore.metamask,
isUnlocked: true,
interactiveReplacementToken: { oldRefreshToken: 'def', url: 'url' },
keyrings: [
{
type: 'Custody - Saturn',
accounts: ['0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281'],
},
],
},
};
const store = configureMockStore([thunk])(customMockStore);
sha256.mockReturnValue('def');
await act(async () => {
renderWithProvider(<InteractiveReplacementTokenNotification />, store);
});
expect(
screen.getByTestId('interactive-replacement-token-notification'),
).toBeInTheDocument();
expect(screen.getByTestId('show-modal')).toBeInTheDocument();
await act(async () => {
fireEvent.click(screen.getByTestId('show-modal'));
});
});
it('should render and call showNotification when component starts', async () => {
const customMockStore = {
...mockStore,
metamask: {
...mockStore.metamask,
isUnlocked: true,
interactiveReplacementToken: { oldRefreshToken: 'def', url: 'url' },
keyrings: [
{
type: 'Custody - Saturn',
accounts: ['0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281', '0x2'],
},
{
type: KeyringType.ledger,
accounts: [],
},
],
},
};
const store = configureMockStore([thunk])(customMockStore);
sha256.mockReturnValue('def');
await act(async () => {
renderWithProvider(<InteractiveReplacementTokenNotification />, store);
});
expect(mockedGetCustodianToken).toHaveBeenCalled();
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
expect(
screen.getByTestId('interactive-replacement-token-notification'),
).toBeInTheDocument();
});
});