diff options
Diffstat (limited to 'spec/javascripts/gfm_auto_complete_spec.js')
-rw-r--r-- | spec/javascripts/gfm_auto_complete_spec.js | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/spec/javascripts/gfm_auto_complete_spec.js b/spec/javascripts/gfm_auto_complete_spec.js index b57c4943c01..6f414c8ccf1 100644 --- a/spec/javascripts/gfm_auto_complete_spec.js +++ b/spec/javascripts/gfm_auto_complete_spec.js @@ -6,39 +6,38 @@ import GfmAutoComplete from '~/gfm_auto_complete'; import 'vendor/jquery.caret'; import 'vendor/jquery.atwho'; -describe('GfmAutoComplete', function () { +describe('GfmAutoComplete', function() { const gfmAutoCompleteCallbacks = GfmAutoComplete.prototype.getDefaultCallbacks.call({ fetchData: () => {}, }); - describe('DefaultOptions.sorter', function () { - describe('assets loading', function () { - beforeEach(function () { + describe('DefaultOptions.sorter', function() { + describe('assets loading', function() { + beforeEach(function() { spyOn(GfmAutoComplete, 'isLoading').and.returnValue(true); this.atwhoInstance = { setting: {} }; this.items = []; - this.sorterValue = gfmAutoCompleteCallbacks.sorter - .call(this.atwhoInstance, '', this.items); + this.sorterValue = gfmAutoCompleteCallbacks.sorter.call(this.atwhoInstance, '', this.items); }); - it('should disable highlightFirst', function () { + it('should disable highlightFirst', function() { expect(this.atwhoInstance.setting.highlightFirst).toBe(false); }); - it('should return the passed unfiltered items', function () { + it('should return the passed unfiltered items', function() { expect(this.sorterValue).toEqual(this.items); }); }); - describe('assets finished loading', function () { - beforeEach(function () { + 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 () { + it('should enable highlightFirst if alwaysHighlightFirst is set', function() { const atwhoInstance = { setting: { alwaysHighlightFirst: true } }; gfmAutoCompleteCallbacks.sorter.call(atwhoInstance); @@ -46,7 +45,7 @@ describe('GfmAutoComplete', function () { expect(atwhoInstance.setting.highlightFirst).toBe(true); }); - it('should enable highlightFirst if a query is present', function () { + it('should enable highlightFirst if a query is present', function() { const atwhoInstance = { setting: {} }; gfmAutoCompleteCallbacks.sorter.call(atwhoInstance, 'query'); @@ -54,7 +53,7 @@ describe('GfmAutoComplete', function () { expect(atwhoInstance.setting.highlightFirst).toBe(true); }); - it('should call the default atwho sorter', function () { + it('should call the default atwho sorter', function() { const atwhoInstance = { setting: {} }; const query = 'query'; @@ -69,9 +68,8 @@ describe('GfmAutoComplete', function () { }); describe('DefaultOptions.beforeInsert', () => { - const beforeInsert = (context, value) => ( - gfmAutoCompleteCallbacks.beforeInsert.call(context, value) - ); + const beforeInsert = (context, value) => + gfmAutoCompleteCallbacks.beforeInsert.call(context, value); const atwhoInstance = { setting: { skipSpecialCharacterTest: false } }; @@ -98,29 +96,51 @@ describe('GfmAutoComplete', function () { }); }); - describe('DefaultOptions.matcher', function () { - const defaultMatcher = (context, flag, subtext) => ( - gfmAutoCompleteCallbacks.matcher.call(context, flag, subtext) - ); + describe('DefaultOptions.matcher', function() { + const defaultMatcher = (context, flag, subtext) => + gfmAutoCompleteCallbacks.matcher.call(context, flag, subtext); const flagsUseDefaultMatcher = ['@', '#', '!', '~', '%', '$']; const otherFlags = ['/', ':']; const flags = flagsUseDefaultMatcher.concat(otherFlags); - const flagsHash = flags.reduce((hash, el) => { hash[el] = null; return hash; }, {}); + const flagsHash = flags.reduce((hash, el) => { + hash[el] = null; + return hash; + }, {}); const atwhoInstance = { setting: {}, app: { controllers: flagsHash } }; const minLen = 1; const maxLen = 20; const argumentSize = [minLen, maxLen / 2, maxLen]; - const allowedSymbols = ['', 'a', 'n', 'z', 'A', 'Z', 'N', '0', '5', '9', 'А', 'а', 'Я', 'я', '.', '\'', '+', '-', '_']; + const allowedSymbols = [ + '', + 'a', + 'n', + 'z', + 'A', + 'Z', + 'N', + '0', + '5', + '9', + 'А', + 'а', + 'Я', + 'я', + '.', + "'", + '+', + '-', + '_', + ]; const jointAllowedSymbols = allowedSymbols.join(''); describe('should match regular symbols', () => { - flagsUseDefaultMatcher.forEach((flag) => { - allowedSymbols.forEach((symbol) => { - argumentSize.forEach((size) => { + flagsUseDefaultMatcher.forEach(flag => { + allowedSymbols.forEach(symbol => { + argumentSize.forEach(size => { const query = new Array(size + 1).join(symbol); const subtext = flag + query; @@ -142,8 +162,8 @@ describe('GfmAutoComplete', function () { const shouldNotBeFollowedBy = flags.concat(['\x00', '\x10', '\x3f', '\n', ' ']); const shouldNotBePrependedBy = ['`']; - flagsUseDefaultMatcher.forEach((atSign) => { - shouldNotBeFollowedBy.forEach((followedSymbol) => { + flagsUseDefaultMatcher.forEach(atSign => { + shouldNotBeFollowedBy.forEach(followedSymbol => { const seq = atSign + followedSymbol; it(`should not match ${JSON.stringify(seq)}`, () => { @@ -151,7 +171,7 @@ describe('GfmAutoComplete', function () { }); }); - shouldNotBePrependedBy.forEach((prependedSymbol) => { + shouldNotBePrependedBy.forEach(prependedSymbol => { const seq = prependedSymbol + atSign; it(`should not match "${seq}"`, () => { @@ -162,28 +182,26 @@ describe('GfmAutoComplete', function () { }); }); - describe('isLoading', function () { - it('should be true with loading data object item', 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 () { + 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 () { + 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 array data', function() { + expect( + GfmAutoComplete.isLoading([{ title: 'Foo' }, { title: 'Bar' }, { title: 'Qux' }]), + ).toBe(false); }); - it('should be false with actual data item', function () { + it('should be false with actual data item', function() { expect(GfmAutoComplete.isLoading({ title: 'Foo' })).toBe(false); }); }); |