2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2020-01-01 13:55:28 +05:30
|
|
|
import deleteAccountModal from '~/profile/account/components/delete_account_modal.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('DeleteAccountModal component', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const actionUrl = `${TEST_HOST}/delete/user`;
|
2018-03-17 18:26:18 +05:30
|
|
|
const username = 'hasnoname';
|
|
|
|
let Component;
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Component = Vue.extend(deleteAccountModal);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
const findElements = () => {
|
|
|
|
const confirmation = vm.confirmWithPassword ? 'password' : 'username';
|
|
|
|
return {
|
|
|
|
form: vm.$refs.form,
|
|
|
|
input: vm.$el.querySelector(`[name="${confirmation}"]`),
|
|
|
|
submitButton: vm.$el.querySelector('.btn-danger'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('with password confirmation', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm = mountComponent(Component, {
|
|
|
|
actionUrl,
|
|
|
|
confirmWithPassword: true,
|
|
|
|
username,
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.isOpen = true;
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('does not accept empty password', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const { form, input, submitButton } = findElements();
|
2020-04-22 19:07:51 +05:30
|
|
|
jest.spyOn(form, 'submit').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
input.value = '';
|
|
|
|
input.dispatchEvent(new Event('input'));
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.enteredPassword).toBe(input.value);
|
|
|
|
expect(submitButton).toHaveAttr('disabled', 'disabled');
|
|
|
|
submitButton.click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(form.submit).not.toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('submits form with password', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const { form, input, submitButton } = findElements();
|
2020-04-22 19:07:51 +05:30
|
|
|
jest.spyOn(form, 'submit').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
input.value = 'anything';
|
|
|
|
input.dispatchEvent(new Event('input'));
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.enteredPassword).toBe(input.value);
|
|
|
|
expect(submitButton).not.toHaveAttr('disabled', 'disabled');
|
|
|
|
submitButton.click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(form.submit).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with username confirmation', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm = mountComponent(Component, {
|
|
|
|
actionUrl,
|
|
|
|
confirmWithPassword: false,
|
|
|
|
username,
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.isOpen = true;
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('does not accept wrong username', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const { form, input, submitButton } = findElements();
|
2020-04-22 19:07:51 +05:30
|
|
|
jest.spyOn(form, 'submit').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
input.value = 'this is wrong';
|
|
|
|
input.dispatchEvent(new Event('input'));
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.enteredUsername).toBe(input.value);
|
|
|
|
expect(submitButton).toHaveAttr('disabled', 'disabled');
|
|
|
|
submitButton.click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(form.submit).not.toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('submits form with correct username', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const { form, input, submitButton } = findElements();
|
2020-04-22 19:07:51 +05:30
|
|
|
jest.spyOn(form, 'submit').mockImplementation(() => {});
|
2018-03-17 18:26:18 +05:30
|
|
|
input.value = username;
|
|
|
|
input.dispatchEvent(new Event('input'));
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.enteredUsername).toBe(input.value);
|
|
|
|
expect(submitButton).not.toHaveAttr('disabled', 'disabled');
|
|
|
|
submitButton.click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(form.submit).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|