From 6243c04e20b480c8353ac820ac4eb7ea43b92718 Mon Sep 17 00:00:00 2001
From: Fatih Acet <acetfatih@gmail.com>
Date: Tue, 22 Jan 2019 21:53:08 +0100
Subject: [PATCH] Fix failing specs and lint errors.

---
 .../javascripts/issue_show/components/app.vue |  8 +++++++-
 .../issue_show/components/description.vue     |  7 +++++--
 app/assets/javascripts/task_list.js           | 20 ++++++++++---------
 .../issue_show/components/description_spec.js |  3 +++
 spec/javascripts/merge_request_spec.js        | 17 ++++++++++++++--
 spec/javascripts/notes_spec.js                | 19 ++++++++++++++++--
 6 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/app/assets/javascripts/issue_show/components/app.vue b/app/assets/javascripts/issue_show/components/app.vue
index 0428e099279..72398cb547a 100644
--- a/app/assets/javascripts/issue_show/components/app.vue
+++ b/app/assets/javascripts/issue_show/components/app.vue
@@ -214,10 +214,16 @@ export default {
     },
 
     updateStoreState() {
-      this.service.getData()
+      this.service
+        .getData()
         .then(res => res.data)
         .then(data => {
           this.store.updateState(data);
+        })
+        .catch(() => {
+          const errMsg = `Error updating ${this.issuableType}`;
+
+          window.Flash(errMsg);
         });
     },
 
diff --git a/app/assets/javascripts/issue_show/components/description.vue b/app/assets/javascripts/issue_show/components/description.vue
index 519012b7df9..56e873c6ba0 100644
--- a/app/assets/javascripts/issue_show/components/description.vue
+++ b/app/assets/javascripts/issue_show/components/description.vue
@@ -39,6 +39,7 @@ export default {
     lockVersion: {
       type: Number,
       required: false,
+      default: 0,
     },
   },
   data() {
@@ -89,8 +90,10 @@ export default {
       }
     },
 
-    taskListUpdateError({ errors, data }) {
-      createFlash('Someone edited this issue at the same time you did and we updated the issue description.');
+    taskListUpdateError() {
+      createFlash(
+        'Someone edited this issue at the same time you did and we updated the issue description.',
+      );
 
       this.$emit('taskListUpdateFailed');
     },
diff --git a/app/assets/javascripts/task_list.js b/app/assets/javascripts/task_list.js
index 08100d1d542..9ea6cba7281 100644
--- a/app/assets/javascripts/task_list.js
+++ b/app/assets/javascripts/task_list.js
@@ -10,15 +10,17 @@ export default class TaskList {
     this.fieldName = options.fieldName;
     this.lockVersion = options.lockVersion;
     this.onSuccess = options.onSuccess || (() => {});
-    this.onError = options.onError || function showFlash(e) {
-      let errorMessages = '';
+    this.onError =
+      options.onError ||
+      function showFlash(e) {
+        let errorMessages = '';
 
-      if (e.response.data && typeof e.response.data === 'object') {
-        errorMessages = e.response.data.errors.join(' ');
-      }
+        if (e.response.data && typeof e.response.data === 'object') {
+          errorMessages = e.response.data.errors.join(' ');
+        }
 
-      return new Flash(errorMessages || 'Update failed', 'alert');
-    };
+        return new Flash(errorMessages || 'Update failed', 'alert');
+      };
 
     this.init();
   }
@@ -56,8 +58,8 @@ export default class TaskList {
       [this.fieldName]: $target.val(),
       lock_version: this.lockVersion,
       update_task: {
-        index: index,
-        checked: checked,
+        index,
+        checked,
         line_number: lineNumber,
         line_source: lineSource,
       },
diff --git a/spec/javascripts/issue_show/components/description_spec.js b/spec/javascripts/issue_show/components/description_spec.js
index 463f3c89926..52148f4c66b 100644
--- a/spec/javascripts/issue_show/components/description_spec.js
+++ b/spec/javascripts/issue_show/components/description_spec.js
@@ -123,7 +123,10 @@ describe('Description component', () => {
           fieldName: 'description',
           selector: '.detail-page-description',
           onSuccess: jasmine.any(Function),
+          onError: jasmine.any(Function),
+          lockVersion: 0,
         });
+
         done();
       });
     });
diff --git a/spec/javascripts/merge_request_spec.js b/spec/javascripts/merge_request_spec.js
index 1cb49b49ca7..32623d1781a 100644
--- a/spec/javascripts/merge_request_spec.js
+++ b/spec/javascripts/merge_request_spec.js
@@ -41,15 +41,28 @@ describe('MergeRequest', function() {
     });
 
     it('submits an ajax request on tasklist:changed', done => {
-      $('.js-task-list-field').trigger('tasklist:changed');
+      const lineNumber = 8;
+      const lineSource = '- [ ] item 8';
+      const index = 3;
+      const checked = true;
+
+      $('.js-task-list-field').trigger({
+        type: 'tasklist:changed',
+        detail: { lineNumber, lineSource, index, checked },
+      });
 
       setTimeout(() => {
         expect(axios.patch).toHaveBeenCalledWith(
           `${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`,
           {
-            merge_request: { description: '- [ ] Task List Item' },
+            merge_request: {
+              description: '- [ ] Task List Item',
+              lock_version: undefined,
+              update_task: { line_number: lineNumber, line_source: lineSource, index, checked },
+            },
           },
         );
+
         done();
       });
     });
diff --git a/spec/javascripts/notes_spec.js b/spec/javascripts/notes_spec.js
index 694f581150f..7c869d4c326 100644
--- a/spec/javascripts/notes_spec.js
+++ b/spec/javascripts/notes_spec.js
@@ -89,10 +89,25 @@ describe('Notes', function() {
     });
 
     it('submits an ajax request on tasklist:changed', function(done) {
-      $('.js-task-list-container').trigger('tasklist:changed');
+      const lineNumber = 8;
+      const lineSource = '- [ ] item 8';
+      const index = 3;
+      const checked = true;
+
+      $('.js-task-list-container').trigger({
+        type: 'tasklist:changed',
+        detail: { lineNumber, lineSource, index, checked },
+      });
 
       setTimeout(() => {
-        expect(axios.patch).toHaveBeenCalled();
+        expect(axios.patch).toHaveBeenCalledWith(undefined, {
+          note: {
+            note: '',
+            lock_version: undefined,
+            update_task: { index, checked, line_number: lineNumber, line_source: lineSource },
+          },
+        });
+
         done();
       });
     });
-- 
2.30.9