@@ -4,6 +4,7 @@ import { fireEvent, waitFor } from '@testing-library/react';
44import thunk from 'redux-thunk' ;
55import { Router } from 'react-router-dom' ;
66import { createMemoryHistory } from 'history' ;
7+ import { SeedlessOnboardingControllerErrorMessage } from '@metamask/seedless-onboarding-controller' ;
78import { renderWithProvider } from '../../../test/lib/render-helpers' ;
89import { ONBOARDING_WELCOME_ROUTE } from '../../helpers/constants/routes' ;
910import { FirstTimeFlowType } from '../../../shared/constants/onboarding' ;
@@ -15,11 +16,15 @@ const mockTryUnlockMetamask = jest.fn(() => {
1516 } ;
1617} ) ;
1718const mockMarkPasswordForgotten = jest . fn ( ) ;
19+ const mockResetWallet = jest . fn ( ( ) => {
20+ return Promise . resolve ( ) ;
21+ } ) ;
1822
1923jest . mock ( '../../store/actions.ts' , ( ) => ( {
2024 ...jest . requireActual ( '../../store/actions.ts' ) ,
2125 tryUnlockMetamask : ( ) => mockTryUnlockMetamask ,
2226 markPasswordForgotten : ( ) => mockMarkPasswordForgotten ,
27+ resetWallet : ( ) => mockResetWallet ,
2328} ) ) ;
2429
2530const mockElement = document . createElement ( 'svg' ) ;
@@ -192,4 +197,48 @@ describe('Unlock Page', () => {
192197 expect ( history . location . pathname ) . toBe ( intendedPath ) ;
193198 expect ( history . location . search ) . toBe ( intendedSearch ) ;
194199 } ) ;
200+
201+ it ( 'should show login error modal when authentication error is thrown' , async ( ) => {
202+ const intendedPath = '/intended-route' ;
203+ const intendedSearch = '?abc=123' ;
204+ const mockStateNonUnlocked = {
205+ metamask : { isUnlocked : false , completedOnboarding : true } ,
206+ } ;
207+ const store = configureMockStore ( [ thunk ] ) ( mockStateNonUnlocked ) ;
208+ const history = createMemoryHistory ( {
209+ initialEntries : [
210+ {
211+ pathname : '/unlock' ,
212+ state : { from : { pathname : intendedPath , search : intendedSearch } } ,
213+ } ,
214+ ] ,
215+ } ) ;
216+ jest . spyOn ( history , 'push' ) ;
217+
218+ mockTryUnlockMetamask . mockImplementationOnce (
219+ jest . fn ( ( ) => {
220+ return Promise . reject (
221+ new Error (
222+ SeedlessOnboardingControllerErrorMessage . AuthenticationError ,
223+ ) ,
224+ ) ;
225+ } ) ,
226+ ) ;
227+ const mockForceUpdateMetamaskState = jest . fn ( ) ;
228+
229+ const { queryByTestId } = renderWithProvider (
230+ < Router history = { history } >
231+ < UnlockPage forceUpdateMetamaskState = { mockForceUpdateMetamaskState } />
232+ </ Router > ,
233+ store ,
234+ ) ;
235+ const passwordField = queryByTestId ( 'unlock-password' ) ;
236+ const loginButton = queryByTestId ( 'unlock-submit' ) ;
237+ fireEvent . change ( passwordField , { target : { value : 'a-password' } } ) ;
238+ fireEvent . click ( loginButton ) ;
239+
240+ await waitFor ( ( ) => {
241+ expect ( queryByTestId ( 'login-error-modal' ) ) . toBeInTheDocument ( ) ;
242+ } ) ;
243+ } ) ;
195244} ) ;
0 commit comments