69e4072f89
* master: (389 commits)
Document "No gems fetched from git repositories" policy [ci skip]
Typos
Small gramatical tweaks
Typos
Added PHP & NPM doc
Use `:empty_project` where possible in request specs
Add caching of droplab ajax requests
Use `:empty_project` where possible in model specs
Revert 3f17f29a
Remove unused js response from refs controller
Add MR id to changelog entry
fixed small mini pipeline graph line glitch
Prevent form to be submitted twice
Fix Error 500 when repositories contain annotated tags pointing to blobs
Fix /explore sorting (trending)
Simplify wording in "adding an image" docs
Remove "official merge window" from CONTRIBUTING.md [ci skip]
Update repository check documentation
Fixed flexbox and wrap issues
Update two_factor_authentication.md
...
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
require('~/gfm_auto_complete');
|
|
require('vendor/jquery.caret');
|
|
require('vendor/jquery.atwho');
|
|
|
|
const global = window.gl || (window.gl = {});
|
|
const GfmAutoComplete = global.GfmAutoComplete;
|
|
|
|
describe('GfmAutoComplete', function () {
|
|
describe('DefaultOptions.sorter', function () {
|
|
describe('assets loading', function () {
|
|
beforeEach(function () {
|
|
spyOn(GfmAutoComplete, 'isLoading').and.returnValue(true);
|
|
|
|
this.atwhoInstance = { setting: {} };
|
|
this.items = [];
|
|
|
|
this.sorterValue = GfmAutoComplete.DefaultOptions.sorter
|
|
.call(this.atwhoInstance, '', this.items);
|
|
});
|
|
|
|
it('should disable highlightFirst', function () {
|
|
expect(this.atwhoInstance.setting.highlightFirst).toBe(false);
|
|
});
|
|
|
|
it('should return the passed unfiltered items', function () {
|
|
expect(this.sorterValue).toEqual(this.items);
|
|
});
|
|
});
|
|
|
|
describe('assets finished loading', function () {
|
|
beforeEach(function () {
|
|
spyOn(GfmAutoComplete, 'isLoading').and.returnValue(false);
|
|
spyOn($.fn.atwho.default.callbacks, 'sorter');
|
|
});
|
|
|
|
it('should enable highlightFirst if alwaysHighlightFirst is set', function () {
|
|
const atwhoInstance = { setting: { alwaysHighlightFirst: true } };
|
|
|
|
GfmAutoComplete.DefaultOptions.sorter.call(atwhoInstance);
|
|
|
|
expect(atwhoInstance.setting.highlightFirst).toBe(true);
|
|
});
|
|
|
|
it('should enable highlightFirst if a query is present', function () {
|
|
const atwhoInstance = { setting: {} };
|
|
|
|
GfmAutoComplete.DefaultOptions.sorter.call(atwhoInstance, 'query');
|
|
|
|
expect(atwhoInstance.setting.highlightFirst).toBe(true);
|
|
});
|
|
|
|
it('should call the default atwho sorter', function () {
|
|
const atwhoInstance = { setting: {} };
|
|
|
|
const query = 'query';
|
|
const items = [];
|
|
const searchKey = 'searchKey';
|
|
|
|
GfmAutoComplete.DefaultOptions.sorter.call(atwhoInstance, query, items, searchKey);
|
|
|
|
expect($.fn.atwho.default.callbacks.sorter).toHaveBeenCalledWith(query, items, searchKey);
|
|
});
|
|
});
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|