2019-08-08 04:16:45 +03:00
|
|
|
QUnit.module('Defaults - Ajax');
|
2016-02-14 22:00:01 +03:00
|
|
|
|
2019-08-22 05:21:52 +03:00
|
|
|
QUnit.test(
|
|
|
|
'options are merged recursively with default options',
|
|
|
|
function (assert) {
|
|
|
|
var defaults = require('select2/defaults');
|
|
|
|
|
|
|
|
var ajaxDelay = 250;
|
|
|
|
var ajaxUrl = 'http://www.test.com';
|
|
|
|
|
|
|
|
var mergedOptions;
|
|
|
|
|
|
|
|
defaults.set('ajax--delay', ajaxDelay);
|
|
|
|
|
|
|
|
mergedOptions = defaults.apply({
|
|
|
|
ajax: {
|
|
|
|
url: ajaxUrl
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
mergedOptions.ajax.delay,
|
2016-05-19 18:40:32 +03:00
|
|
|
ajaxDelay,
|
2019-08-22 05:21:52 +03:00
|
|
|
'Ajax default options are present on the merged options'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
mergedOptions.ajax.url,
|
|
|
|
ajaxUrl,
|
|
|
|
'Ajax provided options are present on the merged options'
|
|
|
|
);
|
|
|
|
|
|
|
|
defaults.reset();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
QUnit.test(
|
|
|
|
'more than one default option can be changed via set()',
|
|
|
|
function(assert) {
|
|
|
|
var defaults = require('select2/defaults');
|
|
|
|
var ajaxDelay = 123;
|
|
|
|
var dataDataType = 'xml';
|
|
|
|
defaults.set('ajax--delay', ajaxDelay);
|
|
|
|
defaults.set('ajax--data-type', dataDataType);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
defaults.defaults.ajax.delay,
|
|
|
|
ajaxDelay,
|
|
|
|
'Both ajax.delay and ajax.dataType present in defaults');
|
|
|
|
assert.equal(
|
|
|
|
defaults.defaults.ajax.dataType,
|
|
|
|
dataDataType,
|
2016-05-19 01:42:07 +03:00
|
|
|
'Both ajax.delay and ajax.dataType present in defaults');
|
2019-08-22 05:21:52 +03:00
|
|
|
defaults.reset();
|
|
|
|
}
|
|
|
|
);
|