Commit 94715834 authored by Fatih Acet's avatar Fatih Acet

Merge branch '26775-fix-auto-complete-initial-loading' into 'master'

Fix autocomplete initial undefined state (loading)

Closes #26775

See merge request !8667
parents 767262ac cfe83509
...@@ -367,9 +367,14 @@ ...@@ -367,9 +367,14 @@
return $input.trigger('keyup'); return $input.trigger('keyup');
}, },
isLoading(data) { isLoading(data) {
if (!data || !data.length) return false; var dataToInspect = data;
if (Array.isArray(data)) data = data[0]; if (data && data.length > 0) {
return data === this.defaultLoadingData[0] || data.name === this.defaultLoadingData[0]; dataToInspect = data[0];
}
var loadingState = this.defaultLoadingData[0];
return dataToInspect &&
(dataToInspect === loadingState || dataToInspect.name === loadingState);
} }
}; };
}).call(this); }).call(this);
---
title: Fix autocomplete initial undefined state
merge_request:
author:
...@@ -62,4 +62,30 @@ describe('GfmAutoComplete', function () { ...@@ -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);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment