From 317ef7b51c680503b01c88b8d8fdb09bd1a515e8 Mon Sep 17 00:00:00 2001
From: Phil Hughes <me@iamphill.com>
Date: Fri, 20 Jan 2017 18:04:15 +0000
Subject: [PATCH] Fixed failing JS specs

---
 .../filtered_search/dropdown_utils.js.es6     |  3 +--
 .../filtered_search_dropdown_manager.js.es6   |  1 -
 .../dropdown_utils_spec.js.es6                | 20 +++++++++++++++----
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/app/assets/javascripts/filtered_search/dropdown_utils.js.es6 b/app/assets/javascripts/filtered_search/dropdown_utils.js.es6
index f5d2eb9ae7..6910cf171d 100644
--- a/app/assets/javascripts/filtered_search/dropdown_utils.js.es6
+++ b/app/assets/javascripts/filtered_search/dropdown_utils.js.es6
@@ -76,7 +76,6 @@
     }
 
     static getSearchInput(filteredSearchInput) {
-      const selectionStart = filteredSearchInput.selectionStart;
       const inputValue = filteredSearchInput.value;
       const { right } = gl.DropdownUtils.getInputSelectionPosition(filteredSearchInput);
 
@@ -88,7 +87,7 @@
       let inputValue = input.value;
       // Replace all spaces inside quote marks with underscores
       // This helps with matching the beginning & end of a token:key
-      inputValue = inputValue.replace(/"(.*?)"/g, str => str.replace(/\s/g, '_') );
+      inputValue = inputValue.replace(/"(.*?)"/g, str => str.replace(/\s/g, '_'));
 
       // Get the right position for the word selected
       // Regex matches first space
diff --git a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
index 42c673a510..0487311558 100644
--- a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
+++ b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
@@ -73,7 +73,6 @@
       // Sometimes can end up at end of input
       input.setSelectionRange(selectionStart, selectionStart);
 
-      const inputValue = input.value;
       const { right } = gl.DropdownUtils.getInputSelectionPosition(input);
 
       input.setSelectionRange(right, right);
diff --git a/spec/javascripts/filtered_search/dropdown_utils_spec.js.es6 b/spec/javascripts/filtered_search/dropdown_utils_spec.js.es6
index f14583ec7d..19bd8d5321 100644
--- a/spec/javascripts/filtered_search/dropdown_utils_spec.js.es6
+++ b/spec/javascripts/filtered_search/dropdown_utils_spec.js.es6
@@ -67,20 +67,32 @@
     });
 
     describe('filterHint', () => {
+      let input;
+
+      beforeEach(() => {
+        setFixtures(`
+          <input type="text" id="test" />
+        `);
+
+        input = document.getElementById('test');
+      });
+
       it('should filter', () => {
-        let updatedItem = gl.DropdownUtils.filterHint({
+        input.value = 'l';
+        let updatedItem = gl.DropdownUtils.filterHint(input, {
           hint: 'label',
-        }, 'l');
+        });
         expect(updatedItem.droplab_hidden).toBe(false);
 
-        updatedItem = gl.DropdownUtils.filterHint({
+        input.value = 'o';
+        updatedItem = gl.DropdownUtils.filterHint(input, {
           hint: 'label',
         }, 'o');
         expect(updatedItem.droplab_hidden).toBe(true);
       });
 
       it('should return droplab_hidden false when item has no hint', () => {
-        const updatedItem = gl.DropdownUtils.filterHint({}, '');
+        const updatedItem = gl.DropdownUtils.filterHint(input, {}, '');
         expect(updatedItem.droplab_hidden).toBe(false);
       });
     });
-- 
2.30.9