Add tests for the multiple selection container
This commit is contained in:
parent
7fc195f70d
commit
43efd43d57
50
tests/selection/multiple-tests.js
Normal file
50
tests/selection/multiple-tests.js
Normal 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(), '');
|
||||
});
|
23
tests/selection/multiple.html
Normal file
23
tests/selection/multiple.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user