Fix autocomplete initial undefined state
Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/26775
This commit is contained in:
parent
b60de9c0fd
commit
cfe83509c0
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Fix autocomplete initial undefined state
|
||||
merge_request:
|
||||
author:
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue