2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2017-09-10 17:25:29 +05:30
|
|
|
import Vue from 'vue';
|
2019-12-04 20:38:33 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2022-01-26 12:08:38 +05:30
|
|
|
import Description from '~/issues/show/components/description.vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import TaskList from '~/task_list';
|
2021-09-04 01:27:46 +05:30
|
|
|
import { descriptionProps as props } from '../mock_data/mock_data';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
jest.mock('~/task_list');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('Description component', () => {
|
|
|
|
let vm;
|
2018-03-17 18:26:18 +05:30
|
|
|
let DescriptionComponent;
|
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();
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('doesnt animate first description changes', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
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-24 23:13:21 +05:30
|
|
|
return vm
|
|
|
|
.$nextTick()
|
2020-11-24 15:15:51 +05:30
|
|
|
.then(() => {
|
|
|
|
vm.descriptionHtml = 'changed second time';
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
2020-05-24 23:13:21 +05:30
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.md').classList.contains('issue-realtime-pre-pulse'),
|
|
|
|
).toBeTruthy();
|
|
|
|
jest.runAllTimers();
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2017-09-10 17:25:29 +05:30
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
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-10-15 14:42:47 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
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', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
beforeEach(() => {
|
2019-12-04 20:38:33 +05:30
|
|
|
vm.$destroy();
|
2020-05-24 23:13:21 +05:30
|
|
|
TaskList.mockClear();
|
|
|
|
vm = mountComponent(DescriptionComponent, { ...props, issuableType: 'issuableType' });
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('re-inits the TaskList when description changed', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(TaskList).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('does not re-init the TaskList when canUpdate is false', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.canUpdate = false;
|
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(TaskList).toHaveBeenCalledTimes(1);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('calls with issuableType dataType', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.descriptionHtml = 'changed';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(TaskList).toHaveBeenCalledWith({
|
|
|
|
dataType: 'issuableType',
|
|
|
|
fieldName: 'description',
|
|
|
|
selector: '.detail-page-description',
|
2021-12-11 22:18:48 +05:30
|
|
|
onUpdate: expect.any(Function),
|
|
|
|
onSuccess: expect.any(Function),
|
2020-05-24 23:13:21 +05:30
|
|
|
onError: expect.any(Function),
|
|
|
|
lockVersion: 0,
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('taskStatus', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('adds full taskStatus', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('adds short taskStatus', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.taskStatus = '1 of 1';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('clears task status text when no tasks are present', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.taskStatus = '0 of 0';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return vm.$nextTick().then(() => {
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('taskListUpdateStarted', () => {
|
|
|
|
it('emits event to parent', () => {
|
|
|
|
const spy = jest.spyOn(vm, '$emit');
|
|
|
|
|
|
|
|
vm.taskListUpdateStarted();
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('taskListUpdateStarted');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('taskListUpdateSuccess', () => {
|
|
|
|
it('emits event to parent', () => {
|
|
|
|
const spy = jest.spyOn(vm, '$emit');
|
|
|
|
|
|
|
|
vm.taskListUpdateSuccess();
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('taskListUpdateSucceeded');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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.';
|
2020-05-24 23:13:21 +05:30
|
|
|
const spy = jest.spyOn(vm, '$emit');
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
vm.taskListUpdateError();
|
|
|
|
|
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(msg);
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(spy).toHaveBeenCalledWith('taskListUpdateFailed');
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|