Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/task_list_spec.js')
-rw-r--r--spec/frontend/task_list_spec.js56
1 files changed, 48 insertions, 8 deletions
diff --git a/spec/frontend/task_list_spec.js b/spec/frontend/task_list_spec.js
index e79c516a694..605ae028049 100644
--- a/spec/frontend/task_list_spec.js
+++ b/spec/frontend/task_list_spec.js
@@ -126,14 +126,19 @@ describe('TaskList', () => {
});
describe('update', () => {
- it('should disable task list items and make a patch request then enable them again', () => {
- const response = { data: { lock_version: 3 } };
+ const setupTaskListAndMocks = (options) => {
+ taskList = new TaskList(options);
+
jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {});
jest.spyOn(taskList, 'disableTaskListItems').mockImplementation(() => {});
jest.spyOn(taskList, 'onUpdate').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 endpoint = '/foo';
const target = $(`<input data-update-url="${endpoint}" value="${value}" />`);
@@ -144,10 +149,11 @@ describe('TaskList', () => {
lineSource: '- [ ] check item',
};
const event = { target, detail };
+ const dataType = options.dataType === 'incident' ? 'issue' : options.dataType;
const patchData = {
- [taskListOptions.dataType]: {
- [taskListOptions.fieldName]: value,
- lock_version: taskListOptions.lockVersion,
+ [dataType]: {
+ [options.fieldName]: value,
+ lock_version: options.lockVersion,
update_task: {
index: detail.index,
checked: detail.checked,
@@ -165,8 +171,42 @@ describe('TaskList', () => {
expect(taskList.disableTaskListItems).toHaveBeenCalledWith(event);
expect(axios.patch).toHaveBeenCalledWith(endpoint, patchData);
expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event);
- expect(taskList.onSuccess).toHaveBeenCalledWith(response.data);
- expect(taskList.lockVersion).toEqual(response.data.lock_version);
+ expect(taskList.onSuccess).toHaveBeenCalledWith({ lock_version: 3 });
+ 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);
});
});
});