@@ -72,6 +72,66 @@ describe('ConnectPage', () => {
72
72
expect ( container ) . toMatchSnapshot ( ) ;
73
73
} ) ;
74
74
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
+
75
135
it ( 'should render title correctly' , ( ) => {
76
136
const { getByText } = render ( ) ;
77
137
expect ( getByText ( 'github.io' ) ) . toBeDefined ( ) ;
@@ -82,6 +142,64 @@ describe('ConnectPage', () => {
82
142
expect ( getByText ( 'Connect this website with MetaMask.' ) ) . toBeDefined ( ) ;
83
143
} ) ;
84
144
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
+
85
203
it ( 'should render account connectionListItem' , ( ) => {
86
204
const { getByText } = render ( ) ;
87
205
const permissionsTab = getByText ( 'Permissions' ) ;
@@ -161,7 +279,7 @@ describe('ConnectPage', () => {
161
279
const confirmButton = getByText ( 'Connect' ) ;
162
280
const cancelButton = getByText ( 'Cancel' ) ;
163
281
// 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.
165
283
expect ( confirmButton ) . toBeDisabled ( ) ;
166
284
expect ( cancelButton ) . toBeDefined ( ) ;
167
285
} ) ;
0 commit comments