Skip to content

Commit 245a18f

Browse files
committed
test: cover multichain account DS migration
1 parent ece36e1 commit 245a18f

2 files changed

Lines changed: 65 additions & 9 deletions

File tree

app/component-library/components-temp/MultichainAccounts/MultichainAddressRow/MultichainAddressRow.test.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render, fireEvent } from '@testing-library/react-native';
2+
import { act, render, fireEvent } from '@testing-library/react-native';
33
import MultichainAddressRow from './MultichainAddressRow';
44
import {
55
SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS,
@@ -24,6 +24,10 @@ jest.mock('../../../../util/networks', () => ({
2424
}));
2525

2626
describe('MultichainAddressRow', () => {
27+
afterEach(() => {
28+
jest.useRealTimers();
29+
});
30+
2731
it('renders MultichainAddressRow correctly', () => {
2832
const { getByTestId } = render(
2933
<MultichainAddressRow {...SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS} />,
@@ -142,8 +146,9 @@ describe('MultichainAddressRow', () => {
142146

143147
const copyButton = getByTestId(MULTICHAIN_ADDRESS_ROW_COPY_BUTTON_TEST_ID);
144148

145-
// Simulate pressing the copy button
146-
fireEvent.press(copyButton);
149+
await act(async () => {
150+
fireEvent.press(copyButton);
151+
});
147152

148153
// Callback should be called
149154
expect(mockCallback).toHaveBeenCalled();
@@ -176,12 +181,14 @@ describe('MultichainAddressRow', () => {
176181
});
177182

178183
it('shows toast when copy button is pressed and toastRef is provided', async () => {
184+
jest.useFakeTimers();
179185
const mockCallback = jest.fn();
180186
const mockShowToast = jest.fn();
187+
const mockCloseToast = jest.fn();
181188
const mockToastRef = {
182189
current: {
183190
showToast: mockShowToast,
184-
closeToast: jest.fn(),
191+
closeToast: mockCloseToast,
185192
},
186193
};
187194
const copyParams = {
@@ -199,19 +206,30 @@ describe('MultichainAddressRow', () => {
199206

200207
const copyButton = getByTestId(MULTICHAIN_ADDRESS_ROW_COPY_BUTTON_TEST_ID);
201208

202-
// Simulate pressing the copy button
203-
fireEvent.press(copyButton);
204-
205-
// Wait for async operations
206-
await new Promise((resolve) => setTimeout(resolve, 0));
209+
await act(async () => {
210+
fireEvent.press(copyButton);
211+
});
207212

208213
// Toast should be called with Plain variant (no icon)
209214
expect(mockShowToast).toHaveBeenCalled();
210215
expect(mockShowToast).toHaveBeenCalledWith(
211216
expect.objectContaining({
212217
variant: expect.stringContaining('Plain'),
218+
labelOptions: [{ label: 'Address copied' }],
219+
closeButtonOptions: expect.objectContaining({
220+
variant: 'Icon',
221+
iconName: IconName.Close,
222+
}),
213223
}),
214224
);
225+
226+
const toastOptions = mockShowToast.mock.calls[0][0];
227+
toastOptions.closeButtonOptions.onPress();
228+
expect(mockCloseToast).toHaveBeenCalled();
229+
230+
act(() => {
231+
jest.advanceTimersByTime(400);
232+
});
215233
});
216234

217235
it('renders truncated address correctly when copyParams is missing', () => {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { AvatarAccountVariant } from '@metamask/design-system-react-native';
2+
import {
3+
type AccountAvatarVariant,
4+
AvatarAccountType,
5+
getAvatarAccountVariant,
6+
} from './avatarAccountVariant';
7+
8+
const avatarVariantCases: [AccountAvatarVariant, AvatarAccountVariant][] = [
9+
['JazzIcon', AvatarAccountVariant.Jazzicon],
10+
['Blockies', AvatarAccountVariant.Blockies],
11+
['Maskicon', AvatarAccountVariant.Maskicon],
12+
[AvatarAccountVariant.Jazzicon, AvatarAccountVariant.Jazzicon],
13+
[AvatarAccountVariant.Blockies, AvatarAccountVariant.Blockies],
14+
[AvatarAccountVariant.Maskicon, AvatarAccountVariant.Maskicon],
15+
];
16+
17+
describe('avatarAccountVariant', () => {
18+
it.each(avatarVariantCases)(
19+
'maps %s to the matching DS avatar variant',
20+
(input, expected) => {
21+
expect(getAvatarAccountVariant(input)).toBe(expected);
22+
},
23+
);
24+
25+
it('defaults to Maskicon for unknown avatar variants', () => {
26+
expect(getAvatarAccountVariant('Unknown' as AccountAvatarVariant)).toBe(
27+
AvatarAccountVariant.Maskicon,
28+
);
29+
});
30+
31+
it('exposes legacy avatar type names with DS variant values', () => {
32+
expect(AvatarAccountType).toEqual({
33+
JazzIcon: AvatarAccountVariant.Jazzicon,
34+
Blockies: AvatarAccountVariant.Blockies,
35+
Maskicon: AvatarAccountVariant.Maskicon,
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)