2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-09 23:01:00 +00:00

Split one test into two.

This commit is contained in:
Tomas Kirda 2013-02-21 11:34:47 -06:00
parent a439496a29
commit 52151c267b

View File

@ -94,18 +94,14 @@ describe('Autocomplete', function () {
expect(autocomplete.options.lookup[1].value).toBe('B'); expect(autocomplete.options.lookup[1].value).toBe('B');
}); });
it('Should execute onSearchStart and onSearchCompleted', function () { it('Should execute onSearchStart', function () {
var input = document.createElement('input'), var input = document.createElement('input'),
startQuery, startQuery,
completeQuery,
ajaxExecuted = false, ajaxExecuted = false,
autocomplete = new $.Autocomplete(input, { autocomplete = new $.Autocomplete(input, {
serviceUrl: '/test', serviceUrl: '/test',
onSearchStart: function (query) { onSearchStart: function (params) {
startQuery = query; startQuery = params.query;
},
onSearchComplete: function (query) {
completeQuery = query;
} }
}); });
@ -133,6 +129,44 @@ describe('Autocomplete', function () {
runs(function () { runs(function () {
expect(ajaxExecuted).toBe(true); expect(ajaxExecuted).toBe(true);
expect(startQuery).toBe('A'); expect(startQuery).toBe('A');
});
});
it('Should execute onSearchCompleted', function () {
var input = document.createElement('input'),
completeQuery,
ajaxExecuted = false,
url = '/test-completed',
autocomplete = new $.Autocomplete(input, {
serviceUrl: url,
onSearchComplete: function (query) {
completeQuery = query;
}
});
$.mockjax({
url: url,
responseTime: 50,
response: function (settings) {
ajaxExecuted = true;
var query = settings.data.query,
response = {
query: query,
suggestions: []
};
this.responseText = JSON.stringify(response);
}
});
input.value = 'A';
autocomplete.onValueChange();
waitsFor(function () {
return ajaxExecuted;
}, 'Ajax call never completed.', 100);
runs(function () {
expect(ajaxExecuted).toBe(true);
expect(completeQuery).toBe('A'); expect(completeQuery).toBe('A');
}); });
}); });