Skip to content
代码片段 群组 项目
提交 bfed3d07 编辑于 作者: Lee Tickett's avatar Lee Tickett 提交者: Phil Hughes
浏览文件

Fix task list updates for different issue types

Changelog: fixed
上级 eaefcb8e
No related branches found
No related tags found
无相关合并请求
...@@ -2,6 +2,7 @@ import $ from 'jquery'; ...@@ -2,6 +2,7 @@ import $ from 'jquery';
import 'deckar01-task_list'; import 'deckar01-task_list';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { createAlert } from '~/alert'; import { createAlert } from '~/alert';
import { TYPE_INCIDENT, TYPE_ISSUE } from '~/issues/constants';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
export default class TaskList { export default class TaskList {
...@@ -94,7 +95,8 @@ export default class TaskList { ...@@ -94,7 +95,8 @@ export default class TaskList {
const { index, checked, lineNumber, lineSource } = e.detail; const { index, checked, lineNumber, lineSource } = e.detail;
const patchData = {}; const patchData = {};
patchData[this.dataType] = { const dataType = this.dataType === TYPE_INCIDENT ? TYPE_ISSUE : this.dataType;
patchData[dataType] = {
[this.fieldName]: $target.val(), [this.fieldName]: $target.val(),
lock_version: this.lockVersion, lock_version: this.lockVersion,
update_task: { update_task: {
......
...@@ -126,14 +126,19 @@ describe('TaskList', () => { ...@@ -126,14 +126,19 @@ describe('TaskList', () => {
}); });
describe('update', () => { describe('update', () => {
it('should disable task list items and make a patch request then enable them again', () => { const setupTaskListAndMocks = (options) => {
const response = { data: { lock_version: 3 } }; taskList = new TaskList(options);
jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {}); jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {});
jest.spyOn(taskList, 'disableTaskListItems').mockImplementation(() => {}); jest.spyOn(taskList, 'disableTaskListItems').mockImplementation(() => {});
jest.spyOn(taskList, 'onUpdate').mockImplementation(() => {}); jest.spyOn(taskList, 'onUpdate').mockImplementation(() => {});
jest.spyOn(taskList, 'onSuccess').mockImplementation(() => {}); jest.spyOn(taskList, 'onSuccess').mockImplementation(() => {});
jest.spyOn(axios, 'patch').mockReturnValue(Promise.resolve(response)); jest.spyOn(axios, 'patch').mockResolvedValue({ data: { lock_version: 3 } });
return taskList;
};
const performTest = (options) => {
const value = 'hello world'; const value = 'hello world';
const endpoint = '/foo'; const endpoint = '/foo';
const target = $(`<input data-update-url="${endpoint}" value="${value}" />`); const target = $(`<input data-update-url="${endpoint}" value="${value}" />`);
...@@ -144,10 +149,11 @@ describe('TaskList', () => { ...@@ -144,10 +149,11 @@ describe('TaskList', () => {
lineSource: '- [ ] check item', lineSource: '- [ ] check item',
}; };
const event = { target, detail }; const event = { target, detail };
const dataType = options.dataType === 'incident' ? 'issue' : options.dataType;
const patchData = { const patchData = {
[taskListOptions.dataType]: { [dataType]: {
[taskListOptions.fieldName]: value, [options.fieldName]: value,
lock_version: taskListOptions.lockVersion, lock_version: options.lockVersion,
update_task: { update_task: {
index: detail.index, index: detail.index,
checked: detail.checked, checked: detail.checked,
...@@ -165,8 +171,42 @@ describe('TaskList', () => { ...@@ -165,8 +171,42 @@ describe('TaskList', () => {
expect(taskList.disableTaskListItems).toHaveBeenCalledWith(event); expect(taskList.disableTaskListItems).toHaveBeenCalledWith(event);
expect(axios.patch).toHaveBeenCalledWith(endpoint, patchData); expect(axios.patch).toHaveBeenCalledWith(endpoint, patchData);
expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event); expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event);
expect(taskList.onSuccess).toHaveBeenCalledWith(response.data); expect(taskList.onSuccess).toHaveBeenCalledWith({ lock_version: 3 });
expect(taskList.lockVersion).toEqual(response.data.lock_version); expect(taskList.lockVersion).toEqual(3);
});
};
it('should disable task list items and make a patch request then enable them again', () => {
taskList = setupTaskListAndMocks(taskListOptions);
return performTest(taskListOptions);
});
describe('for merge requests', () => {
it('should wrap the patch request payload in merge_request', () => {
const options = {
selector: '.task-list',
dataType: 'merge_request',
fieldName: 'description',
lockVersion: 2,
};
taskList = setupTaskListAndMocks(options);
return performTest(options);
});
});
describe('for incidents', () => {
it('should wrap the patch request payload in issue', () => {
const options = {
selector: '.task-list',
dataType: 'incident',
fieldName: 'description',
lockVersion: 2,
};
taskList = setupTaskListAndMocks(options);
return performTest(options);
}); });
}); });
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册