From 6de0696b787697b03ce86540eaa91462278131a4 Mon Sep 17 00:00:00 2001
From: Albert Olive
Date: Mon, 2 Oct 2023 10:54:01 +0200
Subject: [PATCH 1/4] Added unit tests
---
test/data/mock-state.json | 8 +++
.../account-list-item-menu.js | 2 +
.../account-list-item-menu.test.js | 50 +++++++++++++++++++
3 files changed, 60 insertions(+)
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();
+ });
+ });
});
From 3d1e0b90b65cd34468b130ef581cb6635f437840 Mon Sep 17 00:00:00 2001
From: Albert Olive
Date: Mon, 2 Oct 2023 14:07:12 +0200
Subject: [PATCH 2/4] Fixed tests
---
.../multichain/account-list-menu/account-list-menu.test.js | 2 +-
ui/selectors/selectors.test.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
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/selectors/selectors.test.js b/ui/selectors/selectors.test.js
index bfa8c412f2c6..9ffc3b375320 100644
--- a/ui/selectors/selectors.test.js
+++ b/ui/selectors/selectors.test.js
@@ -556,7 +556,7 @@ describe('Selectors', () => {
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',
);
From 3b86035ffec9a6266a755660f87e736ed74f6f29 Mon Sep 17 00:00:00 2001
From: Albert Olive
Date: Mon, 2 Oct 2023 14:30:39 +0200
Subject: [PATCH 3/4] Fixing tests
---
.../multichain/create-account/create-account.test.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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, {
From 6a7809f9a0242601e6623845b157b327dc5b5a18 Mon Sep 17 00:00:00 2001
From: Albert Olive
Date: Mon, 2 Oct 2023 14:39:55 +0200
Subject: [PATCH 4/4] updated snapshots
---
.../add-recipient.component.test.js.snap | 126 ++++++++++++++++++
1 file changed, 126 insertions(+)
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
+
+
+