From 6bf781e486fd9e86c37b365b0ea210a32b26ed4a Mon Sep 17 00:00:00 2001
From: Filipa Lacerda <filipa@gitlab.com>
Date: Mon, 14 Aug 2017 11:35:58 +0100
Subject: [PATCH] Fix autocomplete broken tests

---
 app/assets/javascripts/dispatcher.js               |  2 +-
 .../notes/components/issue_comment_form.vue        |  2 +-
 .../notes/components/issue_note_form.vue           |  2 +-
 app/views/projects/issues/_discussion.html.haml    |  3 +--
 spec/features/participants_autocomplete_spec.rb    | 14 +++++++++-----
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js
index 07f14b3ddb..54135f69b0 100644
--- a/app/assets/javascripts/dispatcher.js
+++ b/app/assets/javascripts/dispatcher.js
@@ -98,7 +98,7 @@ import initChangesDropdown from './init_changes_dropdown';
       path = page.split(':');
       shortcut_handler = null;
 
-      $('.js-gfm-input').each((i, el) => {
+      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
         const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
         const enableGFM = gl.utils.convertPermissionToBoolean(el.dataset.supportsAutocomplete);
         gfm.setup($(el), {
diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue
index 816db03230..9befba4e5e 100644
--- a/app/assets/javascripts/notes/components/issue_comment_form.vue
+++ b/app/assets/javascripts/notes/components/issue_comment_form.vue
@@ -240,7 +240,7 @@
                 <textarea
                   id="note-body"
                   name="note[note]"
-                  class="note-textarea js-vue-comment-form js-gfm-input js-autosize markdown-area"
+                  class="note-textarea js-vue-comment-form js-gfm-input js-autosize markdown-area js-vue-textarea"
                   data-supports-quick-actions="true"
                   aria-label="Description"
                   v-model="note"
diff --git a/app/assets/javascripts/notes/components/issue_note_form.vue b/app/assets/javascripts/notes/components/issue_note_form.vue
index 95ac4e9f38..1e5c142010 100644
--- a/app/assets/javascripts/notes/components/issue_note_form.vue
+++ b/app/assets/javascripts/notes/components/issue_note_form.vue
@@ -131,7 +131,7 @@
         <textarea
           id="note_note"
           name="note[note]"
-          class="note-textarea js-gfm-input js-autosize markdown-area js-vue-issue-note-form"
+          class="note-textarea js-gfm-input js-autosize markdown-area js-vue-issue-note-form js-vue-textarea"
           :data-supports-quick-actions="!isEditing"
           aria-label="Description"
           v-model="note"
diff --git a/app/views/projects/issues/_discussion.html.haml b/app/views/projects/issues/_discussion.html.haml
index 57391c3f14..f2992a7c68 100644
--- a/app/views/projects/issues/_discussion.html.haml
+++ b/app/views/projects/issues/_discussion.html.haml
@@ -1,3 +1,4 @@
+- @gfm_form = true
 - content_for :note_actions do
   - if can?(current_user, :update_issue, @issue)
     = link_to 'Reopen issue', issue_path(@issue, issue: {state_event: :reopen}, format: 'json'), data: {original_text: "Reopen issue", alternative_text: "Comment & reopen issue"}, class: "btn btn-nr btn-reopen btn-comment js-note-target-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen issue'
@@ -16,5 +17,3 @@
   - content_for :page_specific_javascripts do
     = webpack_bundle_tag 'common_vue'
     = webpack_bundle_tag 'notes'
-
-= render "layouts/init_auto_complete"
diff --git a/spec/features/participants_autocomplete_spec.rb b/spec/features/participants_autocomplete_spec.rb
index a22d548eef..96f6df587e 100644
--- a/spec/features/participants_autocomplete_spec.rb
+++ b/spec/features/participants_autocomplete_spec.rb
@@ -11,10 +11,14 @@ feature 'Member autocomplete', :js do
     sign_in(user)
   end
 
-  shared_examples "open suggestions when typing @" do
+  shared_examples "open suggestions when typing @" do |resource_name|
     before do
       page.within('.new-note') do
-        find('#note_note').send_keys('@')
+        if resource_name == 'issue'
+          find('#note-body').send_keys('@')
+        else
+          find('#note_note').send_keys('@')
+        end
       end
     end
 
@@ -32,7 +36,7 @@ feature 'Member autocomplete', :js do
       visit project_issue_path(project, noteable)
     end
 
-    include_examples "open suggestions when typing @"
+    include_examples "open suggestions when typing @", 'issue'
   end
 
   context 'adding a new note on a Merge Request' do
@@ -45,7 +49,7 @@ feature 'Member autocomplete', :js do
       visit project_merge_request_path(project, noteable)
     end
 
-    include_examples "open suggestions when typing @"
+    include_examples "open suggestions when typing @", 'merge_request'
   end
 
   context 'adding a new note on a Commit' do
@@ -60,6 +64,6 @@ feature 'Member autocomplete', :js do
       visit project_commit_path(project, noteable)
     end
 
-    include_examples "open suggestions when typing @"
+    include_examples "open suggestions when typing @", 'commit'
   end
 end
-- 
2.30.9