maximumSelectionLength-tests.js
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
module('Data adapters - Maximum selection length');
var SelectData = require('select2/data/select');
var MaximumSelectionLength = require('select2/data/maximumSelectionLength');
var $ = require('jquery');
var Options = require('select2/options');
var Utils = require('select2/utils');
var MaximumSelectionData = Utils.Decorate(SelectData, MaximumSelectionLength);
test('0 never displays the notice', function (assert) {
assert.expect(3);
var $select = $('#qunit-fixture .multiple');
var zeroOptions = new Options({
maximumSelectionLength: 0
});
var container = new MockContainer();
var data = new MaximumSelectionData($select, zeroOptions);
data.bind(container, null);
data.on('results:message', function () {
assert.ok(false, 'The message should not be displayed');
});
data.query({
term: ''
}, function () {
assert.ok(true, 'The results should be queried');
});
$select.val(['One']);
data.query({
term: ''
}, function () {
assert.ok(true, 'The results should be queried');
});
$select.val(['One', 'Two']);
data.query({
term: ''
}, function () {
assert.ok(true, 'The results should be queried');
});
});
test('< 0 never displays the notice', function (assert) {
assert.expect(3);
var $select = $('#qunit-fixture .multiple');
var negativeOptions = new Options({
maximumSelectionLength: -1
});
var container = new MockContainer();
var data = new MaximumSelectionData($select, negativeOptions);
data.bind(container, null);
data.on('results:message', function () {
assert.ok(false, 'The message should not be displayed');
});
data.query({
term: ''
}, function () {
assert.ok(true, 'The results should be queried');
});
$select.val(['One']);
data.query({
term: ''
}, function () {
assert.ok(true, 'The results should be queried');
});
$select.val(['One', 'Two']);
data.query({
term: ''
}, function () {
assert.ok(true, 'The results should be queried');
});
});
test('triggers when >= 1 selection' , function (assert) {
assert.expect(2);
var $select = $('#qunit-fixture .multiple');
var maxOfOneOptions = new Options({
maximumSelectionLength: 1
});
var container = new MockContainer();
var data = new MaximumSelectionData($select, maxOfOneOptions);
data.bind(container, null);
data.on('results:message', function () {
assert.ok(true, 'The message should be displayed');
});
$select.val(['One']);
data.query({
term: ''
}, function () {
assert.ok(false, 'The results should not be queried');
});
$select.val(['One', 'Two']);
data.query({
term: ''
}, function () {
assert.ok(false, 'The results should not be queried');
});
});
test('triggers after selection' , function (assert) {
assert.expect(1);
var $select = $('#qunit-fixture .multiple');
var maxOfOneOptions = new Options({
maximumSelectionLength: 1
});
var container = new MockContainer();
var data = new MaximumSelectionData($select, maxOfOneOptions);
data.bind(container, null);
data.on('results:message', function () {
assert.ok(true, 'The message should be displayed');
});
$select.val(['One']);
container.trigger('select', {
data: {}
});
});