Skip to content

Commit d7b8e72

Browse files
committed
fix: fixed firefox e2e and added unit tests
1 parent 7b22c46 commit d7b8e72

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

test/e2e/tests/account/unlock-wallet.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ describe('Unlock wallet - ', function () {
5555
userEmail: MOCK_GOOGLE_ACCOUNT,
5656
});
5757
},
58+
ignoredConsoleErrors: [
59+
'#snapSignMessage - unable to proceed, wallet is locked',
60+
],
5861
},
5962
async ({ driver }: { driver: Driver }) => {
6063
await importWalletWithSocialLoginOnboardingFlow({

ui/pages/unlock-page/unlock-page.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class UnlockPage extends Component {
444444
this.setState({ showLoginErrorModal: false });
445445
await this.props.resetWallet();
446446
await this.props.forceUpdateMetamaskState();
447-
this.props.history.replace(ONBOARDING_WELCOME_ROUTE);
447+
this.props.history.replace(DEFAULT_ROUTE);
448448
};
449449

450450
render() {

ui/pages/unlock-page/unlock-page.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { fireEvent, waitFor } from '@testing-library/react';
44
import thunk from 'redux-thunk';
55
import { Router } from 'react-router-dom';
66
import { createMemoryHistory } from 'history';
7+
import { SeedlessOnboardingControllerErrorMessage } from '@metamask/seedless-onboarding-controller';
78
import { renderWithProvider } from '../../../test/lib/render-helpers';
89
import { ONBOARDING_WELCOME_ROUTE } from '../../helpers/constants/routes';
910
import { FirstTimeFlowType } from '../../../shared/constants/onboarding';
@@ -15,11 +16,15 @@ const mockTryUnlockMetamask = jest.fn(() => {
1516
};
1617
});
1718
const mockMarkPasswordForgotten = jest.fn();
19+
const mockResetWallet = jest.fn(() => {
20+
return Promise.resolve();
21+
});
1822

1923
jest.mock('../../store/actions.ts', () => ({
2024
...jest.requireActual('../../store/actions.ts'),
2125
tryUnlockMetamask: () => mockTryUnlockMetamask,
2226
markPasswordForgotten: () => mockMarkPasswordForgotten,
27+
resetWallet: () => mockResetWallet,
2328
}));
2429

2530
const 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

Comments
 (0)