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 @@