1
0
mirror of synced 2024-11-22 13:06:08 +03:00

Tests use jQuery 1.7.2

As jQuery 1.7.2 is the lowest version of jQuery supported by Select2,
it makes sense to run the tests on it. For the most part, we can
assume that the newer versions of Select2 are backwards compatible
enough such that this isn't an issue.

The recommended version of jQuery to use is the latest though, which
is why the jQuery file is only included in the tests.

This revealed a few issues with our data fallbacks and `.append`
functionality that was introduced in jQuery 1.8.
This commit is contained in:
Kevin Brown 2015-03-11 19:20:41 -04:00
parent 4fb079b34f
commit b9b55cec44
14 changed files with 9459 additions and 50 deletions

View File

@ -1088,7 +1088,7 @@ define('select2/selection/multiple',[
return; return;
} }
var $selections = []; var $selections = $();
for (var d = 0; d < data.length; d++) { for (var d = 0; d < data.length; d++) {
var selection = data[d]; var selection = data[d];
@ -1101,7 +1101,7 @@ define('select2/selection/multiple',[
$selection.data('data', selection); $selection.data('data', selection);
$selections.push($selection); $selections = $selections.add($selection);
} }
this.$selection.find('.select2-selection__rendered').append($selections); this.$selection.find('.select2-selection__rendered').append($selections);
@ -2659,7 +2659,7 @@ define('select2/data/array',[
if ($option.length === 0) { if ($option.length === 0) {
$option = this.option(data); $option = this.option(data);
this.addOptions([$option]); this.addOptions($option);
} }
ArrayAdapter.__super__.select.call(this, data); ArrayAdapter.__super__.select.call(this, data);
@ -2673,7 +2673,7 @@ define('select2/data/array',[
return self.item($(this)).id; return self.item($(this)).id;
}).get(); }).get();
var $options = []; var $options = $();
// Filter out all items except for the one passed in the argument // Filter out all items except for the one passed in the argument
function onlyItem (item) { function onlyItem (item) {
@ -2707,7 +2707,7 @@ define('select2/data/array',[
$option.append($children); $option.append($children);
} }
$options.push($option); $options = $options.add($option);
} }
return $options; return $options;
@ -2887,7 +2887,7 @@ define('select2/data/tags',[
var $option = self.option(tag); var $option = self.option(tag);
$option.attr('data-select2-tag', true); $option.attr('data-select2-tag', true);
self.addOptions([$option]); self.addOptions($option);
self.insertTag(data, tag); self.insertTag(data, tag);
} }
@ -4160,7 +4160,8 @@ define('select2/options',[
); );
} }
$e.data('ajax-Url', $e.data('ajaxUrl')); $e.attr('ajax--url', $e.data('ajaxUrl'));
$e.data('ajax--url', $e.data('ajaxUrl'));
} }
var dataset = {}; var dataset = {};
@ -5155,8 +5156,8 @@ define('select2/compat/inputData',[
}; };
InputData.prototype.addOptions = function (_, $options) { InputData.prototype.addOptions = function (_, $options) {
var options = $.map($options, function ($option) { var options = $.map($options, function (option) {
return $.data($option[0], 'data'); return $.data(option, 'data');
}); });
this._currentData.push.apply(this._currentData, options); this._currentData.push.apply(this._currentData, options);

View File

@ -1088,7 +1088,7 @@ define('select2/selection/multiple',[
return; return;
} }
var $selections = []; var $selections = $();
for (var d = 0; d < data.length; d++) { for (var d = 0; d < data.length; d++) {
var selection = data[d]; var selection = data[d];
@ -1101,7 +1101,7 @@ define('select2/selection/multiple',[
$selection.data('data', selection); $selection.data('data', selection);
$selections.push($selection); $selections = $selections.add($selection);
} }
this.$selection.find('.select2-selection__rendered').append($selections); this.$selection.find('.select2-selection__rendered').append($selections);
@ -2659,7 +2659,7 @@ define('select2/data/array',[
if ($option.length === 0) { if ($option.length === 0) {
$option = this.option(data); $option = this.option(data);
this.addOptions([$option]); this.addOptions($option);
} }
ArrayAdapter.__super__.select.call(this, data); ArrayAdapter.__super__.select.call(this, data);
@ -2673,7 +2673,7 @@ define('select2/data/array',[
return self.item($(this)).id; return self.item($(this)).id;
}).get(); }).get();
var $options = []; var $options = $();
// Filter out all items except for the one passed in the argument // Filter out all items except for the one passed in the argument
function onlyItem (item) { function onlyItem (item) {
@ -2707,7 +2707,7 @@ define('select2/data/array',[
$option.append($children); $option.append($children);
} }
$options.push($option); $options = $options.add($option);
} }
return $options; return $options;
@ -2887,7 +2887,7 @@ define('select2/data/tags',[
var $option = self.option(tag); var $option = self.option(tag);
$option.attr('data-select2-tag', true); $option.attr('data-select2-tag', true);
self.addOptions([$option]); self.addOptions($option);
self.insertTag(data, tag); self.insertTag(data, tag);
} }
@ -4160,7 +4160,8 @@ define('select2/options',[
); );
} }
$e.data('ajax-Url', $e.data('ajaxUrl')); $e.attr('ajax--url', $e.data('ajaxUrl'));
$e.data('ajax--url', $e.data('ajaxUrl'));
} }
var dataset = {}; var dataset = {};

View File

@ -1527,7 +1527,7 @@ define('select2/selection/multiple',[
return; return;
} }
var $selections = []; var $selections = $();
for (var d = 0; d < data.length; d++) { for (var d = 0; d < data.length; d++) {
var selection = data[d]; var selection = data[d];
@ -1540,7 +1540,7 @@ define('select2/selection/multiple',[
$selection.data('data', selection); $selection.data('data', selection);
$selections.push($selection); $selections = $selections.add($selection);
} }
this.$selection.find('.select2-selection__rendered').append($selections); this.$selection.find('.select2-selection__rendered').append($selections);
@ -3098,7 +3098,7 @@ define('select2/data/array',[
if ($option.length === 0) { if ($option.length === 0) {
$option = this.option(data); $option = this.option(data);
this.addOptions([$option]); this.addOptions($option);
} }
ArrayAdapter.__super__.select.call(this, data); ArrayAdapter.__super__.select.call(this, data);
@ -3112,7 +3112,7 @@ define('select2/data/array',[
return self.item($(this)).id; return self.item($(this)).id;
}).get(); }).get();
var $options = []; var $options = $();
// Filter out all items except for the one passed in the argument // Filter out all items except for the one passed in the argument
function onlyItem (item) { function onlyItem (item) {
@ -3146,7 +3146,7 @@ define('select2/data/array',[
$option.append($children); $option.append($children);
} }
$options.push($option); $options = $options.add($option);
} }
return $options; return $options;
@ -3326,7 +3326,7 @@ define('select2/data/tags',[
var $option = self.option(tag); var $option = self.option(tag);
$option.attr('data-select2-tag', true); $option.attr('data-select2-tag', true);
self.addOptions([$option]); self.addOptions($option);
self.insertTag(data, tag); self.insertTag(data, tag);
} }
@ -4599,7 +4599,8 @@ define('select2/options',[
); );
} }
$e.data('ajax-Url', $e.data('ajaxUrl')); $e.attr('ajax--url', $e.data('ajaxUrl'));
$e.data('ajax--url', $e.data('ajaxUrl'));
} }
var dataset = {}; var dataset = {};
@ -5594,8 +5595,8 @@ define('select2/compat/inputData',[
}; };
InputData.prototype.addOptions = function (_, $options) { InputData.prototype.addOptions = function (_, $options) {
var options = $.map($options, function ($option) { var options = $.map($options, function (option) {
return $.data($option[0], 'data'); return $.data(option, 'data');
}); });
this._currentData.push.apply(this._currentData, options); this._currentData.push.apply(this._currentData, options);

File diff suppressed because one or more lines are too long

15
dist/js/select2.js vendored
View File

@ -1527,7 +1527,7 @@ define('select2/selection/multiple',[
return; return;
} }
var $selections = []; var $selections = $();
for (var d = 0; d < data.length; d++) { for (var d = 0; d < data.length; d++) {
var selection = data[d]; var selection = data[d];
@ -1540,7 +1540,7 @@ define('select2/selection/multiple',[
$selection.data('data', selection); $selection.data('data', selection);
$selections.push($selection); $selections = $selections.add($selection);
} }
this.$selection.find('.select2-selection__rendered').append($selections); this.$selection.find('.select2-selection__rendered').append($selections);
@ -3098,7 +3098,7 @@ define('select2/data/array',[
if ($option.length === 0) { if ($option.length === 0) {
$option = this.option(data); $option = this.option(data);
this.addOptions([$option]); this.addOptions($option);
} }
ArrayAdapter.__super__.select.call(this, data); ArrayAdapter.__super__.select.call(this, data);
@ -3112,7 +3112,7 @@ define('select2/data/array',[
return self.item($(this)).id; return self.item($(this)).id;
}).get(); }).get();
var $options = []; var $options = $();
// Filter out all items except for the one passed in the argument // Filter out all items except for the one passed in the argument
function onlyItem (item) { function onlyItem (item) {
@ -3146,7 +3146,7 @@ define('select2/data/array',[
$option.append($children); $option.append($children);
} }
$options.push($option); $options = $options.add($option);
} }
return $options; return $options;
@ -3326,7 +3326,7 @@ define('select2/data/tags',[
var $option = self.option(tag); var $option = self.option(tag);
$option.attr('data-select2-tag', true); $option.attr('data-select2-tag', true);
self.addOptions([$option]); self.addOptions($option);
self.insertTag(data, tag); self.insertTag(data, tag);
} }
@ -4599,7 +4599,8 @@ define('select2/options',[
); );
} }
$e.data('ajax-Url', $e.data('ajaxUrl')); $e.attr('ajax--url', $e.data('ajaxUrl'));
$e.data('ajax--url', $e.data('ajaxUrl'));
} }
var dataset = {}; var dataset = {};

File diff suppressed because one or more lines are too long

View File

@ -116,8 +116,8 @@ define([
}; };
InputData.prototype.addOptions = function (_, $options) { InputData.prototype.addOptions = function (_, $options) {
var options = $.map($options, function ($option) { var options = $.map($options, function (option) {
return $.data($option[0], 'data'); return $.data(option, 'data');
}); });
this._currentData.push.apply(this._currentData, options); this._currentData.push.apply(this._currentData, options);

View File

@ -19,7 +19,7 @@ define([
if ($option.length === 0) { if ($option.length === 0) {
$option = this.option(data); $option = this.option(data);
this.addOptions([$option]); this.addOptions($option);
} }
ArrayAdapter.__super__.select.call(this, data); ArrayAdapter.__super__.select.call(this, data);
@ -33,7 +33,7 @@ define([
return self.item($(this)).id; return self.item($(this)).id;
}).get(); }).get();
var $options = []; var $options = $();
// Filter out all items except for the one passed in the argument // Filter out all items except for the one passed in the argument
function onlyItem (item) { function onlyItem (item) {
@ -67,7 +67,7 @@ define([
$option.append($children); $option.append($children);
} }
$options.push($option); $options = $options.add($option);
} }
return $options; return $options;

View File

@ -71,7 +71,7 @@ define([
var $option = self.option(tag); var $option = self.option(tag);
$option.attr('data-select2-tag', true); $option.attr('data-select2-tag', true);
self.addOptions([$option]); self.addOptions($option);
self.insertTag(data, tag); self.insertTag(data, tag);
} }

View File

@ -76,7 +76,8 @@ define([
); );
} }
$e.data('ajax-Url', $e.data('ajaxUrl')); $e.attr('ajax--url', $e.data('ajaxUrl'));
$e.data('ajax--url', $e.data('ajaxUrl'));
} }
var dataset = {}; var dataset = {};

View File

@ -76,7 +76,7 @@ define([
return; return;
} }
var $selections = []; var $selections = $();
for (var d = 0; d < data.length; d++) { for (var d = 0; d < data.length; d++) {
var selection = data[d]; var selection = data[d];
@ -89,7 +89,7 @@ define([
$selection.data('data', selection); $selection.data('data', selection);
$selections.push($selection); $selections = $selections.add($selection);
} }
this.$selection.find('.select2-selection__rendered').append($selections); this.$selection.find('.select2-selection__rendered').append($selections);

View File

@ -1,7 +1,7 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<link rel="stylesheet" href="../vendor/qunit-1.14.0.css" type="text/css" /> <link rel="stylesheet" href="vendor/qunit-1.14.0.css" type="text/css" />
<link rel="stylesheet" href="../../dist/css/select2.css" type="text/css" /> <link rel="stylesheet" href="../../dist/css/select2.css" type="text/css" />
</head> </head>
<body> <body>
@ -49,7 +49,7 @@
</div> </div>
<script src="vendor/qunit-1.14.0.js" type="text/javascript"></script> <script src="vendor/qunit-1.14.0.js" type="text/javascript"></script>
<script src="../vendor/jquery-2.1.0.js" type="text/javascript"></script> <script src="vendor/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../dist/js/select2.full.js" type="text/javascript"></script> <script src="../dist/js/select2.full.js" type="text/javascript"></script>
<script src="helpers.js" type="text/javascript"></script> <script src="helpers.js" type="text/javascript"></script>
@ -60,7 +60,7 @@
<script src="data/base-tests.js" type="text/javascript"></script> <script src="data/base-tests.js" type="text/javascript"></script>
<script src="data/inputData-tests.js" type="text/javascript"></script> <script src="data/inputData-tests.js" type="text/javascript"></script>
<script src="data/select-tests.js" type="text/javascript"></script> <script src="data/select-tests.js" type="text/javascript"></script>
<script src="tags-tests.js" type="text/javascript"></script> <script src="data/tags-tests.js" type="text/javascript"></script>
<script src="data/maximumInputLength-tests.js" type="text/javascript"></script> <script src="data/maximumInputLength-tests.js" type="text/javascript"></script>
<script src="data/maximumSelectionLength-tests.js" type="text/javascript"></script> <script src="data/maximumSelectionLength-tests.js" type="text/javascript"></script>

View File

@ -65,8 +65,8 @@ test('escapeMarkup is being used', function (assert) {
}]); }]);
assert.equal( assert.equal(
$rendered.text().indexOf(unescapedText), $rendered.text().substr(1),
1, unescapedText,
'The text should be escaped by default to prevent injection' 'The text should be escaped by default to prevent injection'
); );
}); });

9404
tests/vendor/jquery-1.7.2.js vendored Normal file

File diff suppressed because it is too large Load Diff