2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2017-09-10 17:25:29 +05:30
|
|
|
import Vue from 'vue';
|
2018-10-15 14:42:47 +05:30
|
|
|
import Description from '~/issue_show/components/description.vue';
|
2018-03-27 19:54:05 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('Description component', () => {
|
|
|
|
let vm;
|
2018-03-17 18:26:18 +05:30
|
|
|
let DescriptionComponent;
|
|
|
|
const props = {
|
|
|
|
canUpdate: true,
|
|
|
|
descriptionHtml: 'test',
|
|
|
|
descriptionText: 'test',
|
|
|
|
updatedAt: new Date().toString(),
|
|
|
|
taskStatus: '',
|
|
|
|
updateUrl: gl.TEST_HOST,
|
|
|
|
};
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
DescriptionComponent = Vue.extend(Description);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
if (!document.querySelector('.issuable-meta')) {
|
|
|
|
const metaData = document.createElement('div');
|
|
|
|
metaData.classList.add('issuable-meta');
|
2019-03-02 22:35:43 +05:30
|
|
|
metaData.innerHTML =
|
|
|
|
'<div class="flash-container"></div><span id="task_status"></span><span id="task_status_short"></span>';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
document.body.appendChild(metaData);
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
vm = mountComponent(DescriptionComponent, props);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
afterAll(() => {
|
|
|
|
$('.issuable-meta .flash-container').remove();
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('animates description changes', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
2019-07-07 11:18:12 +05:30
|
|
|
vm.$el.querySelector('.md').classList.contains('issue-realtime-pre-pulse'),
|
2017-09-10 17:25:29 +05:30
|
|
|
).toBeTruthy();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
2019-07-07 11:18:12 +05:30
|
|
|
vm.$el.querySelector('.md').classList.contains('issue-realtime-trigger-pulse'),
|
2017-09-10 17:25:29 +05:30
|
|
|
).toBeTruthy();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('opens recaptcha dialog if update rejected as spam', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let modal;
|
2018-12-13 13:39:08 +05:30
|
|
|
const recaptchaChild = vm.$children.find(
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
child => child.$options._componentTag === 'recaptcha-modal',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
recaptchaChild.scriptSrc = '//scriptsrc';
|
|
|
|
|
|
|
|
vm.taskListUpdateSuccess({
|
|
|
|
recaptcha_html: '<div class="g-recaptcha">recaptcha_html</div>',
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
modal = vm.$el.querySelector('.js-recaptcha-modal');
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TaskList', () => {
|
2018-10-15 14:42:47 +05:30
|
|
|
let TaskList;
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
beforeEach(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
vm = mountComponent(
|
|
|
|
DescriptionComponent,
|
|
|
|
Object.assign({}, props, {
|
|
|
|
issuableType: 'issuableType',
|
|
|
|
}),
|
|
|
|
);
|
2018-10-15 14:42:47 +05:30
|
|
|
TaskList = spyOnDependency(Description, 'TaskList');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('re-inits the TaskList when description changed', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(TaskList).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('does not re-init the TaskList when canUpdate is false', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.canUpdate = false;
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(TaskList).not.toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('calls with issuableType dataType', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(TaskList).toHaveBeenCalledWith({
|
2018-03-17 18:26:18 +05:30
|
|
|
dataType: 'issuableType',
|
|
|
|
fieldName: 'description',
|
|
|
|
selector: '.detail-page-description',
|
|
|
|
onSuccess: jasmine.any(Function),
|
2019-03-02 22:35:43 +05:30
|
|
|
onError: jasmine.any(Function),
|
|
|
|
lockVersion: 0,
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('taskStatus', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('adds full taskStatus', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.issuable-meta #task_status').textContent.trim()).toBe(
|
|
|
|
'1 of 1',
|
|
|
|
);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('adds short taskStatus', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.issuable-meta #task_status_short').textContent.trim()).toBe(
|
|
|
|
'1/1 task',
|
|
|
|
);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('clears task status text when no tasks are present', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.taskStatus = '0 of 0';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.issuable-meta #task_status').textContent.trim()).toBe('');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('applies syntax highlighting and math when description changed', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it('sets data-update-url', () => {
|
|
|
|
expect(vm.$el.querySelector('textarea').dataset.updateUrl).toEqual(gl.TEST_HOST);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
describe('taskListUpdateError', () => {
|
|
|
|
it('should create flash notification and emit an event to parent', () => {
|
|
|
|
const msg =
|
|
|
|
'Someone edited this issue at the same time you did. The description has been updated and you will need to make your changes again.';
|
|
|
|
spyOn(vm, '$emit');
|
|
|
|
|
|
|
|
vm.taskListUpdateError();
|
|
|
|
|
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(msg);
|
|
|
|
expect(vm.$emit).toHaveBeenCalledWith('taskListUpdateFailed');
|
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|