summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Eastwood <contact@ericeastwood.com>2017-01-20 11:38:06 -0600
committerEric Eastwood <contact@ericeastwood.com>2017-01-23 17:38:06 -0600
commitcfe83509c094390f170f9cec53d1f6576c2162de (patch)
tree8d8f6b664be35f2703f4789ffb33e41e624467e3
parentb60de9c0fd90c310d2a4146f75b67f9f360cbd6c (diff)
downloadgitlab-ce-26775-fix-auto-complete-initial-loading.tar.gz
Fix autocomplete initial undefined state26775-fix-auto-complete-initial-loading
Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/26775
-rw-r--r--app/assets/javascripts/gfm_auto_complete.js.es611
-rw-r--r--changelogs/unreleased/26775-fix-auto-complete-initial-loading.yml4
-rw-r--r--spec/javascripts/gfm_auto_complete_spec.js.es626
3 files changed, 38 insertions, 3 deletions
diff --git a/app/assets/javascripts/gfm_auto_complete.js.es6 b/app/assets/javascripts/gfm_auto_complete.js.es6
index a1b7b442882..3f23095dad9 100644
--- a/app/assets/javascripts/gfm_auto_complete.js.es6
+++ b/app/assets/javascripts/gfm_auto_complete.js.es6
@@ -367,9 +367,14 @@
return $input.trigger('keyup');
},
isLoading(data) {
- if (!data || !data.length) return false;
- if (Array.isArray(data)) data = data[0];
- return data === this.defaultLoadingData[0] || data.name === this.defaultLoadingData[0];
+ var dataToInspect = data;
+ if (data && data.length > 0) {
+ dataToInspect = data[0];
+ }
+
+ var loadingState = this.defaultLoadingData[0];
+ return dataToInspect &&
+ (dataToInspect === loadingState || dataToInspect.name === loadingState);
}
};
}).call(this);
diff --git a/changelogs/unreleased/26775-fix-auto-complete-initial-loading.yml b/changelogs/unreleased/26775-fix-auto-complete-initial-loading.yml
new file mode 100644
index 00000000000..2d4ec482ee0
--- /dev/null
+++ b/changelogs/unreleased/26775-fix-auto-complete-initial-loading.yml
@@ -0,0 +1,4 @@
+---
+title: Fix autocomplete initial undefined state
+merge_request:
+author:
diff --git a/spec/javascripts/gfm_auto_complete_spec.js.es6 b/spec/javascripts/gfm_auto_complete_spec.js.es6
index 6b48d82cb23..99cebb32a8b 100644
--- a/spec/javascripts/gfm_auto_complete_spec.js.es6
+++ b/spec/javascripts/gfm_auto_complete_spec.js.es6
@@ -62,4 +62,30 @@ describe('GfmAutoComplete', function () {
});
});
});
+
+ describe('isLoading', function () {
+ it('should be true with loading data object item', function () {
+ expect(GfmAutoComplete.isLoading({ name: 'loading' })).toBe(true);
+ });
+
+ it('should be true with loading data array', function () {
+ expect(GfmAutoComplete.isLoading(['loading'])).toBe(true);
+ });
+
+ it('should be true with loading data object array', function () {
+ expect(GfmAutoComplete.isLoading([{ name: 'loading' }])).toBe(true);
+ });
+
+ it('should be false with actual array data', function () {
+ expect(GfmAutoComplete.isLoading([
+ { title: 'Foo' },
+ { title: 'Bar' },
+ { title: 'Qux' },
+ ])).toBe(false);
+ });
+
+ it('should be false with actual data item', function () {
+ expect(GfmAutoComplete.isLoading({ title: 'Foo' })).toBe(false);
+ });
+ });
});