mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-29 08:14:06 +00:00
Make JSLint happy.
This commit is contained in:
parent
d27a586af2
commit
d257039e38
@ -1,38 +1,39 @@
|
|||||||
/*jslint vars: true*/
|
/*jslint vars: true*/
|
||||||
/*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $*/
|
/*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $, beforeEach*/
|
||||||
|
|
||||||
describe('Autocomplete Async', function(){
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var input = document.createElement('input'),
|
var input = document.createElement('input'),
|
||||||
startQuery,
|
startQuery,
|
||||||
ajaxExecuted = false,
|
ajaxExecuted = false,
|
||||||
autocomplete = new $.Autocomplete(input, {
|
autocomplete = new $.Autocomplete(input, {
|
||||||
serviceUrl: '/test',
|
serviceUrl: '/test',
|
||||||
onSearchStart: function (params) {
|
onSearchStart: function (params) {
|
||||||
startQuery = params.query;
|
startQuery = params.query;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function (done){
|
|
||||||
$.mockjax({
|
|
||||||
url: '/test',
|
|
||||||
responseTime: 50,
|
|
||||||
response: function (settings) {
|
|
||||||
ajaxExecuted = true;
|
|
||||||
var query = settings.data.query,
|
|
||||||
response = {
|
|
||||||
query: query,
|
|
||||||
suggestions: []
|
|
||||||
};
|
|
||||||
this.responseText = JSON.stringify(response);
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
input.value = 'A';
|
|
||||||
autocomplete.onValueChange();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(function (done) {
|
||||||
|
$.mockjax({
|
||||||
|
url: '/test',
|
||||||
|
responseTime: 50,
|
||||||
|
response: function (settings) {
|
||||||
|
ajaxExecuted = true;
|
||||||
|
var query = settings.data.query,
|
||||||
|
response = {
|
||||||
|
query: query,
|
||||||
|
suggestions: []
|
||||||
|
};
|
||||||
|
this.responseText = JSON.stringify(response);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
input.value = 'A';
|
||||||
|
autocomplete.onValueChange();
|
||||||
|
});
|
||||||
|
|
||||||
it('Should execute onSearchStart', function () {
|
it('Should execute onSearchStart', function () {
|
||||||
expect(ajaxExecuted).toBe(true);
|
expect(ajaxExecuted).toBe(true);
|
||||||
expect(startQuery).toBe('A');
|
expect(startQuery).toBe('A');
|
||||||
@ -40,6 +41,8 @@ describe('Autocomplete Async', function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function () {
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var input = document.createElement('input'),
|
var input = document.createElement('input'),
|
||||||
completeQuery,
|
completeQuery,
|
||||||
mockupSuggestion = { value: 'A', data: 'A' },
|
mockupSuggestion = { value: 'A', data: 'A' },
|
||||||
@ -48,16 +51,16 @@ describe('Autocomplete Async', function () {
|
|||||||
url = '/test-completed';
|
url = '/test-completed';
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
var autocomplete = new $.Autocomplete(input, {
|
var autocomplete = new $.Autocomplete(input, {
|
||||||
serviceUrl: url,
|
serviceUrl: url,
|
||||||
onSearchComplete: function (query, suggestions) {
|
onSearchComplete: function (query, suggestions) {
|
||||||
completeQuery = query;
|
completeQuery = query;
|
||||||
resultSuggestions = suggestions;
|
resultSuggestions = suggestions;
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.mockjax({
|
$.mockjax({
|
||||||
url: url,
|
url: url,
|
||||||
responseTime: 50,
|
responseTime: 50,
|
||||||
response: function (settings) {
|
response: function (settings) {
|
||||||
@ -83,11 +86,11 @@ describe('Autocomplete Async', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function() {
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
var errorMessage = false;
|
var errorMessage = false;
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function (done) {
|
||||||
var input = document.createElement('input'),
|
var input = document.createElement('input'),
|
||||||
url = '/test-error',
|
url = '/test-error',
|
||||||
autocomplete = new $.Autocomplete(input, {
|
autocomplete = new $.Autocomplete(input, {
|
||||||
@ -116,11 +119,12 @@ describe('Autocomplete Async', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Asyn', function(){
|
describe('Asyn', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var instance;
|
var instance;
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function (done) {
|
||||||
var input = document.createElement('input'),
|
var input = document.createElement('input'),
|
||||||
ajaxExecuted = false,
|
ajaxExecuted = false,
|
||||||
url = '/test-transform',
|
url = '/test-transform',
|
||||||
@ -162,10 +166,12 @@ describe('Asyn', function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function(){
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var instance;
|
var instance;
|
||||||
|
|
||||||
beforeEach(function (done){
|
beforeEach(function (done) {
|
||||||
var input = document.createElement('input'),
|
var input = document.createElement('input'),
|
||||||
ajaxExecuted = false,
|
ajaxExecuted = false,
|
||||||
url = '/test-original-query',
|
url = '/test-original-query',
|
||||||
@ -200,6 +206,8 @@ describe('Autocomplete Async', function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function () {
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var paramValue;
|
var paramValue;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@ -235,6 +243,8 @@ describe('Autocomplete Async', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function () {
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var dynamicUrl,
|
var dynamicUrl,
|
||||||
data;
|
data;
|
||||||
|
|
||||||
@ -273,6 +283,8 @@ describe('Autocomplete Async', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function () {
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var instance,
|
var instance,
|
||||||
cacheKey;
|
cacheKey;
|
||||||
|
|
||||||
@ -315,6 +327,8 @@ describe('Autocomplete Async', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Autocomplete Async', function () {
|
describe('Autocomplete Async', function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var ajaxCount = 0;
|
var ajaxCount = 0;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@ -330,10 +344,12 @@ describe('Autocomplete Async', function () {
|
|||||||
url: serviceUrl,
|
url: serviceUrl,
|
||||||
responseTime: 1,
|
responseTime: 1,
|
||||||
response: function (settings) {
|
response: function (settings) {
|
||||||
ajaxCount++;
|
ajaxCount += 1;
|
||||||
var response = { suggestions: [] };
|
var response = { suggestions: [] };
|
||||||
this.responseText = JSON.stringify(response);
|
this.responseText = JSON.stringify(response);
|
||||||
if (ajaxCount === 2) done();
|
if (ajaxCount === 2) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -676,59 +692,61 @@ describe('Autocomplete', function () {
|
|||||||
noSuggestionNotice: 'Sorry, no matching results'
|
noSuggestionNotice: 'Sorry, no matching results'
|
||||||
},
|
},
|
||||||
autocomplete = new $.Autocomplete(input, options),
|
autocomplete = new $.Autocomplete(input, options),
|
||||||
suggestionsContainer = $(autocomplete.suggestionsContainer)
|
suggestionsContainer = $(autocomplete.suggestionsContainer);
|
||||||
|
|
||||||
input.value = 'Jamaica';
|
input.value = 'Jamaica';
|
||||||
autocomplete.onValueChange();
|
autocomplete.onValueChange();
|
||||||
|
|
||||||
expect(autocomplete.visible).toBe(true);
|
expect(autocomplete.visible).toBe(true);
|
||||||
expect(autocomplete.selectedIndex).toBe(-1)
|
expect(autocomplete.selectedIndex).toBe(-1);
|
||||||
expect(suggestionsContainer.find('.autocomplete-no-suggestion').length).toBe(1)
|
expect(suggestionsContainer.find('.autocomplete-no-suggestion').length).toBe(1);
|
||||||
expect(suggestionsContainer.find('.autocomplete-no-suggestion').text()).toBe('Sorry, no matching results')
|
expect(suggestionsContainer.find('.autocomplete-no-suggestion').text()).toBe('Sorry, no matching results');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When options.preserveInput is true', function() {
|
describe('When options.preserveInput is true', function () {
|
||||||
var input = $('<input />'),
|
'use strict';
|
||||||
instance,
|
|
||||||
suggestionData = null;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
var input = $('<input />'),
|
||||||
input.autocomplete({
|
instance,
|
||||||
lookup: [{ value: 'Jamaica', data: 'J' }, { value: 'Jamaica2', data: 'J' }, { value: 'Jamaica3', data: 'J' }],
|
suggestionData = null;
|
||||||
preserveInput: true,
|
|
||||||
onSelect: function (suggestion) {
|
|
||||||
suggestionData = suggestion.data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
input.val('J');
|
beforeEach(function () {
|
||||||
instance = input.autocomplete();
|
input.autocomplete({
|
||||||
});
|
lookup: [{ value: 'Jamaica', data: 'J' }, { value: 'Jamaica2', data: 'J' }, { value: 'Jamaica3', data: 'J' }],
|
||||||
|
preserveInput: true,
|
||||||
|
onSelect: function (suggestion) {
|
||||||
|
suggestionData = suggestion.data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
input.val('J');
|
||||||
|
instance = input.autocomplete();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
instance.dispose();
|
instance.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should NOT change input value when item is selected', function() {
|
it('Should NOT change input value when item is selected', function () {
|
||||||
instance.onValueChange();
|
instance.onValueChange();
|
||||||
instance.select(0);
|
instance.select(0);
|
||||||
|
|
||||||
expect(input.val()).toEqual('J');
|
expect(input.val()).toEqual('J');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should NOT change input value when move down', function() {
|
it('Should NOT change input value when move down', function () {
|
||||||
instance.onValueChange();
|
instance.onValueChange();
|
||||||
instance.moveDown();
|
instance.moveDown();
|
||||||
|
|
||||||
expect(input.val()).toEqual('J');
|
expect(input.val()).toEqual('J');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should NOT change input value when move up', function() {
|
it('Should NOT change input value when move up', function () {
|
||||||
instance.onValueChange();
|
instance.onValueChange();
|
||||||
instance.moveUp();
|
instance.moveUp();
|
||||||
|
|
||||||
expect(input.val()).toEqual('J');
|
expect(input.val()).toEqual('J');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user