From c85c94aa40c3d91a474f76d6908b84d232ce5b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 19 Jun 2019 14:07:35 +0200 Subject: [PATCH] Splitting components, better route navigation This also allows us to generate a password reset link to quickly reset your password without entering the code and email manually. --- .../PasswordReset/ChangePassword.spec.js | 83 +++++++++ .../PasswordReset/ChangePassword.vue | 140 +++++++++++++++ ...{PasswordReset.spec.js => Request.spec.js} | 6 +- .../{PasswordReset.vue => Request.vue} | 0 .../PasswordReset/VerifyCode.spec.js | 47 +----- .../components/PasswordReset/VerifyCode.vue | 159 +++--------------- .../pages/password-reset/change-password.vue | 28 +++ webapp/pages/password-reset/request.vue | 6 +- webapp/pages/password-reset/verify-code.vue | 8 +- 9 files changed, 282 insertions(+), 195 deletions(-) create mode 100644 webapp/components/PasswordReset/ChangePassword.spec.js create mode 100644 webapp/components/PasswordReset/ChangePassword.vue rename webapp/components/PasswordReset/{PasswordReset.spec.js => Request.spec.js} (94%) rename webapp/components/PasswordReset/{PasswordReset.vue => Request.vue} (100%) create mode 100644 webapp/pages/password-reset/change-password.vue diff --git a/webapp/components/PasswordReset/ChangePassword.spec.js b/webapp/components/PasswordReset/ChangePassword.spec.js new file mode 100644 index 000000000..88caa6c6d --- /dev/null +++ b/webapp/components/PasswordReset/ChangePassword.spec.js @@ -0,0 +1,83 @@ +import { mount, createLocalVue } from '@vue/test-utils' +import ChangePassword from './ChangePassword' +import Styleguide from '@human-connection/styleguide' + +const localVue = createLocalVue() + +localVue.use(Styleguide) + +describe('ChangePassword ', () => { + let wrapper + let Wrapper + let mocks + let propsData + + beforeEach(() => { + propsData = {} + mocks = { + $toast: { + success: jest.fn(), + error: jest.fn(), + }, + $t: jest.fn(), + $apollo: { + loading: false, + mutate: jest.fn().mockResolvedValue({ data: { resetPassword: true } }), + }, + } + }) + + describe('mount', () => { + beforeEach(jest.useFakeTimers) + + Wrapper = () => { + return mount(ChangePassword, { + mocks, + propsData, + localVue, + }) + } + + describe('given email and verification code', () => { + beforeEach(() => { + propsData.email = 'mail@example.org' + propsData.code = '123456' + }) + + describe('submitting new password', () => { + beforeEach(() => { + wrapper = Wrapper() + wrapper.find('input#newPassword').setValue('supersecret') + wrapper.find('input#confirmPassword').setValue('supersecret') + wrapper.find('form').trigger('submit') + }) + + it('calls resetPassword graphql mutation', () => { + expect(mocks.$apollo.mutate).toHaveBeenCalled() + }) + + it('delivers new password to backend', () => { + const expected = expect.objectContaining({ + variables: { code: '123456', email: 'mail@example.org', newPassword: 'supersecret' }, + }) + expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected) + }) + + describe('password reset successful', () => { + it('displays success message', () => { + const expected = 'verify-code.form.change-password.success' + expect(mocks.$t).toHaveBeenCalledWith(expected) + }) + + describe('after animation', () => { + beforeEach(jest.runAllTimers) + + it('emits `change-password-sucess`', () => { + expect(wrapper.emitted('passwordResetResponse')).toEqual([['success']]) + }) + }) + }) + }) + }) + }) +}) diff --git a/webapp/components/PasswordReset/ChangePassword.vue b/webapp/components/PasswordReset/ChangePassword.vue new file mode 100644 index 000000000..5a12f9938 --- /dev/null +++ b/webapp/components/PasswordReset/ChangePassword.vue @@ -0,0 +1,140 @@ + + + diff --git a/webapp/components/PasswordReset/PasswordReset.spec.js b/webapp/components/PasswordReset/Request.spec.js similarity index 94% rename from webapp/components/PasswordReset/PasswordReset.spec.js rename to webapp/components/PasswordReset/Request.spec.js index 1adf68ee5..e7a1f6866 100644 --- a/webapp/components/PasswordReset/PasswordReset.spec.js +++ b/webapp/components/PasswordReset/Request.spec.js @@ -1,12 +1,12 @@ import { mount, createLocalVue } from '@vue/test-utils' -import PasswordReset from './PasswordReset' +import Request from './Request' import Styleguide from '@human-connection/styleguide' const localVue = createLocalVue() localVue.use(Styleguide) -describe('PasswordReset', () => { +describe('Request', () => { let wrapper let Wrapper let mocks @@ -29,7 +29,7 @@ describe('PasswordReset', () => { beforeEach(jest.useFakeTimers) Wrapper = () => { - return mount(PasswordReset, { + return mount(Request, { mocks, localVue, }) diff --git a/webapp/components/PasswordReset/PasswordReset.vue b/webapp/components/PasswordReset/Request.vue similarity index 100% rename from webapp/components/PasswordReset/PasswordReset.vue rename to webapp/components/PasswordReset/Request.vue diff --git a/webapp/components/PasswordReset/VerifyCode.spec.js b/webapp/components/PasswordReset/VerifyCode.spec.js index 6f489e55f..062e7e8f7 100644 --- a/webapp/components/PasswordReset/VerifyCode.spec.js +++ b/webapp/components/PasswordReset/VerifyCode.spec.js @@ -13,15 +13,7 @@ describe('VerifyCode ', () => { beforeEach(() => { mocks = { - $toast: { - success: jest.fn(), - error: jest.fn(), - }, $t: jest.fn(), - $apollo: { - loading: false, - mutate: jest.fn().mockResolvedValue({ data: { resetPassword: true } }), - }, } }) @@ -48,42 +40,9 @@ describe('VerifyCode ', () => { wrapper.find('form').trigger('submit') }) - it('displays a form to update your password', () => { - expect(wrapper.find('.change-password').exists()).toBe(true) - }) - - describe('submitting new password', () => { - beforeEach(() => { - wrapper.find('input#newPassword').setValue('supersecret') - wrapper.find('input#confirmPassword').setValue('supersecret') - wrapper.find('form').trigger('submit') - }) - - it('calls resetPassword graphql mutation', () => { - expect(mocks.$apollo.mutate).toHaveBeenCalled() - }) - - it('delivers new password to backend', () => { - const expected = expect.objectContaining({ - variables: { code: '123456', email: 'mail@example.org', newPassword: 'supersecret' }, - }) - expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected) - }) - - describe('password reset successful', () => { - it('displays success message', () => { - const expected = 'verify-code.form.change-password.success' - expect(mocks.$t).toHaveBeenCalledWith(expected) - }) - - describe('after animation', () => { - beforeEach(jest.runAllTimers) - - it('emits `change-password-sucess`', () => { - expect(wrapper.emitted('passwordResetResponse')).toEqual([['success']]) - }) - }) - }) + it('emits `verifyCode`', () => { + const expected = [[{ code: '123456', email: 'mail@example.org' }]] + expect(wrapper.emitted('verification')).toEqual(expected) }) }) }) diff --git a/webapp/components/PasswordReset/VerifyCode.vue b/webapp/components/PasswordReset/VerifyCode.vue index d53d08bf2..410a027af 100644 --- a/webapp/components/PasswordReset/VerifyCode.vue +++ b/webapp/components/PasswordReset/VerifyCode.vue @@ -2,9 +2,8 @@ - diff --git a/webapp/pages/password-reset/request.vue b/webapp/pages/password-reset/request.vue index 7cf37f537..9148b4ed4 100644 --- a/webapp/pages/password-reset/request.vue +++ b/webapp/pages/password-reset/request.vue @@ -1,13 +1,13 @@