Commit cfe83509 authored by Eric Eastwood's avatar Eric Eastwood

Fix autocomplete initial undefined state

Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/26775
parent b60de9c0
...@@ -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