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

Add tests for the multiple selection container

This commit is contained in:
Kevin Brown 2014-11-26 20:50:39 -05:00
parent 7fc195f70d
commit 43efd43d57
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,50 @@
module('Selection containers - Multiple');
var MultipleSelection = require('select2/selection/multiple');
var $ = require('jquery');
var Options = require('select2/options');
var Utils = require('select2/utils');
var options = new Options({});
test('display uses templateSelection', function (assert) {
var called = false;
var templateOptions = new Options({
templateSelection: function (data) {
called = true;
return data.text;
}
});
var selection = new MultipleSelection(
$('#qunit-fixture .multiple'),
templateOptions
);
var out = selection.display({
text: 'test'
});
assert.ok(called);
assert.equal(out, 'test');
});
test('empty update clears the selection', function (assert) {
var selection = new MultipleSelection(
$('#qunit-fixture .multiple'),
options
);
var $selection = selection.render();
var $rendered = $selection.find('.select2-selection__rendered');
$rendered.text('testing');
selection.update([]);
assert.equal($rendered.text(), '');
});

View File

@ -0,0 +1,23 @@
<!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">
<select class="multiple" multiple="multiple">
<option>One</option>
<option>Two</option>
</select>
</div>
<script src="../vendor/qunit-1.14.0.js" type="text/javascript"></script>
<script src="../../vendor/almond-0.2.9.js" type="text/javascript"></script>
<script src="../../vendor/jquery-2.1.0.js" type="text/javascript"></script>
<script src="../../dist/js/select2.amd.js" type="text/javascript"></script>
<script src="multiple-tests.js" type="text/javascript"></script>
</body>
</html>