2015-01-13 19:34:52 +03:00
|
|
|
module('Data adapters - Maximum selection length');
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var SelectData = require('select2/data/select');
|
2015-01-13 19:34:52 +03:00
|
|
|
var MaximumSelectionLength = require('select2/data/maximumSelectionLength');
|
|
|
|
|
|
|
|
var $ = require('jquery');
|
|
|
|
var Options = require('select2/options');
|
|
|
|
var Utils = require('select2/utils');
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var MaximumSelectionData = Utils.Decorate(SelectData, MaximumSelectionLength);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
test('0 never displays the notice', function (assert) {
|
|
|
|
assert.expect(3);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var $select = $('#qunit-fixture .multiple');
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
var zeroOptions = new Options({
|
|
|
|
maximumSelectionLength: 0
|
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var container = new MockContainer();
|
|
|
|
var data = new MaximumSelectionData($select, zeroOptions);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
data.bind(container, null);
|
|
|
|
|
|
|
|
data.on('results:message', function () {
|
|
|
|
assert.ok(false, 'The message should not be displayed');
|
|
|
|
});
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(true, 'The results should be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(true, 'The results should be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One', 'Two']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(true, 'The results should be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('< 0 never displays the notice', function (assert) {
|
2019-07-21 22:44:37 +03:00
|
|
|
assert.expect(3);
|
|
|
|
|
|
|
|
var $select = $('#qunit-fixture .multiple');
|
|
|
|
|
2015-01-13 19:34:52 +03:00
|
|
|
var negativeOptions = new Options({
|
|
|
|
maximumSelectionLength: -1
|
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var container = new MockContainer();
|
|
|
|
var data = new MaximumSelectionData($select, negativeOptions);
|
|
|
|
|
|
|
|
data.bind(container, null);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
data.on('results:message', function () {
|
|
|
|
assert.ok(false, 'The message should not be displayed');
|
|
|
|
});
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(true, 'The results should be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(true, 'The results should be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One', 'Two']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(true, 'The results should be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('triggers when >= 1 selection' , function (assert) {
|
2019-07-21 22:44:37 +03:00
|
|
|
assert.expect(2);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var $select = $('#qunit-fixture .multiple');
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var maxOfOneOptions = new Options({
|
|
|
|
maximumSelectionLength: 1
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var container = new MockContainer();
|
|
|
|
var data = new MaximumSelectionData($select, maxOfOneOptions);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
data.bind(container, null);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
data.on('results:message', function () {
|
|
|
|
assert.ok(true, 'The message should be displayed');
|
|
|
|
});
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(false, 'The results should not be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One', 'Two']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
|
|
|
data.query({
|
|
|
|
term: ''
|
2019-07-21 22:44:37 +03:00
|
|
|
}, function () {
|
|
|
|
assert.ok(false, 'The results should not be queried');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
2019-07-21 22:44:37 +03:00
|
|
|
});
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
test('triggers after selection' , function (assert) {
|
|
|
|
assert.expect(1);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var $select = $('#qunit-fixture .multiple');
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var maxOfOneOptions = new Options({
|
|
|
|
maximumSelectionLength: 1
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
var container = new MockContainer();
|
|
|
|
var data = new MaximumSelectionData($select, maxOfOneOptions);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
data.bind(container, null);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
data.on('results:message', function () {
|
|
|
|
assert.ok(true, 'The message should be displayed');
|
2015-01-13 19:34:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
$select.val(['One']);
|
2015-01-13 19:34:52 +03:00
|
|
|
|
2019-07-21 22:44:37 +03:00
|
|
|
container.trigger('select', {
|
|
|
|
data: {}
|
|
|
|
});
|
2015-02-14 07:28:36 +03:00
|
|
|
});
|