mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
import Vue from 'vue';
|
|
import { mount } from '@vue/test-utils';
|
|
import Forgot from '@/components/auth/Forgot';
|
|
|
|
test('click to refresh captcha', () => {
|
|
jest.spyOn(Date, 'now');
|
|
const wrapper = mount(Forgot);
|
|
wrapper.find('img').trigger('click');
|
|
expect(Date.now).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
test('submit forgot form', async () => {
|
|
jest.spyOn(Date, 'now');
|
|
Vue.prototype.$http.post
|
|
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
|
|
.mockResolvedValueOnce({ errno: 0, msg: 'ok' });
|
|
const wrapper = mount(Forgot);
|
|
const button = wrapper.find('button');
|
|
const info = wrapper.find('.callout-info');
|
|
const warning = wrapper.find('.callout-warning');
|
|
const success = wrapper.find('.callout-success');
|
|
|
|
button.trigger('click');
|
|
expect(Vue.prototype.$http.post).not.toBeCalled();
|
|
expect(info.text()).toBe('auth.emptyEmail');
|
|
|
|
wrapper.find('[type="email"]').setValue('a');
|
|
button.trigger('click');
|
|
expect(Vue.prototype.$http.post).not.toBeCalled();
|
|
expect(info.text()).toBe('auth.invalidEmail');
|
|
|
|
wrapper.find('[type="email"]').setValue('a@b.c');
|
|
button.trigger('click');
|
|
expect(Vue.prototype.$http.post).not.toBeCalled();
|
|
expect(info.text()).toBe('auth.emptyCaptcha');
|
|
|
|
wrapper.find('[type="text"]').setValue('captcha');
|
|
button.trigger('click');
|
|
await wrapper.vm.$nextTick();
|
|
expect(Vue.prototype.$http.post).toBeCalledWith(
|
|
'/auth/forgot',
|
|
{ email: 'a@b.c', captcha: 'captcha' }
|
|
);
|
|
expect(warning.text()).toBe('fail');
|
|
expect(Date.now).toHaveBeenCalledTimes(2);
|
|
|
|
button.trigger('click');
|
|
await wrapper.vm.$nextTick();
|
|
expect(success.text()).toBe('ok');
|
|
});
|