diff options
author | Fatih Acet <acetfatih@gmail.com> | 2017-01-25 22:45:59 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2017-01-25 22:45:59 +0300 |
commit | 94715834cef03ab5e7bda0bb558a650f39d41e94 (patch) | |
tree | 9d600402394618f5a2eade94771c5bf60e4bd3f3 | |
parent | 767262ac82721b9ac4d80f1cff87188307170ee6 (diff) | |
parent | cfe83509c094390f170f9cec53d1f6576c2162de (diff) |
Merge branch '26775-fix-auto-complete-initial-loading' into 'master'
Fix autocomplete initial undefined state (loading)
Closes #26775
See merge request !8667
-rw-r--r-- | app/assets/javascripts/gfm_auto_complete.js.es6 | 11 | ||||
-rw-r--r-- | changelogs/unreleased/26775-fix-auto-complete-initial-loading.yml | 4 | ||||
-rw-r--r-- | spec/javascripts/gfm_auto_complete_spec.js.es6 | 26 |
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); + }); + }); }); |