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

Fix select2('data') again

This finally fixes and adds some integration tests to make sure
that `select2('data')` works as we are expecting. This also adds
tests for `select2('val')` and fixes undefined variable issues
that were spotted because of these tests.

We also no longer date stamp distribution builds.

This closes https://github.com/select2/select2/issues/3104.
This commit is contained in:
Kevin Brown 2015-03-14 15:21:34 -04:00
parent 7a1791d5f3
commit e8fd5a0352
12 changed files with 181 additions and 29 deletions

View File

@ -56,13 +56,10 @@ module.exports = function (grunt) {
i18nPaths[name] = '../../' + name; i18nPaths[name] = '../../' + name;
} }
var minifiedBanner = '/!* Select2 <%= package.version %> | <%= vars.date %> | https://github.com/select2/select2/blob/master/LICENSE.md */'; var minifiedBanner = '/!* Select2 <%= package.version %> | https://github.com/select2/select2/blob/master/LICENSE.md */';
grunt.initConfig({ grunt.initConfig({
package: grunt.file.readJSON('package.json'), package: grunt.file.readJSON('package.json'),
vars: {
date: (new Date()).toUTCString()
},
clean: { clean: {
docs: ['docs/_site'] docs: ['docs/_site']

View File

@ -4626,7 +4626,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
args = [true]; args = [true];
} }
@ -4646,7 +4646,7 @@ define('select2/core',[
var data = []; var data = [];
this.dataAdpater.current(function (currentData) { this.dataAdapter.current(function (currentData) {
data = currentData; data = currentData;
}); });
@ -4661,7 +4661,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
return this.$element.val(); return this.$element.val();
} }

View File

@ -4626,7 +4626,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
args = [true]; args = [true];
} }
@ -4646,7 +4646,7 @@ define('select2/core',[
var data = []; var data = [];
this.dataAdpater.current(function (currentData) { this.dataAdapter.current(function (currentData) {
data = currentData; data = currentData;
}); });
@ -4661,7 +4661,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
return this.$element.val(); return this.$element.val();
} }

View File

@ -1,5 +1,5 @@
/*! /*!
* Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 17:03:44 GMT * Select2 4.0.0-rc.1
* https://select2.github.io * https://select2.github.io
* *
* Released under the MIT license * Released under the MIT license
@ -5072,7 +5072,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
args = [true]; args = [true];
} }
@ -5092,7 +5092,7 @@ define('select2/core',[
var data = []; var data = [];
this.dataAdpater.current(function (currentData) { this.dataAdapter.current(function (currentData) {
data = currentData; data = currentData;
}); });
@ -5107,7 +5107,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
return this.$element.val(); return this.$element.val();
} }

File diff suppressed because one or more lines are too long

8
dist/js/select2.js vendored
View File

@ -1,5 +1,5 @@
/*! /*!
* Select2 4.0.0-rc.1 - Thu, 12 Mar 2015 17:03:44 GMT * Select2 4.0.0-rc.1
* https://select2.github.io * https://select2.github.io
* *
* Released under the MIT license * Released under the MIT license
@ -5072,7 +5072,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
args = [true]; args = [true];
} }
@ -5092,7 +5092,7 @@ define('select2/core',[
var data = []; var data = [];
this.dataAdpater.current(function (currentData) { this.dataAdapter.current(function (currentData) {
data = currentData; data = currentData;
}); });
@ -5107,7 +5107,7 @@ define('select2/core',[
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
return this.$element.val(); return this.$element.val();
} }

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{ {
"start": "/*!\n * Select2 <%= package.version %> - <%= vars.date %>\n * https://select2.github.io\n *\n * Released under the MIT license\n * https://github.com/select2/select2/blob/master/LICENSE.md\n */\n(function() { if (window.define) { var define = window.define; } if (window.require) { var require = window.require; } if (window.jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) { var define = jQuery.fn.select2.amd.define; var require = jQuery.fn.select2.amd.require; }", "start": "/*!\n * Select2 <%= package.version %>\n * https://select2.github.io\n *\n * Released under the MIT license\n * https://github.com/select2/select2/blob/master/LICENSE.md\n */\n(function() { if (window.define) { var define = window.define; } if (window.require) { var require = window.require; } if (window.jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) { var define = jQuery.fn.select2.amd.define; var require = jQuery.fn.select2.amd.require; }",
"end": "require('jquery.select2'); jQuery.fn.select2.amd = { define: define, require: require }; }());" "end": "require('jquery.select2'); jQuery.fn.select2.amd = { define: define, require: require }; }());"
} }

View File

@ -419,7 +419,7 @@ define([
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
args = [true]; args = [true];
} }
@ -439,7 +439,7 @@ define([
var data = []; var data = [];
this.dataAdpater.current(function (currentData) { this.dataAdapter.current(function (currentData) {
data = currentData; data = currentData;
}); });
@ -454,7 +454,7 @@ define([
); );
} }
if (args.length === 0) { if (args == null || args.length === 0) {
return this.$element.val(); return this.$element.val();
} }

19
tests/integration.html Normal file
View File

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="vendor/qunit-1.14.0.css" type="text/css" />
<link rel="stylesheet" href="../../dist/css/select2.css" type="text/css" />
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="vendor/qunit-1.14.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="helpers.js" type="text/javascript"></script>
<script src="integration/select2-methods.js" type="text/javascript"></script>
</body>
</html>

View File

@ -0,0 +1,139 @@
module('select2(data)');
var $ = require('jquery');
var Select2 = require('select2/core');
var Options = require('select2/options');
test('single default selection returned', function (assert) {
var $select = $(
'<select>' +
'<option>One</option>' +
'<option>Two</option>' +
'<option value="3" selected>Three</option>' +
'</select>'
);
var options = new Options({});
var select = new Select2($select, options);
var items = select.data();
assert.equal(
items.length,
1,
'The one selected item should be returned'
);
var first = items[0];
assert.equal(
first.id,
'3',
'The first option was correct'
);
assert.equal(
first.text,
'Three',
'The first option was correct'
);
});
test('multiple default selections returned', function (assert) {
var $select = $(
'<select multiple>' +
'<option selected>One</option>' +
'<option>Two</option>' +
'<option value="3" selected>Three</option>' +
'</select>'
);
var options = new Options({});
var select = new Select2($select, options);
var items = select.data();
assert.equal(
items.length,
2,
'The two selected items should be returned'
);
var first = items[0];
assert.equal(
first.id,
'One',
'The first option was correct'
);
var second = items[1];
assert.equal(
second.id,
'3',
'The option value should be pulled correctly'
);
});
module('select2(val)');
test('single value matches jquery value', function (assert) {
var $select = $(
'<select>' +
'<option>One</option>' +
'<option>Two</option>' +
'<option value="3" selected>Three</option>' +
'</select>'
);
var options = new Options({});
var select = new Select2($select, options);
var value = select.val();
assert.equal(
value,
'3',
'The value should match the option tag attribute'
);
assert.equal(
value,
$select.val(),
'The value should match the jquery value'
);
});
test('multiple value matches the jquery value', function (assert) {
var $select = $(
'<select multiple>' +
'<option selected>One</option>' +
'<option>Two</option>' +
'<option value="3" selected>Three</option>' +
'</select>'
);
var options = new Options({});
var select = new Select2($select, options);
var value = select.val();
assert.equal(
value.length,
2,
'Two options should be selected'
);
assert.deepEqual(
value,
['One', '3'],
'The values should match the option tag attribute'
);
assert.deepEqual(
value,
$select.val(),
'The values should match the jquery values'
);
});