From 3848fcffa478531ffb167049965122e7844c8175 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 27 Apr 2021 15:51:18 +0200 Subject: SONAR-14604 Improve reset password form layout --- .../common/__tests__/ResetPassword-test.tsx | 79 --------------------- .../common/__tests__/ResetPasswordForm-test.tsx | 79 +++++++++++++++++++++ .../__snapshots__/ResetPassword-test.tsx.snap | 81 ---------------------- .../__snapshots__/ResetPasswordForm-test.tsx.snap | 71 +++++++++++++++++++ 4 files changed, 150 insertions(+), 160 deletions(-) delete mode 100644 server/sonar-web/src/main/js/components/common/__tests__/ResetPassword-test.tsx create mode 100644 server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPassword-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPasswordForm-test.tsx.snap (limited to 'server/sonar-web/src/main/js/components/common/__tests__') diff --git a/server/sonar-web/src/main/js/components/common/__tests__/ResetPassword-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/ResetPassword-test.tsx deleted file mode 100644 index 904f693ed69..00000000000 --- a/server/sonar-web/src/main/js/components/common/__tests__/ResetPassword-test.tsx +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; -import { changePassword } from '../../../api/users'; -import { mockEvent, mockLoggedInUser } from '../../../helpers/testMocks'; -import ResetPassword from '../ResetPassword'; - -jest.mock('../../../api/users', () => ({ - changePassword: jest.fn().mockResolvedValue({}) -})); - -it('should trigger on password change prop', () => { - const onPasswordChange = jest.fn(); - const wrapper = shallowRender({ onPasswordChange }); - wrapper.instance().handleSuccessfulChange(); - expect(onPasswordChange).not.toBeCalled(); - wrapper.instance().oldPassword = { value: '' } as HTMLInputElement; - wrapper.instance().password = { value: '' } as HTMLInputElement; - wrapper.instance().passwordConfirmation = { value: '' } as HTMLInputElement; - wrapper.instance().handleSuccessfulChange(); - expect(onPasswordChange).toBeCalled(); -}); - -it('should not trigger password change', () => { - const wrapper = shallowRender(); - wrapper.instance().oldPassword = { value: 'testold' } as HTMLInputElement; - wrapper.instance().password = { value: 'test', focus: () => {} } as HTMLInputElement; - wrapper.instance().passwordConfirmation = { value: 'test1' } as HTMLInputElement; - wrapper.instance().handleChangePassword(mockEvent()); - expect(changePassword).not.toBeCalled(); - expect(wrapper.state().errors).toBeDefined(); -}); - -it('should trigger password change', async () => { - const user = mockLoggedInUser(); - const wrapper = shallowRender({ user }); - wrapper.instance().handleChangePassword(mockEvent()); - await waitAndUpdate(wrapper); - expect(changePassword).not.toBeCalled(); - - wrapper.instance().oldPassword = { value: 'testold' } as HTMLInputElement; - wrapper.instance().password = { value: 'test' } as HTMLInputElement; - wrapper.instance().passwordConfirmation = { value: 'test' } as HTMLInputElement; - wrapper.instance().handleChangePassword(mockEvent()); - await waitAndUpdate(wrapper); - - expect(changePassword).toBeCalledWith({ - login: user.login, - password: 'test', - previousPassword: 'testold' - }); -}); - -it('renders correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -function shallowRender(props?: Partial) { - return shallow(); -} diff --git a/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx new file mode 100644 index 00000000000..e940f20395e --- /dev/null +++ b/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx @@ -0,0 +1,79 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { shallow } from 'enzyme'; +import * as React from 'react'; +import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; +import { changePassword } from '../../../api/users'; +import { mockEvent, mockLoggedInUser } from '../../../helpers/testMocks'; +import ResetPasswordForm from '../ResetPasswordForm'; + +jest.mock('../../../api/users', () => ({ + changePassword: jest.fn().mockResolvedValue({}) +})); + +it('should trigger on password change prop', () => { + const onPasswordChange = jest.fn(); + const wrapper = shallowRender({ onPasswordChange }); + wrapper.instance().handleSuccessfulChange(); + expect(onPasswordChange).not.toBeCalled(); + wrapper.instance().oldPassword = { value: '' } as HTMLInputElement; + wrapper.instance().password = { value: '' } as HTMLInputElement; + wrapper.instance().passwordConfirmation = { value: '' } as HTMLInputElement; + wrapper.instance().handleSuccessfulChange(); + expect(onPasswordChange).toBeCalled(); +}); + +it('should not trigger password change', () => { + const wrapper = shallowRender(); + wrapper.instance().oldPassword = { value: 'testold' } as HTMLInputElement; + wrapper.instance().password = { value: 'test', focus: () => {} } as HTMLInputElement; + wrapper.instance().passwordConfirmation = { value: 'test1' } as HTMLInputElement; + wrapper.instance().handleChangePassword(mockEvent()); + expect(changePassword).not.toBeCalled(); + expect(wrapper.state().errors).toBeDefined(); +}); + +it('should trigger password change', async () => { + const user = mockLoggedInUser(); + const wrapper = shallowRender({ user }); + wrapper.instance().handleChangePassword(mockEvent()); + await waitAndUpdate(wrapper); + expect(changePassword).not.toBeCalled(); + + wrapper.instance().oldPassword = { value: 'testold' } as HTMLInputElement; + wrapper.instance().password = { value: 'test' } as HTMLInputElement; + wrapper.instance().passwordConfirmation = { value: 'test' } as HTMLInputElement; + wrapper.instance().handleChangePassword(mockEvent()); + await waitAndUpdate(wrapper); + + expect(changePassword).toBeCalledWith({ + login: user.login, + password: 'test', + previousPassword: 'testold' + }); +}); + +it('renders correctly', () => { + expect(shallowRender()).toMatchSnapshot(); +}); + +function shallowRender(props?: Partial) { + return shallow(); +} diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPassword-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPassword-test.tsx.snap deleted file mode 100644 index f2fbe03c093..00000000000 --- a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPassword-test.tsx.snap +++ /dev/null @@ -1,81 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders correctly 1`] = ` -
-

- my_profile.password.title -

-
- -
- - -
-
- - -
-
- - -
-
- - update_verb - -
- -
-`; diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPasswordForm-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPasswordForm-test.tsx.snap new file mode 100644 index 00000000000..3f32833747d --- /dev/null +++ b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/ResetPasswordForm-test.tsx.snap @@ -0,0 +1,71 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders correctly 1`] = ` +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + update_verb + +
+ +`; -- cgit v1.2.3