1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/app/menu-bar/account-options-menu.test.js
Albert Olivé dfb2c0e0e8
[MMI] Added code fencing in app menu bar (#18069)
* Added code fencing in app me nu bar

* Fixed lint issues

* Fixed yarn.lock

* Fixed issue

* Fixed tests

* Fixed yarn.lock

* Fixing policies

* Fixing lavamoat

* fixed yarn.lock

* Fixed storybook

* clean up and adds test

* lint

* typo

* adds test

---------

Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
2023-05-23 14:51:39 +02:00

105 lines
3.0 KiB
JavaScript

import React from 'react';
import configureStore from 'redux-mock-store';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import mockState from '../../../../test/data/mock-state.json';
import AccountOptionsMenu from './account-options-menu';
const initState = {
...mockState,
metamask: {
...mockState.metamask,
providerConfig: {
type: 'test',
chainId: '1',
},
identities: {
'0x5Ab19e7091dD208F352F8E727B6DCC6F8aBB6275': {
name: 'Custody Account A',
address: '0x5Ab19e7091dD208F352F8E727B6DCC6F8aBB6275',
},
},
selectedAddress: '0x5Ab19e7091dD208F352F8E727B6DCC6F8aBB6275',
keyrings: [
{
type: 'Custody',
accounts: ['0x5Ab19e7091dD208F352F8E727B6DCC6F8aBB6275'],
},
],
custodyStatusMaps: '123',
custodyAccountDetails: {
'0x5Ab19e7091dD208F352F8E727B6DCC6F8aBB6275': {
custodianName: 'saturn',
},
},
custodianSupportedChains: {
'0x5Ab19e7091dD208F352F8E727B6DCC6F8aBB6275': {
supportedChains: ['1', '2'],
custodianName: 'saturn',
},
},
mmiConfiguration: {
portfolio: {
enabled: true,
url: 'https://dashboard.metamask-institutional.io',
},
custodians: [
{
type: 'saturn',
name: 'saturn',
apiUrl: 'https://saturn-custody.dev.metamask-institutional.io',
iconUrl: 'images/saturn.svg',
displayName: 'Saturn Custody',
production: true,
refreshTokenUrl: null,
isNoteToTraderSupported: false,
version: 1,
},
],
},
},
};
const mockStore = configureStore();
const props = {
onClose: jest.fn(),
anchorElement: document.body,
};
const mockedGetCustodianToken = jest.fn().mockReturnValue({ type: 'TYPE' });
const mockedGetAllCustodianAccountsWithToken = jest
.fn()
.mockReturnValue({ type: 'TYPE' });
jest.mock('../../../store/institutional/institution-background', () => ({
mmiActionsFactory: () => ({
getCustodianToken: mockedGetCustodianToken,
getAllCustodianAccountsWithToken: mockedGetAllCustodianAccountsWithToken,
}),
}));
describe('AccountOptionsMenu', () => {
it('shows the remove account and remove jwt menu options', async () => {
const store = mockStore(initState);
renderWithProvider(<AccountOptionsMenu {...props} />, store);
await waitFor(() => {
expect(
screen.queryByTestId('account-options-menu__connected-sites'),
).toBeInTheDocument();
const removeAccount = screen.queryByTestId(
'account-options-menu__remove-account',
);
fireEvent.click(removeAccount);
expect(props.onClose).toHaveBeenCalled();
const removeJwt = screen.queryByTestId(
'account-options-menu__remove-jwt',
);
fireEvent.click(removeJwt);
expect(mockedGetCustodianToken).toHaveBeenCalled();
});
});
});