2017-05-10 10:05:58 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import descriptionComponent from '~/issue_show/components/description.vue';
|
2017-11-29 04:29:06 -05:00
|
|
|
import * as taskList from '~/task_list';
|
|
|
|
import mountComponent from '../../helpers/vue_mount_component_helper';
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
describe('Description component', () => {
|
|
|
|
let vm;
|
2017-11-29 04:29:06 -05:00
|
|
|
let DescriptionComponent;
|
|
|
|
const props = {
|
|
|
|
canUpdate: true,
|
|
|
|
descriptionHtml: 'test',
|
|
|
|
descriptionText: 'test',
|
|
|
|
updatedAt: new Date().toString(),
|
|
|
|
taskStatus: '',
|
|
|
|
updateUrl: gl.TEST_HOST,
|
|
|
|
};
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-11-29 04:29:06 -05:00
|
|
|
DescriptionComponent = Vue.extend(descriptionComponent);
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
if (!document.querySelector('.issuable-meta')) {
|
|
|
|
const metaData = document.createElement('div');
|
|
|
|
metaData.classList.add('issuable-meta');
|
2017-05-11 09:34:56 -04:00
|
|
|
metaData.innerHTML = '<span id="task_status"></span><span id="task_status_short"></span>';
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
document.body.appendChild(metaData);
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:29:06 -05:00
|
|
|
vm = mountComponent(DescriptionComponent, props);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('animates description changes', (done) => {
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.wiki').classList.contains('issue-realtime-pre-pulse'),
|
|
|
|
).toBeTruthy();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.wiki').classList.contains('issue-realtime-trigger-pulse'),
|
|
|
|
).toBeTruthy();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-08 07:26:39 -05:00
|
|
|
it('opens recaptcha dialog if update rejected as spam', (done) => {
|
|
|
|
let modal;
|
|
|
|
const recaptchaChild = vm.$children
|
2017-12-11 14:06:07 -05:00
|
|
|
.find(child => child.$options._componentTag === 'recaptcha-modal'); // eslint-disable-line no-underscore-dangle
|
2017-12-08 07:26:39 -05:00
|
|
|
|
|
|
|
recaptchaChild.scriptSrc = '//scriptsrc';
|
|
|
|
|
|
|
|
vm.taskListUpdateSuccess({
|
|
|
|
recaptcha_html: '<div class="g-recaptcha">recaptcha_html</div>',
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
2017-12-11 14:06:07 -05:00
|
|
|
modal = vm.$el.querySelector('.js-recaptcha-modal');
|
2017-12-08 07:26:39 -05:00
|
|
|
|
|
|
|
expect(modal.style.display).not.toEqual('none');
|
|
|
|
expect(modal.querySelector('.g-recaptcha').textContent).toEqual('recaptcha_html');
|
|
|
|
expect(document.body.querySelector('.js-recaptcha-script').src).toMatch('//scriptsrc');
|
|
|
|
})
|
|
|
|
.then(() => modal.querySelector('.close').click())
|
|
|
|
.then(() => vm.$nextTick())
|
|
|
|
.then(() => {
|
|
|
|
expect(modal.style.display).toEqual('none');
|
|
|
|
expect(document.body.querySelector('.js-recaptcha-script')).toBeNull();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2017-11-29 04:29:06 -05:00
|
|
|
describe('TaskList', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(DescriptionComponent, Object.assign({}, props, {
|
|
|
|
issuableType: 'issuableType',
|
|
|
|
}));
|
|
|
|
spyOn(taskList, 'default');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('re-inits the TaskList when description changed', (done) => {
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(taskList.default).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not re-init the TaskList when canUpdate is false', (done) => {
|
|
|
|
vm.canUpdate = false;
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(taskList.default).not.toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls with issuableType dataType', (done) => {
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(taskList.default).toHaveBeenCalledWith({
|
|
|
|
dataType: 'issuableType',
|
|
|
|
fieldName: 'description',
|
|
|
|
selector: '.detail-page-description',
|
2017-12-08 07:26:39 -05:00
|
|
|
onSuccess: jasmine.any(Function),
|
2017-11-29 04:29:06 -05:00
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
describe('taskStatus', () => {
|
|
|
|
it('adds full taskStatus', (done) => {
|
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.issuable-meta #task_status').textContent.trim(),
|
|
|
|
).toBe('1 of 1');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds short taskStatus', (done) => {
|
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.issuable-meta #task_status_short').textContent.trim(),
|
|
|
|
).toBe('1/1 task');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-06-20 05:56:18 -04:00
|
|
|
|
|
|
|
it('clears task status text when no tasks are present', (done) => {
|
|
|
|
vm.taskStatus = '0 of 0';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.issuable-meta #task_status').textContent.trim(),
|
|
|
|
).toBe('');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
2017-06-19 16:29:46 -04:00
|
|
|
|
|
|
|
it('applies syntax highlighting and math when description changed', (done) => {
|
|
|
|
spyOn(vm, 'renderGFM').and.callThrough();
|
|
|
|
spyOn($.prototype, 'renderGFM').and.callThrough();
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.$refs['gfm-content']).toBeDefined();
|
|
|
|
expect(vm.renderGFM).toHaveBeenCalled();
|
|
|
|
expect($.prototype.renderGFM).toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-11-29 04:29:06 -05:00
|
|
|
|
|
|
|
it('sets data-update-url', () => {
|
|
|
|
expect(vm.$el.querySelector('textarea').dataset.updateUrl).toEqual(gl.TEST_HOST);
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|