|
@@ -6,31 +6,34 @@ var $ = require('jquery');
|
|
var Options = require('select2/options');
|
|
var Options = require('select2/options');
|
|
var Utils = require('select2/utils');
|
|
var Utils = require('select2/utils');
|
|
|
|
|
|
-function StubData () {
|
|
|
|
|
|
+function MaximumSelectionStub () {
|
|
this.called = false;
|
|
this.called = false;
|
|
this.currentData = [];
|
|
this.currentData = [];
|
|
}
|
|
}
|
|
|
|
|
|
-StubData.prototype.current = function (callback) {
|
|
|
|
|
|
+MaximumSelectionStub.prototype.current = function (callback) {
|
|
callback(this.currentData);
|
|
callback(this.currentData);
|
|
};
|
|
};
|
|
|
|
|
|
-StubData.prototype.val = function (val) {
|
|
|
|
|
|
+MaximumSelectionStub.prototype.val = function (val) {
|
|
this.currentData.push(val);
|
|
this.currentData.push(val);
|
|
};
|
|
};
|
|
|
|
|
|
-StubData.prototype.query = function (params, callback) {
|
|
|
|
|
|
+MaximumSelectionStub.prototype.query = function (params, callback) {
|
|
this.called = true;
|
|
this.called = true;
|
|
};
|
|
};
|
|
|
|
|
|
-var MaximumData = Utils.Decorate(StubData, MaximumSelectionLength);
|
|
|
|
|
|
+var MaximumSelectionData = Utils.Decorate(
|
|
|
|
+ MaximumSelectionStub,
|
|
|
|
+ MaximumSelectionLength
|
|
|
|
+);
|
|
|
|
|
|
test('0 never displays the notice', function (assert) {
|
|
test('0 never displays the notice', function (assert) {
|
|
var zeroOptions = new Options({
|
|
var zeroOptions = new Options({
|
|
maximumSelectionLength: 0
|
|
maximumSelectionLength: 0
|
|
});
|
|
});
|
|
|
|
|
|
- var data = new MaximumData(null, zeroOptions);
|
|
|
|
|
|
+ var data = new MaximumSelectionData(null, zeroOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -42,7 +45,7 @@ test('0 never displays the notice', function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, zeroOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, zeroOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -56,7 +59,7 @@ test('0 never displays the notice', function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, zeroOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, zeroOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -77,7 +80,7 @@ test('< 0 never displays the notice', function (assert) {
|
|
maximumSelectionLength: -1
|
|
maximumSelectionLength: -1
|
|
});
|
|
});
|
|
|
|
|
|
- var data = new MaximumData(null, negativeOptions);
|
|
|
|
|
|
+ var data = new MaximumSelectionData(null, negativeOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -89,7 +92,7 @@ test('< 0 never displays the notice', function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, negativeOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, negativeOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -103,7 +106,7 @@ test('< 0 never displays the notice', function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, negativeOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, negativeOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -123,7 +126,7 @@ test('triggers when >= 1 selection' , function (assert) {
|
|
var maxOfOneOptions = new Options({
|
|
var maxOfOneOptions = new Options({
|
|
maximumSelectionLength: 1
|
|
maximumSelectionLength: 1
|
|
});
|
|
});
|
|
- var data = new MaximumData(null, maxOfOneOptions);
|
|
|
|
|
|
+ var data = new MaximumSelectionData(null, maxOfOneOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -135,7 +138,7 @@ test('triggers when >= 1 selection' , function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, maxOfOneOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, maxOfOneOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(true, 'The event should be triggered.');
|
|
assert.ok(true, 'The event should be triggered.');
|
|
@@ -155,7 +158,7 @@ test('triggers when >= 2 selections' , function (assert) {
|
|
var maxOfTwoOptions = new Options({
|
|
var maxOfTwoOptions = new Options({
|
|
maximumSelectionLength: 2
|
|
maximumSelectionLength: 2
|
|
});
|
|
});
|
|
- var data = new MaximumData(null, maxOfTwoOptions);
|
|
|
|
|
|
+ var data = new MaximumSelectionData(null, maxOfTwoOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -167,7 +170,7 @@ test('triggers when >= 2 selections' , function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, maxOfTwoOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, maxOfTwoOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(false, 'No events should be triggered');
|
|
assert.ok(false, 'No events should be triggered');
|
|
@@ -181,7 +184,7 @@ test('triggers when >= 2 selections' , function (assert) {
|
|
|
|
|
|
assert.ok(data.called);
|
|
assert.ok(data.called);
|
|
|
|
|
|
- data = new MaximumData(null, maxOfTwoOptions);
|
|
|
|
|
|
+ data = new MaximumSelectionData(null, maxOfTwoOptions);
|
|
|
|
|
|
data.trigger = function () {
|
|
data.trigger = function () {
|
|
assert.ok(true, 'The event should be triggered.');
|
|
assert.ok(true, 'The event should be triggered.');
|
|
@@ -196,4 +199,4 @@ test('triggers when >= 2 selections' , function (assert) {
|
|
|
|
|
|
assert.ok(!data.called);
|
|
assert.ok(!data.called);
|
|
|
|
|
|
-});
|
|
|
|
|
|
+});
|