1
0
mirror of synced 2024-11-22 21:16:10 +03:00

Added tests for the single selection container

This commit is contained in:
Kevin Brown 2014-11-26 20:25:56 -05:00
parent 56d5778590
commit 4cab421966
2 changed files with 88 additions and 0 deletions

View 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');
});

View 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>