2019-08-08 04:16:45 +03:00
|
|
|
QUnit.module('Selection containers - Placeholders');
|
2015-01-09 18:04:21 +03:00
|
|
|
|
|
|
|
var Placeholder = require('select2/selection/placeholder');
|
|
|
|
var SingleSelection = require('select2/selection/single');
|
|
|
|
|
|
|
|
var $ = require('jquery');
|
|
|
|
var Options = require('select2/options');
|
|
|
|
var Utils = require('select2/utils');
|
|
|
|
|
|
|
|
var SinglePlaceholder = Utils.Decorate(SingleSelection, Placeholder);
|
|
|
|
|
2015-02-14 07:28:36 +03:00
|
|
|
var placeholderOptions = new Options({
|
2015-01-09 18:04:21 +03:00
|
|
|
placeholder: {
|
|
|
|
id: 'placeholder',
|
|
|
|
text: 'This is the placeholder'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('normalizing placeholder ignores objects', function (assert) {
|
2015-01-09 18:04:21 +03:00
|
|
|
var selection = new SinglePlaceholder(
|
|
|
|
$('#qunit-fixture .single'),
|
2015-02-14 07:28:36 +03:00
|
|
|
placeholderOptions
|
2015-01-09 18:04:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
var original = {
|
|
|
|
id: 'test',
|
|
|
|
text: 'testing'
|
|
|
|
};
|
|
|
|
|
|
|
|
var normalized = selection.normalizePlaceholder(original);
|
|
|
|
|
|
|
|
assert.equal(original, normalized);
|
|
|
|
});
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('normalizing placeholder gives object for string', function (assert) {
|
2015-01-09 18:04:21 +03:00
|
|
|
var selection = new SinglePlaceholder(
|
|
|
|
$('#qunit-fixture .single'),
|
2015-02-14 07:28:36 +03:00
|
|
|
placeholderOptions
|
2015-01-09 18:04:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
var normalized = selection.normalizePlaceholder('placeholder');
|
|
|
|
|
|
|
|
assert.equal(normalized.id, '');
|
|
|
|
assert.equal(normalized.text, 'placeholder');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('text is shown for placeholder option on single', function (assert) {
|
2015-01-09 18:04:21 +03:00
|
|
|
var selection = new SinglePlaceholder(
|
|
|
|
$('#qunit-fixture .single'),
|
2015-02-14 07:28:36 +03:00
|
|
|
placeholderOptions
|
2015-01-09 18:04:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
var $selection = selection.render();
|
|
|
|
|
|
|
|
selection.update([{
|
|
|
|
id: 'placeholder'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
assert.equal($selection.text(), 'This is the placeholder');
|
|
|
|
});
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('placeholder is shown when no options are selected', function (assert) {
|
2015-01-09 18:04:21 +03:00
|
|
|
var selection = new SinglePlaceholder(
|
|
|
|
$('#qunit-fixture .multiple'),
|
2015-02-14 07:28:36 +03:00
|
|
|
placeholderOptions
|
2015-01-09 18:04:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
var $selection = selection.render();
|
|
|
|
|
|
|
|
selection.update([]);
|
|
|
|
|
|
|
|
assert.equal($selection.text(), 'This is the placeholder');
|
|
|
|
});
|