Added tests for the single selection container
This commit is contained in:
parent
56d5778590
commit
4cab421966
66
tests/selection/single-tests.js
Normal file
66
tests/selection/single-tests.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
module('Selection containers - Single');
|
||||||
|
|
||||||
|
var SingleSelection = require('select2/selection/single');
|
||||||
|
|
||||||
|
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 SingleSelection(
|
||||||
|
$('#qunit-fixture .single'),
|
||||||
|
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 SingleSelection(
|
||||||
|
$('#qunit-fixture .single'),
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
var $selection = selection.render();
|
||||||
|
var $rendered = $selection.find('.select2-selection__rendered');
|
||||||
|
|
||||||
|
$rendered.text('testing');
|
||||||
|
|
||||||
|
selection.update([]);
|
||||||
|
|
||||||
|
assert.equal($rendered.text(), '');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('update renders the data text', function (assert) {
|
||||||
|
var selection = new SingleSelection(
|
||||||
|
$('#qunit-fixture .single'),
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
var $selection = selection.render();
|
||||||
|
var $rendered = $selection.find('.select2-selection__rendered');
|
||||||
|
|
||||||
|
selection.update([{
|
||||||
|
text: 'test'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
assert.equal($rendered.text(), 'test');
|
||||||
|
});
|
22
tests/selection/single.html
Normal file
22
tests/selection/single.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!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="single">
|
||||||
|
<option>One</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="single-tests.js" type="text/javascript"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user