diff --git a/resources/assets/src/components/auth/Reset.vue b/resources/assets/src/components/auth/Reset.vue new file mode 100644 index 00000000..fd778b43 --- /dev/null +++ b/resources/assets/src/components/auth/Reset.vue @@ -0,0 +1,95 @@ + + + diff --git a/resources/assets/src/components/route.js b/resources/assets/src/components/route.js index ad8ad7d4..b133ac7c 100644 --- a/resources/assets/src/components/route.js +++ b/resources/assets/src/components/route.js @@ -49,4 +49,9 @@ export default [ component: () => import('./auth/Forgot'), el: 'form' }, + { + path: 'auth/reset/(\\d+)', + component: () => import('./auth/Reset'), + el: 'form' + }, ]; diff --git a/resources/assets/tests/components/auth/Reset.test.js b/resources/assets/tests/components/auth/Reset.test.js new file mode 100644 index 00000000..75a58546 --- /dev/null +++ b/resources/assets/tests/components/auth/Reset.test.js @@ -0,0 +1,52 @@ +import Vue from 'vue'; +import { mount } from '@vue/test-utils'; +import Reset from '@/components/auth/Reset'; +import { swal } from '@/js/notify'; + +jest.mock('@/js/notify'); + +test('reset password', async () => { + Vue.prototype.$http.post + .mockResolvedValueOnce({ errno: 1, msg: 'fail' }) + .mockResolvedValueOnce({ errno: 0, msg: 'ok' }); + const wrapper = mount(Reset, { + mocks: { + $route: ['/auth/reset/1', '1'] + } + }); + const button = wrapper.find('button'); + const info = wrapper.find('.callout-info'); + const warning = wrapper.find('.callout-warning'); + + button.trigger('click'); + expect(Vue.prototype.$http.post).not.toBeCalled(); + expect(info.text()).toBe('auth.emptyPassword'); + + wrapper.findAll('[type="password"]').at(0).setValue('123456'); + button.trigger('click'); + expect(Vue.prototype.$http.post).not.toBeCalled(); + expect(info.text()).toBe('auth.invalidPassword'); + + wrapper.findAll('[type="password"]').at(0).setValue('12345678'); + button.trigger('click'); + expect(Vue.prototype.$http.post).not.toBeCalled(); + expect(info.text()).toBe('auth.invalidConfirmPwd'); + + wrapper.findAll('[type="password"]').at(1).setValue('123456'); + button.trigger('click'); + expect(Vue.prototype.$http.post).not.toBeCalled(); + expect(info.text()).toBe('auth.invalidConfirmPwd'); + + wrapper.findAll('[type="password"]').at(1).setValue('12345678'); + button.trigger('click'); + expect(Vue.prototype.$http.post).toBeCalledWith( + '/auth/reset/1', // Ignore `location.search` + { password: '12345678' } + ); + await wrapper.vm.$nextTick(); + expect(warning.text()).toBe('fail'); + + button.trigger('click'); + await wrapper.vm.$nextTick(); + expect(swal).toBeCalledWith({ type: 'success', html: 'ok' }); +}); diff --git a/resources/lang/en/front-end.yml b/resources/lang/en/front-end.yml index 674434f7..4d1ddfb3 100644 --- a/resources/lang/en/front-end.yml +++ b/resources/lang/en/front-end.yml @@ -32,6 +32,7 @@ auth: forgot: login-link: I do remember it button: Send + reset-button: Reset skinlib: addToCloset: Add to closet diff --git a/resources/lang/zh_CN/front-end.yml b/resources/lang/zh_CN/front-end.yml index 963cadf2..178554d0 100644 --- a/resources/lang/zh_CN/front-end.yml +++ b/resources/lang/zh_CN/front-end.yml @@ -32,6 +32,7 @@ auth: forgot: login-link: 我又想起来了 button: 发送 + reset-button: 重置 skinlib: addToCloset: 添加至衣柜 diff --git a/resources/views/auth/reset.tpl b/resources/views/auth/reset.tpl index e0bdb145..07f20d0e 100644 --- a/resources/views/auth/reset.tpl +++ b/resources/views/auth/reset.tpl @@ -12,30 +12,7 @@

@lang('auth.reset.message', ['username' => $user->getNickName()])

-
- - -
- - -
-
- - -
- -
- -
-
-
- -
- -
- -
-
+