From b8591ea6a2d470d63732c0f31a46c2fcb7057ef3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Oliv=C3=A9?=
Date: Mon, 2 Oct 2023 17:10:31 +0200
Subject: [PATCH] [MMI] Add Account-list-item-menu unit test (#21138)
## Explanation
Add Account-list-item-menu unit test
## Pre-merge author checklist
- [x] I've clearly explained:
- [x] What problem this PR is solving
- [x] How this problem was solved
- [x] How reviewers can test my changes
- [x] Sufficient automated test coverage has been added
## Pre-merge reviewer checklist
- [x] Manual testing (e.g. pull and build branch, run in browser, test
code being changed)
- [x] **IF** this PR fixes a bug in the release milestone, add this PR
to the release milestone
If further QA is required (e.g. new feature, complex testing steps,
large refactor), add the `Extension QA Board` label.
In this case, a QA Engineer approval will be be required.
---
test/data/mock-state.json | 8 ++
.../account-list-item-menu.js | 2 +
.../account-list-item-menu.test.js | 50 +++++++
.../account-list-menu.test.js | 2 +-
.../create-account/create-account.test.js | 6 +-
.../add-recipient.component.test.js.snap | 126 ++++++++++++++++++
ui/selectors/selectors.test.js | 2 +-
7 files changed, 191 insertions(+), 5 deletions(-)
diff --git a/test/data/mock-state.json b/test/data/mock-state.json
index be994991cb49..95a1e6caff3d 100644
--- a/test/data/mock-state.json
+++ b/test/data/mock-state.json
@@ -152,6 +152,10 @@
{
"type": "Snap Keyring",
"accounts": ["0xb552685e3d2790efd64a175b00d51f02cdafee5d"]
+ },
+ {
+ "type": "Custody test",
+ "accounts": ["0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281"]
}
],
"identities": {
@@ -170,6 +174,10 @@
"0xeb9e64b93097bc15f01f13eae97015c57ab64823": {
"name": "Test Account 3",
"address": "0xeb9e64b93097bc15f01f13eae97015c57ab64823"
+ },
+ "0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281": {
+ "name": "Custody test",
+ "address": "0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281"
}
},
"selectedNetworkClientId": "goerli",
diff --git a/ui/components/multichain/account-list-item-menu/account-list-item-menu.js b/ui/components/multichain/account-list-item-menu/account-list-item-menu.js
index 036ae0a848ea..5475a883de98 100644
--- a/ui/components/multichain/account-list-item-menu/account-list-item-menu.js
+++ b/ui/components/multichain/account-list-item-menu/account-list-item-menu.js
@@ -178,12 +178,14 @@ export const AccountListItemMenu = ({
const token = await dispatch(
mmiActions.getCustodianToken(identity.address),
);
+
const custodyAccountDetails = await dispatch(
mmiActions.getAllCustodianAccountsWithToken(
keyring.type.split(' - ')[1],
token,
),
);
+
dispatch(
showModal({
name: 'CONFIRM_REMOVE_JWT',
diff --git a/ui/components/multichain/account-list-item-menu/account-list-item-menu.test.js b/ui/components/multichain/account-list-item-menu/account-list-item-menu.test.js
index b601e2f8657d..e2ba38124531 100644
--- a/ui/components/multichain/account-list-item-menu/account-list-item-menu.test.js
+++ b/ui/components/multichain/account-list-item-menu/account-list-item-menu.test.js
@@ -1,10 +1,22 @@
/* eslint-disable jest/require-top-level-describe */
import React from 'react';
+import { act, fireEvent } from '@testing-library/react';
+import { mmiActionsFactory } from '../../../store/institutional/institution-background';
import { renderWithProvider } from '../../../../test/jest';
import configureStore from '../../../store/store';
import mockState from '../../../../test/data/mock-state.json';
import { AccountListItemMenu } from '.';
+const mockShowModal = jest.fn();
+
+jest.mock('../../../store/institutional/institution-background');
+
+jest.mock('../../../store/actions', () => {
+ return {
+ showModal: () => mockShowModal,
+ };
+});
+
const identity = {
...mockState.metamask.identities[
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
@@ -35,4 +47,42 @@ describe('AccountListItem', () => {
const { getByTestId } = render({ isRemovable: true });
expect(getByTestId('account-list-menu-remove')).toBeInTheDocument();
});
+
+ it('should render remove JWT menu item if the user is custodian and click the button', async () => {
+ const mockedGetCustodianToken = jest
+ .fn()
+ .mockReturnValue({ type: 'Custody', payload: 'token' });
+ const mockedGetAllCustodianAccountsWithToken = jest
+ .fn()
+ .mockReturnValue({ type: 'Custody', payload: 'token' });
+
+ mmiActionsFactory.mockReturnValue({
+ getCustodianToken: mockedGetCustodianToken,
+ getAllCustodianAccountsWithToken: mockedGetAllCustodianAccountsWithToken,
+ });
+
+ const newIdentity = {
+ ...mockState.metamask.identities[
+ '0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281'
+ ],
+ balance: '0x152387ad22c3f0',
+ };
+
+ const { getByTestId } = render({ identity: newIdentity });
+
+ const removeJWTButton = getByTestId('account-options-menu__remove-jwt');
+
+ expect(removeJWTButton).toBeInTheDocument();
+
+ fireEvent.click(removeJWTButton);
+
+ await act(async () => {
+ expect(mockedGetCustodianToken).toHaveBeenCalledWith(newIdentity.address);
+ });
+
+ await act(async () => {
+ expect(mockedGetAllCustodianAccountsWithToken).toHaveBeenCalled();
+ expect(mockShowModal).toHaveBeenCalled();
+ });
+ });
});
diff --git a/ui/components/multichain/account-list-menu/account-list-menu.test.js b/ui/components/multichain/account-list-menu/account-list-menu.test.js
index 28d2af13f699..ebdc008732db 100644
--- a/ui/components/multichain/account-list-menu/account-list-menu.test.js
+++ b/ui/components/multichain/account-list-menu/account-list-menu.test.js
@@ -94,7 +94,7 @@ describe('AccountListMenu', () => {
const listItems = document.querySelectorAll(
'.multichain-account-list-item',
);
- expect(listItems).toHaveLength(4);
+ expect(listItems).toHaveLength(5);
const searchBox = document.querySelector('input[type=search]');
fireEvent.change(searchBox, {
diff --git a/ui/components/multichain/create-account/create-account.test.js b/ui/components/multichain/create-account/create-account.test.js
index f93f013afc08..6bbe52831add 100644
--- a/ui/components/multichain/create-account/create-account.test.js
+++ b/ui/components/multichain/create-account/create-account.test.js
@@ -26,14 +26,14 @@ describe('CreateAccount', () => {
it('displays account name input and suggests name', () => {
const { getByPlaceholderText } = render();
- expect(getByPlaceholderText('Account 5')).toBeInTheDocument();
+ expect(getByPlaceholderText('Account 6')).toBeInTheDocument();
});
it('fires onActionComplete when clicked', async () => {
const onActionComplete = jest.fn();
const { getByText, getByPlaceholderText } = render({ onActionComplete });
- const input = getByPlaceholderText('Account 5');
+ const input = getByPlaceholderText('Account 6');
const newAccountName = 'New Account Name';
fireEvent.change(input, {
@@ -54,7 +54,7 @@ describe('CreateAccount', () => {
it(`doesn't allow duplicate account names`, async () => {
const { getByText, getByPlaceholderText } = render();
- const input = getByPlaceholderText('Account 5');
+ const input = getByPlaceholderText('Account 6');
const usedAccountName = 'Account 4';
fireEvent.change(input, {
diff --git a/ui/pages/send/send-content/add-recipient/__snapshots__/add-recipient.component.test.js.snap b/ui/pages/send/send-content/add-recipient/__snapshots__/add-recipient.component.test.js.snap
index b6587dd99582..fbcbeac549ee 100644
--- a/ui/pages/send/send-content/add-recipient/__snapshots__/add-recipient.component.test.js.snap
+++ b/ui/pages/send/send-content/add-recipient/__snapshots__/add-recipient.component.test.js.snap
@@ -273,6 +273,69 @@ exports[`Add Recipient Component Domain Resolution should match snapshot 1`] = `
+
+
+
+
+ Custody test
+
+
+ 0xca8f...f281
+
+
+
+
+
+
+
+ Custody test
+
+
+ 0xca8f...f281
+
+
+
{
it('returns accounts with balance, address, and name from identity and accounts in state', () => {
const accountsWithSendEther =
selectors.accountsWithSendEtherInfoSelector(mockState);
- expect(accountsWithSendEther).toHaveLength(4);
+ expect(accountsWithSendEther).toHaveLength(5);
expect(accountsWithSendEther[0].balance).toStrictEqual(
'0x346ba7725f412cbfdb',
);