2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-05-10 10:05:58 -04:00
|
|
|
import Vue from 'vue';
|
2019-08-21 04:06:50 -04:00
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2020-05-06 11:09:42 -04:00
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2019-12-10 04:07:51 -05:00
|
|
|
import Description from '~/issue_show/components/description.vue';
|
2020-05-06 11:09:42 -04:00
|
|
|
import TaskList from '~/task_list';
|
2021-05-19 17:12:42 -04:00
|
|
|
import { descriptionProps as props } from '../mock_data/mock_data';
|
2020-05-06 11:09:42 -04:00
|
|
|
|
|
|
|
jest.mock('~/task_list');
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
describe('Description component', () => {
|
|
|
|
let vm;
|
2017-11-29 04:29:06 -05:00
|
|
|
let DescriptionComponent;
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-04-16 14:40:30 -04:00
|
|
|
DescriptionComponent = Vue.extend(Description);
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
if (!document.querySelector('.issuable-meta')) {
|
|
|
|
const metaData = document.createElement('div');
|
|
|
|
metaData.classList.add('issuable-meta');
|
2019-02-06 18:18:07 -05:00
|
|
|
metaData.innerHTML =
|
|
|
|
'<div class="flash-container"></div><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
|
|
|
});
|
|
|
|
|
2019-02-06 18:18:07 -05:00
|
|
|
afterAll(() => {
|
|
|
|
$('.issuable-meta .flash-container').remove();
|
|
|
|
});
|
|
|
|
|
2020-09-02 08:10:35 -04:00
|
|
|
it('doesnt animate first description changes', () => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-09-02 08:10:35 -04:00
|
|
|
return vm.$nextTick().then(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.md').classList.contains('issue-realtime-pre-pulse'),
|
|
|
|
).toBeFalsy();
|
|
|
|
jest.runAllTimers();
|
|
|
|
return vm.$nextTick();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('animates description changes on live update', () => {
|
|
|
|
vm.descriptionHtml = 'changed';
|
2020-05-06 11:09:42 -04:00
|
|
|
return vm
|
|
|
|
.$nextTick()
|
2020-09-02 08:10:35 -04:00
|
|
|
.then(() => {
|
|
|
|
vm.descriptionHtml = 'changed second time';
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
2020-05-06 11:09:42 -04:00
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.md').classList.contains('issue-realtime-pre-pulse'),
|
|
|
|
).toBeTruthy();
|
|
|
|
jest.runAllTimers();
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2017-05-10 10:05:58 -04:00
|
|
|
expect(
|
2019-03-23 09:09:14 -04:00
|
|
|
vm.$el.querySelector('.md').classList.contains('issue-realtime-trigger-pulse'),
|
2017-05-10 10:05:58 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
it('applies syntax highlighting and math when description changed', () => {
|
|
|
|
const vmSpy = jest.spyOn(vm, 'renderGFM');
|
|
|
|
const prototypeSpy = jest.spyOn($.prototype, 'renderGFM');
|
|
|
|
vm.descriptionHtml = 'changed';
|
2018-04-16 14:40:30 -04:00
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
return vm.$nextTick().then(() => {
|
|
|
|
expect(vm.$refs['gfm-content']).toBeDefined();
|
|
|
|
expect(vmSpy).toHaveBeenCalled();
|
|
|
|
expect(prototypeSpy).toHaveBeenCalled();
|
|
|
|
expect($.prototype.renderGFM).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets data-update-url', () => {
|
|
|
|
expect(vm.$el.querySelector('textarea').dataset.updateUrl).toEqual(TEST_HOST);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TaskList', () => {
|
2017-11-29 04:29:06 -05:00
|
|
|
beforeEach(() => {
|
2019-08-21 04:06:50 -04:00
|
|
|
vm.$destroy();
|
2020-05-06 11:09:42 -04:00
|
|
|
TaskList.mockClear();
|
2020-05-07 17:09:26 -04:00
|
|
|
vm = mountComponent(DescriptionComponent, { ...props, issuableType: 'issuableType' });
|
2017-11-29 04:29:06 -05:00
|
|
|
});
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
it('re-inits the TaskList when description changed', () => {
|
2017-11-29 04:29:06 -05:00
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
expect(TaskList).toHaveBeenCalled();
|
2017-11-29 04:29:06 -05:00
|
|
|
});
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
it('does not re-init the TaskList when canUpdate is false', () => {
|
2017-11-29 04:29:06 -05:00
|
|
|
vm.canUpdate = false;
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
expect(TaskList).toHaveBeenCalledTimes(1);
|
2017-11-29 04:29:06 -05:00
|
|
|
});
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
it('calls with issuableType dataType', () => {
|
2017-11-29 04:29:06 -05:00
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
expect(TaskList).toHaveBeenCalledWith({
|
|
|
|
dataType: 'issuableType',
|
|
|
|
fieldName: 'description',
|
|
|
|
selector: '.detail-page-description',
|
|
|
|
onError: expect.any(Function),
|
|
|
|
lockVersion: 0,
|
2017-11-29 04:29:06 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
describe('taskStatus', () => {
|
2020-05-06 11:09:42 -04:00
|
|
|
it('adds full taskStatus', () => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
return vm.$nextTick().then(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.issuable-meta #task_status').textContent.trim()).toBe(
|
|
|
|
'1 of 1',
|
|
|
|
);
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
it('adds short taskStatus', () => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
return vm.$nextTick().then(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.issuable-meta #task_status_short').textContent.trim()).toBe(
|
|
|
|
'1/1 task',
|
|
|
|
);
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
|
|
|
});
|
2017-06-20 05:56:18 -04:00
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
it('clears task status text when no tasks are present', () => {
|
2017-06-20 05:56:18 -04:00
|
|
|
vm.taskStatus = '0 of 0';
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
return vm.$nextTick().then(() => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.issuable-meta #task_status').textContent.trim()).toBe('');
|
2017-06-20 05:56:18 -04:00
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
2017-06-19 16:29:46 -04:00
|
|
|
|
2019-01-26 09:49:49 -05:00
|
|
|
describe('taskListUpdateError', () => {
|
|
|
|
it('should create flash notification and emit an event to parent', () => {
|
|
|
|
const msg =
|
2019-01-28 19:36:31 -05:00
|
|
|
'Someone edited this issue at the same time you did. The description has been updated and you will need to make your changes again.';
|
2020-05-06 11:09:42 -04:00
|
|
|
const spy = jest.spyOn(vm, '$emit');
|
2019-01-26 09:49:49 -05:00
|
|
|
|
|
|
|
vm.taskListUpdateError();
|
|
|
|
|
2019-02-06 18:18:07 -05:00
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(msg);
|
2020-05-06 11:09:42 -04:00
|
|
|
expect(spy).toHaveBeenCalledWith('taskListUpdateFailed');
|
2019-01-26 09:49:49 -05:00
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|