Skip to content

Commit 50d30a0

Browse files
committed
Add more unit tests
1 parent a4f990b commit 50d30a0

File tree

3 files changed

+121
-3
lines changed

3 files changed

+121
-3
lines changed

ui/pages/permissions-connect/connect-page/__snapshots__/connect-page.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ exports[`ConnectPage should render with defaults from the requested permissions
489489
>
490490
<div>
491491
<div
492-
aria-describedby="tippy-tooltip-9"
492+
aria-describedby="tippy-tooltip-34"
493493
class=""
494494
data-original-title="Not connected"
495495
data-tooltipped=""

ui/pages/permissions-connect/connect-page/connect-page.test.tsx

+119-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,66 @@ describe('ConnectPage', () => {
7272
expect(container).toMatchSnapshot();
7373
});
7474

75+
it('should render image icon correctly', () => {
76+
const { getAllByAltText } = render();
77+
78+
const images = getAllByAltText('github.io logo');
79+
expect(images.length).toBe(2);
80+
expect(images[0]).toHaveAttribute(
81+
'src',
82+
'https://metamask.github.io/test-dapp/metamask-fox.svg',
83+
);
84+
expect(images[1]).toHaveAttribute(
85+
'src',
86+
'https://metamask.github.io/test-dapp/metamask-fox.svg',
87+
);
88+
});
89+
90+
it('should render fallback icon correctly', () => {
91+
const { container } = render({
92+
props: {
93+
request: {
94+
id: '1',
95+
origin: mockTestDappUrl,
96+
},
97+
permissionsRequestId: '1',
98+
rejectPermissionsRequest: jest.fn(),
99+
approveConnection: jest.fn(),
100+
activeTabOrigin: mockTestDappUrl,
101+
targetSubjectMetadata: {
102+
...mockTargetSubjectMetadata,
103+
iconUrl: null,
104+
},
105+
},
106+
});
107+
108+
const divElement = container.querySelector('div.mm-avatar-base--size-lg');
109+
expect(divElement).toHaveTextContent('g');
110+
});
111+
112+
it('should render fallback icon correctly for IP address as an origin', () => {
113+
const { container } = render({
114+
props: {
115+
request: {
116+
id: '1',
117+
origin: 'http://127.0.0.1/test-dapp',
118+
},
119+
permissionsRequestId: '1',
120+
rejectPermissionsRequest: jest.fn(),
121+
approveConnection: jest.fn(),
122+
activeTabOrigin: mockTestDappUrl,
123+
targetSubjectMetadata: {
124+
...mockTargetSubjectMetadata,
125+
iconUrl: null,
126+
origin: 'http://127.0.0.1/test-dapp',
127+
},
128+
},
129+
});
130+
131+
const divElement = container.querySelector('div.mm-avatar-base--size-lg');
132+
expect(divElement).toHaveTextContent('?');
133+
});
134+
75135
it('should render title correctly', () => {
76136
const { getByText } = render();
77137
expect(getByText('github.io')).toBeDefined();
@@ -82,6 +142,64 @@ describe('ConnectPage', () => {
82142
expect(getByText('Connect this website with MetaMask.')).toBeDefined();
83143
});
84144

145+
it('should render learn more link correctly', () => {
146+
const { getByText } = render();
147+
expect(getByText('Learn more')).toBeDefined();
148+
});
149+
150+
it('should render accounts tab correctly', () => {
151+
const { getByText, queryAllByText } = render();
152+
153+
expect(getByText('Accounts')).toBeDefined();
154+
expect(getByText('Test Account')).toBeDefined();
155+
expect(getByText('0x0DCD5...3E7bc')).toBeDefined();
156+
157+
const valueElements = queryAllByText('966.988');
158+
expect(valueElements[0]).toBeDefined();
159+
expect(getByText('Edit accounts')).toBeDefined();
160+
});
161+
162+
it('should render edit accounts modal', () => {
163+
const { getByText, queryAllByText } = render();
164+
const editAccountsButton = getByText('Edit accounts');
165+
fireEvent.click(editAccountsButton);
166+
167+
expect(getByText('Update')).toBeDefined();
168+
expect(getByText('Select all')).toBeDefined();
169+
expect(getByText('New account')).toBeDefined();
170+
171+
const accountElements = queryAllByText('Test Account');
172+
173+
expect(accountElements.length).toBe(2);
174+
expect(accountElements[0].textContent).toBe('Test Account');
175+
expect(accountElements[1].textContent).toBe('Test Account');
176+
});
177+
178+
it('should render empty accounts state correctly', () => {
179+
const { getByText, queryAllByText, getByTestId } = render();
180+
const editAccountsButton = getByText('Edit accounts');
181+
fireEvent.click(editAccountsButton);
182+
183+
const accountElements = queryAllByText('Test Account');
184+
fireEvent.click(accountElements[1]);
185+
186+
const disconnectButton = getByText('Disconnect');
187+
fireEvent.click(disconnectButton);
188+
189+
expect(getByText('Select an account to connect')).toBeDefined();
190+
191+
const confirmButton = getByTestId('confirm-btn');
192+
expect(confirmButton).toBeDisabled();
193+
194+
const selectAnAccountToConnectButton = getByText(
195+
'Select an account to connect',
196+
);
197+
fireEvent.click(selectAnAccountToConnectButton);
198+
199+
expect(getByText('Select all')).toBeDefined();
200+
expect(getByText('New account')).toBeDefined();
201+
});
202+
85203
it('should render account connectionListItem', () => {
86204
const { getByText } = render();
87205
const permissionsTab = getByText('Permissions');
@@ -161,7 +279,7 @@ describe('ConnectPage', () => {
161279
const confirmButton = getByText('Connect');
162280
const cancelButton = getByText('Cancel');
163281
// The currently selected account is a Bitcoin account, the "connecting account list" would be
164-
// empty by default and thus, we cannot confirm without explictly select an EVM account.
282+
// empty by default and thus, we cannot confirm without explicitly select an EVM account.
165283
expect(confirmButton).toBeDisabled();
166284
expect(cancelButton).toBeDefined();
167285
});

ui/pages/permissions-connect/connect-page/connect-page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export type ConnectPageProps = {
8181
activeTabOrigin: string;
8282
targetSubjectMetadata: {
8383
extensionId: string | null;
84-
iconUrl: string;
84+
iconUrl: string | null;
8585
name: string;
8686
origin: string;
8787
subjectType: string;

0 commit comments

Comments
 (0)