selectic 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,675 +7,692 @@ const _ = require('../tools.js');
7
7
  const StoreFile = require('../dist/Store.js');
8
8
  const Store = StoreFile.default;
9
9
 
10
- tape.test('change props', (subT) => {
11
- subT.test('"value"', (sTest) => {
12
- sTest.test('should change internalValue but not hasChanged', async (t) => {
13
- const propOptions = getOptions(15, 'alpha');
14
- propOptions[12].disabled = true;
10
+ const testValue = true;
11
+ const testOptions = true;
12
+ const testChild = true;
13
+ const testExclude = true;
14
+ const testDisabled = true;
15
15
 
16
- const store = new Store({
17
- options: propOptions,
18
- value: 1,
19
- });
20
-
21
- await _.nextVueTick(store);
22
- store.props.value = 23;
23
-
24
- await _.nextVueTick(store);
25
- t.is(store.state.internalValue, 23);
26
- t.is(store.state.status.hasChanged, false);
27
-
28
- store.props.value = 12;
29
- await _.nextVueTick(store);
30
-
31
- t.is(store.state.internalValue, 12);
32
- t.is(store.state.status.hasChanged, false);
33
-
34
- t.end();
35
- });
36
- });
16
+ tape.test('change props', (subT) => {
17
+ if (testValue) {
18
+ subT.test('"value"', (sTest) => {
19
+ sTest.test('should change internalValue but not hasChanged', async (t) => {
20
+ const propOptions = getOptions(15, 'alpha');
21
+ propOptions[12].disabled = true;
37
22
 
38
- subT.test('"options"', (sTest) => {
39
- sTest.test('should change options', async (t) => {
40
- const propOptions = getOptions(15, 'alpha', 2);
41
- const store = new Store({ options: propOptions });
42
- await _.nextVueTick(store);
23
+ const store = new Store({
24
+ options: propOptions,
25
+ value: 1,
26
+ });
43
27
 
44
- store.commit('isOpen', true);
45
- await _.nextVueTick(store);
28
+ await _.nextVueTick(store);
29
+ store.props.value = 23;
46
30
 
47
- t.is(store.state.allOptions.length, 15);
31
+ await _.nextVueTick(store);
32
+ t.is(store.state.internalValue, 23);
33
+ t.is(store.state.status.hasChanged, false);
48
34
 
49
- /* change options */
50
- store.props.options = getOptions(5, 'beta');
51
- await _.nextVueTick(store);
35
+ store.props.value = 12;
36
+ await _.nextVueTick(store);
52
37
 
53
- t.is(store.state.isOpen, false, 'should close the component');
38
+ t.is(store.state.internalValue, 12);
39
+ t.is(store.state.status.hasChanged, false);
54
40
 
55
- store.commit('isOpen', true);
56
- await _.nextVueTick(store);
57
- const firstOption = store.state.filteredOptions[0];
58
- const selectedOption = store.state.filteredOptions[2];
59
-
60
- t.is(store.state.allOptions.length, 5, 'should have updated allOptions');
61
- t.is(store.state.totalAllOptions, 5, 'should have updated totalAllOptions');
62
- t.is(store.state.filteredOptions.length, 5, 'should have updated filteredOptions');
63
- t.is(store.state.totalFilteredOptions, 5, 'should have updated totalFilteredOptions');
64
- t.is(store.state.internalValue, 2, 'should keep previous selected value');
65
- t.deepEqual(firstOption, {
66
- id: 0,
67
- text: 'beta0',
68
- disabled: false,
69
- selected: false,
70
- isGroup: false,
71
- });
72
- t.deepEqual(selectedOption, {
73
- id: 2,
74
- text: 'beta2',
75
- disabled: false,
76
- selected: true,
77
- isGroup: false,
41
+ t.end();
78
42
  });
79
- t.is(store.state.status.errorMessage, '');
80
- t.end();
81
43
  });
82
-
83
- sTest.test('should invalid selection in strictValue', async (t) => {
84
- const propOptions = getOptions(15, 'alpha');
85
- const store = new Store({
86
- options: propOptions,
87
- value: 7,
88
- params: {
89
- autoSelect: false,
90
- strictValue: true,
91
- },
44
+ }
45
+
46
+ if (testOptions) {
47
+ subT.test('"options"', (sTest) => {
48
+ sTest.test('should change options', async (t) => {
49
+ const propOptions = getOptions(15, 'alpha', 2);
50
+ const store = new Store({ options: propOptions });
51
+ await _.nextVueTick(store);
52
+
53
+ store.commit('isOpen', true);
54
+ await _.nextVueTick(store);
55
+
56
+ t.is(store.state.allOptions.length, 15);
57
+
58
+ /* change options */
59
+ store.props.options = getOptions(5, 'beta');
60
+ await _.nextVueTick(store);
61
+
62
+ t.is(store.state.isOpen, false, 'should close the component');
63
+
64
+ store.commit('isOpen', true);
65
+ await _.nextVueTick(store, _.sleep(0));
66
+ const firstOption = store.state.filteredOptions[0];
67
+ const selectedOption = store.state.filteredOptions[2];
68
+
69
+ t.is(store.state.allOptions.length, 5, 'should have updated allOptions');
70
+ t.is(store.state.totalAllOptions, 5, 'should have updated totalAllOptions');
71
+ t.is(store.state.filteredOptions.length, 5, 'should have updated filteredOptions');
72
+ t.is(store.state.totalFilteredOptions, 5, 'should have updated totalFilteredOptions');
73
+ t.is(store.state.internalValue, 2, 'should keep previous selected value');
74
+ t.deepEqual(firstOption, {
75
+ id: 0,
76
+ text: 'beta0',
77
+ disabled: false,
78
+ selected: false,
79
+ isGroup: false,
80
+ });
81
+ t.deepEqual(selectedOption, {
82
+ id: 2,
83
+ text: 'beta2',
84
+ disabled: false,
85
+ selected: true,
86
+ isGroup: false,
87
+ });
88
+ t.is(store.state.status.errorMessage, '');
89
+
90
+ t.end();
92
91
  });
93
- store.commit('isOpen', true);
94
-
95
- t.is(store.state.internalValue, 7);
96
-
97
- store.props.options = getOptions(5, 'beta');
98
92
 
99
- await _.nextVueTick(store);
100
- t.is(store.state.internalValue, null);
101
- t.end();
102
- });
103
-
104
- sTest.test('should keep valid selection in strictValue', async (t) => {
105
- const propOptions = getOptions(15, 'alpha');
106
- const store = new Store({
107
- options: propOptions,
108
- value: 3,
109
- params: {
110
- autoSelect: false,
111
- strictValue: true,
112
- },
93
+ sTest.test('should invalid selection in strictValue', async (t) => {
94
+ const propOptions = getOptions(15, 'alpha');
95
+ const store = new Store({
96
+ options: propOptions,
97
+ value: 7,
98
+ params: {
99
+ autoSelect: false,
100
+ strictValue: true,
101
+ },
102
+ });
103
+ store.commit('isOpen', true);
104
+
105
+ t.is(store.state.internalValue, 7);
106
+
107
+ store.props.options = getOptions(5, 'beta');
108
+
109
+ await _.nextVueTick(store);
110
+ t.is(store.state.internalValue, null);
111
+ t.end();
113
112
  });
114
- store.commit('isOpen', true);
115
-
116
- t.is(store.state.internalValue, 3);
117
113
 
118
- store.props.options = getOptions(5, 'beta');
119
-
120
- await _.nextVueTick(store);
121
- t.is(store.state.internalValue, 3);
122
- t.end();
123
- });
124
-
125
- sTest.test('should accept new selection in strictValue', async (t) => {
126
- const propOptions = getOptions(5, 'alpha');
127
- const store = new Store({
128
- options: propOptions,
129
- value: 3,
130
- params: {
131
- autoSelect: false,
132
- strictValue: true,
133
- },
114
+ sTest.test('should keep valid selection in strictValue', async (t) => {
115
+ const propOptions = getOptions(15, 'alpha');
116
+ const store = new Store({
117
+ options: propOptions,
118
+ value: 3,
119
+ params: {
120
+ autoSelect: false,
121
+ strictValue: true,
122
+ },
123
+ });
124
+ store.commit('isOpen', true);
125
+
126
+ t.is(store.state.internalValue, 3);
127
+
128
+ store.props.options = getOptions(5, 'beta');
129
+
130
+ await _.nextVueTick(store);
131
+ t.is(store.state.internalValue, 3);
132
+ t.end();
134
133
  });
135
- store.commit('isOpen', true);
136
- await _.nextVueTick(store);
137
- store.props.options = getOptions(10, 'beta');
138
- await _.nextVueTick(store);
139
-
140
- store.props.value = 7;
141
-
142
- await _.nextVueTick(store);
143
- t.is(store.state.internalValue, 7);
144
- t.end();
145
- });
146
134
 
147
- sTest.test('should update selection in strictValue and multiple', async (t) => {
148
- const propOptions = getOptions(15, 'alpha');
149
- const store = new Store({
150
- options: propOptions,
151
- value: [3, 7, 11],
152
- params: {
153
- autoSelect: false,
154
- strictValue: true,
155
- multiple: true,
156
- },
135
+ sTest.test('should accept new selection in strictValue', async (t) => {
136
+ const propOptions = getOptions(5, 'alpha');
137
+ const store = new Store({
138
+ options: propOptions,
139
+ value: 3,
140
+ params: {
141
+ autoSelect: false,
142
+ strictValue: true,
143
+ },
144
+ });
145
+ store.commit('isOpen', true);
146
+ await _.nextVueTick(store);
147
+ store.props.options = getOptions(10, 'beta');
148
+ await _.nextVueTick(store);
149
+
150
+ store.props.value = 7;
151
+
152
+ await _.nextVueTick(store);
153
+ t.is(store.state.internalValue, 7);
154
+ t.end();
157
155
  });
158
- store.commit('isOpen', true);
159
- await _.nextVueTick(store);
160
-
161
- t.deepEqual(store.state.internalValue, [3, 7, 11]);
162
-
163
- store.props.options = getOptions(10, 'beta');
164
- await _.nextVueTick(store);
165
- t.deepEqual(store.state.internalValue, [3, 7]);
166
-
167
- store.props.options = getOptions(5, 'gamma');
168
-
169
- await _.nextVueTick(store);
170
- t.deepEqual(store.state.internalValue, [3]);
171
- t.end();
172
- });
173
156
 
174
- sTest.test('should update selection', async (t) => {
175
- const propOptions = getOptions(15, 'alpha');
176
- const store = new Store({
177
- options: propOptions,
178
- value: 7,
179
- params: {
180
- autoSelect: false,
181
- strictValue: false,
182
- },
157
+ sTest.test('should update selection in strictValue and multiple', async (t) => {
158
+ const propOptions = getOptions(15, 'alpha');
159
+ const store = new Store({
160
+ options: propOptions,
161
+ value: [3, 7, 11],
162
+ params: {
163
+ autoSelect: false,
164
+ strictValue: true,
165
+ multiple: true,
166
+ },
167
+ });
168
+ store.commit('isOpen', true);
169
+ await _.nextVueTick(store);
170
+
171
+ t.deepEqual(store.state.internalValue, [3, 7, 11]);
172
+
173
+ store.props.options = getOptions(10, 'beta');
174
+ await _.nextVueTick(store);
175
+ t.deepEqual(store.state.internalValue, [3, 7]);
176
+
177
+ store.props.options = getOptions(5, 'gamma');
178
+
179
+ await _.nextVueTick(store);
180
+ t.deepEqual(store.state.internalValue, [3]);
181
+ t.end();
183
182
  });
184
- await _.nextVueTick(store);
185
- store.commit('isOpen', true);
186
-
187
- await _.nextVueTick(store);
188
- t.is(store.state.selectedOptions.text, 'alpha7');
189
-
190
- store.props.options = getOptions(10, 'beta');
191
- await _.deferPromise(_.nextVueTick(store));
192
-
193
- t.is(store.state.selectedOptions.text, 'beta7');
194
- t.end();
195
- });
196
183
 
197
- sTest.test('should disable the select when only one option is given', async (t) => {
198
- const store = new Store({
199
- options: getOptions(5, 'alpha'),
200
- params: {
201
- autoDisabled: true,
202
- },
184
+ sTest.test('should update selection', async (t) => {
185
+ const propOptions = getOptions(15, 'alpha');
186
+ const store = new Store({
187
+ options: propOptions,
188
+ value: 7,
189
+ params: {
190
+ autoSelect: false,
191
+ strictValue: false,
192
+ },
193
+ });
194
+ await _.nextVueTick(store);
195
+ store.commit('isOpen', true);
196
+
197
+ await _.nextVueTick(store);
198
+ t.is(store.state.selectedOptions.text, 'alpha7');
199
+
200
+ store.props.options = getOptions(10, 'beta');
201
+ await _.deferPromise(_.nextVueTick(store));
202
+
203
+ t.is(store.state.selectedOptions.text, 'beta7');
204
+ t.end();
203
205
  });
204
- await _.nextVueTick(store);
205
-
206
- store.commit('isOpen', true);
207
- await _.nextVueTick(store);
208
-
209
- t.is(store.state.internalValue, 0);
210
- t.is(store.state.disabled, false);
211
- t.is(store.state.isOpen, true);
212
-
213
- store.props.options = getOptions(1, 'beta');
214
- await _.nextVueTick(store);
215
-
216
- t.is(store.state.internalValue, 0, 'should keep the correct value selected');
217
- t.is(store.state.disabled, true, 'should disable the component');
218
- t.is(store.state.isOpen, false, 'should close the component');
219
- t.end();
220
- });
221
206
 
222
- sTest.test('should not disable the select with an invalid value', async (t) => {
223
- const store = new Store({
224
- value: 2,
225
- options: getOptions(5, 'alpha'),
226
- disabled: false,
227
- params: {
228
- autoDisabled: true,
229
- },
207
+ sTest.test('should disable the select when only one option is given', async (t) => {
208
+ const store = new Store({
209
+ options: getOptions(5, 'alpha'),
210
+ params: {
211
+ autoDisabled: true,
212
+ },
213
+ });
214
+ await _.nextVueTick(store);
215
+
216
+ store.commit('isOpen', true);
217
+ await _.nextVueTick(store);
218
+
219
+ t.is(store.state.internalValue, 0);
220
+ t.is(store.state.disabled, false);
221
+ t.is(store.state.isOpen, true);
222
+
223
+ store.props.options = getOptions(1, 'beta');
224
+ await _.nextVueTick(store);
225
+
226
+ t.is(store.state.internalValue, 0, 'should keep the correct value selected');
227
+ t.is(store.state.disabled, true, 'should disable the component');
228
+ t.is(store.state.isOpen, false, 'should close the component');
229
+ t.end();
230
230
  });
231
- await _.nextVueTick(store);
232
-
233
- store.commit('isOpen', true);
234
- await _.nextVueTick(store);
235
-
236
- t.is(store.state.internalValue, 2);
237
- t.is(store.state.disabled, false);
238
- t.is(store.state.isOpen, true);
239
231
 
240
- store.props.options = getOptions(1, 'beta', 6);
241
- await _.nextVueTick(store);
242
-
243
- t.is(store.state.internalValue, 2, 'should keep the invalid value');
244
- t.is(store.state.disabled, false, 'should not disable the component');
245
- t.is(store.state.isOpen, false, 'should close the component');
246
- t.end();
247
- });
248
-
249
- sTest.test('should disable the select with an invalid value in strict mode', async (t) => {
250
- const store = new Store({
251
- value: 2,
252
- options: getOptions(5, 'alpha'),
253
- disabled: false,
254
- params: {
255
- autoDisabled: true,
256
- strictValue: true,
257
- autoSelect: true,
258
- },
232
+ sTest.test('should not disable the select with an invalid value', async (t) => {
233
+ const store = new Store({
234
+ value: 2,
235
+ options: getOptions(5, 'alpha'),
236
+ disabled: false,
237
+ params: {
238
+ autoDisabled: true,
239
+ },
240
+ });
241
+ await _.nextVueTick(store);
242
+
243
+ store.commit('isOpen', true);
244
+ await _.nextVueTick(store);
245
+
246
+ t.is(store.state.internalValue, 2);
247
+ t.is(store.state.disabled, false);
248
+ t.is(store.state.isOpen, true);
249
+
250
+ store.props.options = getOptions(1, 'beta', 6);
251
+ await _.nextVueTick(store);
252
+
253
+ t.is(store.state.internalValue, 2, 'should keep the invalid value');
254
+ t.is(store.state.disabled, false, 'should not disable the component');
255
+ t.is(store.state.isOpen, false, 'should close the component');
256
+ t.end();
259
257
  });
260
- await _.nextVueTick(store);
261
-
262
- store.commit('isOpen', true);
263
- await _.nextVueTick(store);
264
-
265
- t.is(store.state.internalValue, 2);
266
- t.is(store.state.disabled, false);
267
- t.is(store.state.isOpen, true);
268
258
 
269
- store.props.options = getOptions(1, 'beta', 6);
270
- await _.nextVueTick(store);
271
-
272
- t.is(store.state.internalValue, 6, 'should have auto-selected the first value');
273
- t.is(store.state.disabled, true, 'should disable the component');
274
- t.is(store.state.isOpen, false, 'should have close the component');
275
- t.end();
276
- });
277
-
278
- sTest.test('should enable the select when more options are given', async (t) => {
279
- const store = new Store({
280
- options: getOptions(1, 'alpha', 1),
281
- params: {
282
- autoDisabled: true,
283
- },
259
+ sTest.test('should disable the select with an invalid value in strict mode', async (t) => {
260
+ const store = new Store({
261
+ value: 2,
262
+ options: getOptions(5, 'alpha'),
263
+ disabled: false,
264
+ params: {
265
+ autoDisabled: true,
266
+ strictValue: true,
267
+ autoSelect: true,
268
+ },
269
+ });
270
+ await _.nextVueTick(store);
271
+
272
+ store.commit('isOpen', true);
273
+ await _.nextVueTick(store);
274
+
275
+ t.is(store.state.internalValue, 2);
276
+ t.is(store.state.disabled, false);
277
+ t.is(store.state.isOpen, true);
278
+
279
+ store.props.options = getOptions(1, 'beta', 6);
280
+ await _.nextVueTick(store);
281
+
282
+ t.is(store.state.internalValue, 6, 'should have auto-selected the first value');
283
+ t.is(store.state.disabled, true, 'should disable the component');
284
+ t.is(store.state.isOpen, false, 'should have close the component');
285
+ t.end();
284
286
  });
285
- await _.nextVueTick(store);
286
-
287
- store.commit('isOpen', true);
288
- await _.nextVueTick(store);
289
287
 
290
- t.is(store.state.internalValue, 1);
291
- t.is(store.state.disabled, true);
292
- t.is(store.state.isOpen, false);
293
-
294
- store.props.options = getOptions(5, 'beta');
295
- await _.nextVueTick(store);
296
-
297
- t.is(store.state.internalValue, 1, 'should keep selected value');
298
- t.is(store.state.disabled, false, 'should enable the component');
299
- t.is(store.state.isOpen, false, 'should close the component anyway');
300
- t.end();
301
- });
302
-
303
- sTest.test('should re-enable the select when data are loaded', async (t) => {
304
- const store = new Store({
305
- options: [],
306
- disabled: false,
307
- params: {
308
- autoDisabled: true,
309
- },
288
+ sTest.test('should enable the select when more options are given', async (t) => {
289
+ const store = new Store({
290
+ options: getOptions(1, 'alpha', 1),
291
+ params: {
292
+ autoDisabled: true,
293
+ },
294
+ });
295
+ await _.nextVueTick(store);
296
+
297
+ store.commit('isOpen', true);
298
+ await _.nextVueTick(store);
299
+
300
+ t.is(store.state.internalValue, 1);
301
+ t.is(store.state.disabled, true);
302
+ t.is(store.state.isOpen, false);
303
+
304
+ store.props.options = getOptions(5, 'beta');
305
+ await _.nextVueTick(store);
306
+
307
+ t.is(store.state.internalValue, 1, 'should keep selected value');
308
+ t.is(store.state.disabled, false, 'should enable the component');
309
+ t.is(store.state.isOpen, false, 'should close the component anyway');
310
+ t.end();
310
311
  });
311
- await _.nextVueTick(store);
312
312
 
313
- store.commit('isOpen', true);
314
- await _.nextVueTick(store);
313
+ sTest.test('should re-enable the select when data are loaded', async (t) => {
314
+ const store = new Store({
315
+ options: [],
316
+ disabled: false,
317
+ params: {
318
+ autoDisabled: true,
319
+ },
320
+ });
321
+ await _.nextVueTick(store);
315
322
 
316
- t.is(store.state.internalValue, null);
317
- t.is(store.state.disabled, true);
318
- t.is(store.state.isOpen, false);
323
+ store.commit('isOpen', true);
324
+ await _.nextVueTick(store);
319
325
 
320
- store.props.options = getOptions(0, 'alpha');
321
- await _.nextVueTick(store);
326
+ t.is(store.state.internalValue, null);
327
+ t.is(store.state.disabled, true);
328
+ t.is(store.state.isOpen, false);
322
329
 
323
- t.is(store.state.internalValue, null);
324
- t.is(store.state.disabled, true), 'should be disabled';
330
+ store.props.options = getOptions(0, 'alpha');
331
+ await _.nextVueTick(store);
325
332
 
326
- store.props.options = getOptions(5, 'beta');
327
- await _.nextVueTick(store);
333
+ t.is(store.state.internalValue, null);
334
+ t.is(store.state.disabled, true), 'should be disabled';
328
335
 
329
- t.is(store.state.internalValue, 0);
330
- t.is(store.state.disabled, false), 'should be enabled';
331
- t.end();
332
- });
336
+ store.props.options = getOptions(5, 'beta');
337
+ await _.nextVueTick(store);
333
338
 
334
- sTest.test('should not re-enable the select if disable is set', async (t) => {
335
- const store = new Store({
336
- options: getOptions(1, 'alpha'),
337
- disabled: true,
338
- params: {
339
- autoDisabled: true,
340
- },
339
+ t.is(store.state.internalValue, 0);
340
+ t.is(store.state.disabled, false), 'should be enabled';
341
+ t.end();
341
342
  });
342
- await _.nextVueTick(store);
343
343
 
344
- store.commit('isOpen', true);
345
- await _.nextVueTick(store);
346
-
347
- t.is(store.state.internalValue, 0);
348
- t.is(store.state.disabled, true);
349
- t.is(store.state.isOpen, false);
350
-
351
- store.props.options = getOptions(5, 'beta');
352
- await _.nextVueTick(store);
353
-
354
- t.is(store.state.internalValue, 0);
355
- t.is(store.state.disabled, true);
356
- t.is(store.state.isOpen, false);
357
- t.end();
358
- });
359
-
360
- sTest.test('should fallback to next option source', async (t) => {
361
- const command = {};
362
- const spy = {};
363
-
364
- const store = new Store({
365
- options: getOptions(10),
366
- childOptions: getOptions(2, '', 10),
367
- fetchCallback: buildFetchCb({ total: 4, command, spy }),
368
- params: {
369
- optionBehavior: 'force-ODE',
370
- },
344
+ sTest.test('should not re-enable the select if disable is set', async (t) => {
345
+ const store = new Store({
346
+ options: getOptions(1, 'alpha'),
347
+ disabled: true,
348
+ params: {
349
+ autoDisabled: true,
350
+ },
351
+ });
352
+ await _.nextVueTick(store);
353
+
354
+ store.commit('isOpen', true);
355
+ await _.nextVueTick(store);
356
+
357
+ t.is(store.state.internalValue, 0);
358
+ t.is(store.state.disabled, true);
359
+ t.is(store.state.isOpen, false);
360
+
361
+ store.props.options = getOptions(5, 'beta');
362
+ await _.nextVueTick(store);
363
+
364
+ t.is(store.state.internalValue, 0);
365
+ t.is(store.state.disabled, true);
366
+ t.is(store.state.isOpen, false);
367
+ t.end();
371
368
  });
372
- store.commit('isOpen', true);
373
- await _.nextVueTick(store);
374
- t.is(store.state.filteredOptions.length, 10);
375
-
376
- store.props.options = [];
377
- await _.nextVueTick(store);
378
- store.commit('isOpen', true);
379
- await _.sleep(0);
380
- command.fetch();
381
- await _.nextVueTick(store, spy.promise);
382
-
383
- t.is(store.state.filteredOptions.length, 4, 'should fallback to dynamic options');
384
369
 
385
- store.props.options = getOptions(3);
386
- await _.nextVueTick(store);
387
- store.commit('isOpen', true);
388
- await _.nextVueTick(store);
389
-
390
- t.is(store.state.filteredOptions.length, 3, 'should get back to static options');
391
- t.end();
392
- });
393
- });
394
-
395
- subT.test('"childOptions"', (sTest) => {
396
- sTest.test('should change childOptions', async (t) => {
397
- const propOptions = getOptions(15, 'alpha', 1);
398
- const store = new Store({ childOptions: propOptions });
399
- await _.nextVueTick(store);
400
-
401
- store.commit('isOpen', true);
402
- await _.nextVueTick(store);
403
-
404
- t.is(store.state.allOptions.length, 15);
405
-
406
- store.props.childOptions = getOptions(5, 'beta');
407
- await _.nextVueTick(store);
408
-
409
- t.is(store.state.isOpen, false, 'should close component');
410
-
411
- store.commit('isOpen', true);
412
- await _.nextVueTick(store);
413
- const secondOption = store.state.filteredOptions[1];
414
-
415
- t.is(store.state.allOptions.length, 5, 'should have updated allOptions');
416
- t.is(store.state.totalAllOptions, 5, 'should have updated totalAllOptions');
417
- t.is(store.state.filteredOptions.length, 5, 'should have updated filteredOptions');
418
- t.is(store.state.totalFilteredOptions, 5, 'should have updated totalFilteredOptions');
419
- t.is(store.state.internalValue, 1, 'should have kept previous selected value');
420
- t.deepEqual(secondOption, {
421
- id: 1,
422
- text: 'beta1',
423
- disabled: false,
424
- selected: true,
425
- isGroup: false,
370
+ sTest.test('should fallback to next option source', async (t) => {
371
+ const command = {};
372
+ const spy = {};
373
+
374
+ const store = new Store({
375
+ options: getOptions(10),
376
+ childOptions: getOptions(2, '', 10),
377
+ fetchCallback: buildFetchCb({ total: 4, command, spy }),
378
+ params: {
379
+ optionBehavior: 'force-ODE',
380
+ },
381
+ });
382
+ store.commit('isOpen', true);
383
+ await _.nextVueTick(store);
384
+ t.is(store.state.filteredOptions.length, 10);
385
+
386
+ store.props.options = [];
387
+ await _.nextVueTick(store);
388
+ store.commit('isOpen', true);
389
+ await _.sleep(0);
390
+ command.fetch();
391
+ await _.nextVueTick(store, spy.promise, _.sleep(0) /* await request resolution */);
392
+
393
+ t.is(store.state.filteredOptions.length, 4, 'should fallback to dynamic options');
394
+
395
+ store.props.options = getOptions(3);
396
+ await _.nextVueTick(store);
397
+ store.commit('isOpen', true);
398
+ await _.nextVueTick(store);
399
+
400
+ t.is(store.state.filteredOptions.length, 3, 'should get back to static options');
401
+ t.end();
426
402
  });
427
- t.is(store.state.status.errorMessage, '');
428
- t.end();
429
403
  });
430
-
431
- sTest.test('should update selection', async (t) => {
432
- const propOptions = getOptions(15, 'alpha');
433
- const store = new Store({
434
- childOptions: propOptions,
435
- value: 7,
436
- params: {
437
- autoSelect: false,
438
- strictValue: false,
439
- },
404
+ }
405
+
406
+ if (testChild) {
407
+ subT.test('"childOptions"', (sTest) => {
408
+ sTest.test('should change childOptions', async (t) => {
409
+ const propOptions = getOptions(15, 'alpha', 1);
410
+ const store = new Store({ childOptions: propOptions });
411
+ await _.nextVueTick(store);
412
+
413
+ store.commit('isOpen', true);
414
+ await _.nextVueTick(store);
415
+
416
+ t.is(store.state.allOptions.length, 15);
417
+
418
+ store.props.childOptions = getOptions(5, 'beta');
419
+ await _.nextVueTick(store);
420
+
421
+ t.is(store.state.isOpen, false, 'should close component');
422
+
423
+ store.commit('isOpen', true);
424
+ await _.nextVueTick(store);
425
+ const secondOption = store.state.filteredOptions[1];
426
+
427
+ t.is(store.state.allOptions.length, 5, 'should have updated allOptions');
428
+ t.is(store.state.totalAllOptions, 5, 'should have updated totalAllOptions');
429
+ t.is(store.state.filteredOptions.length, 5, 'should have updated filteredOptions');
430
+ t.is(store.state.totalFilteredOptions, 5, 'should have updated totalFilteredOptions');
431
+ t.is(store.state.internalValue, 1, 'should have kept previous selected value');
432
+ t.deepEqual(secondOption, {
433
+ id: 1,
434
+ text: 'beta1',
435
+ disabled: false,
436
+ selected: true,
437
+ isGroup: false,
438
+ });
439
+ t.is(store.state.status.errorMessage, '');
440
+ t.end();
440
441
  });
441
- await _.nextVueTick(store);
442
- store.commit('isOpen', true);
443
442
 
444
- await _.nextVueTick(store);
445
- t.is(store.state.selectedOptions.text, 'alpha7');
446
-
447
- store.props.childOptions = getOptions(10, 'beta');
448
- await _.deferPromise(_.nextVueTick(store));
449
-
450
- t.is(store.state.selectedOptions.text, 'beta7');
451
- t.end();
452
- });
453
-
454
- sTest.test('should disable the select when only one option is given', async (t) => {
455
- const store = new Store({
456
- childOptions: getOptions(5, 'alpha'),
457
- params: {
458
- autoDisabled: true,
459
- },
443
+ sTest.test('should update selection', async (t) => {
444
+ const propOptions = getOptions(15, 'alpha');
445
+ const store = new Store({
446
+ childOptions: propOptions,
447
+ value: 7,
448
+ params: {
449
+ autoSelect: false,
450
+ strictValue: false,
451
+ },
452
+ });
453
+ await _.nextVueTick(store);
454
+ store.commit('isOpen', true);
455
+
456
+ await _.nextVueTick(store);
457
+ t.is(store.state.selectedOptions.text, 'alpha7');
458
+
459
+ store.props.childOptions = getOptions(10, 'beta');
460
+ await _.deferPromise(_.nextVueTick(store));
461
+
462
+ t.is(store.state.selectedOptions.text, 'beta7');
463
+ t.end();
460
464
  });
461
- await _.nextVueTick(store);
462
-
463
- store.commit('isOpen', true);
464
- await _.nextVueTick(store);
465
-
466
- t.is(store.state.internalValue, 0);
467
- t.is(store.state.disabled, false);
468
- t.is(store.state.isOpen, true);
469
-
470
- store.props.childOptions = getOptions(1, 'beta');
471
- await _.nextVueTick(store);
472
465
 
473
- t.is(store.state.internalValue, 0);
474
- t.is(store.state.disabled, true);
475
- t.is(store.state.isOpen, false);
476
- t.end();
477
- });
478
-
479
- sTest.test('should enable the select when more options are given', async (t) => {
480
- const store = new Store({
481
- childOptions: getOptions(1, 'alpha'),
482
- params: {
483
- autoDisabled: true,
484
- },
466
+ sTest.test('should disable the select when only one option is given', async (t) => {
467
+ const store = new Store({
468
+ childOptions: getOptions(5, 'alpha'),
469
+ params: {
470
+ autoDisabled: true,
471
+ },
472
+ });
473
+ await _.nextVueTick(store);
474
+
475
+ store.commit('isOpen', true);
476
+ await _.nextVueTick(store);
477
+
478
+ t.is(store.state.internalValue, 0);
479
+ t.is(store.state.disabled, false);
480
+ t.is(store.state.isOpen, true);
481
+
482
+ store.props.childOptions = getOptions(1, 'beta');
483
+ await _.nextVueTick(store);
484
+
485
+ t.is(store.state.internalValue, 0);
486
+ t.is(store.state.disabled, true);
487
+ t.is(store.state.isOpen, false);
488
+ t.end();
485
489
  });
486
- await _.nextVueTick(store);
487
490
 
488
- store.commit('isOpen', true);
489
- await _.nextVueTick(store);
491
+ sTest.test('should enable the select when more options are given', async (t) => {
492
+ const store = new Store({
493
+ childOptions: getOptions(1, 'alpha'),
494
+ params: {
495
+ autoDisabled: true,
496
+ },
497
+ });
498
+ await _.nextVueTick(store);
499
+
500
+ store.commit('isOpen', true);
501
+ await _.nextVueTick(store);
502
+
503
+ t.is(store.state.internalValue, 0);
504
+ t.is(store.state.disabled, true);
505
+ t.is(store.state.isOpen, false);
506
+
507
+ store.props.childOptions = getOptions(5, 'beta');
508
+ await _.nextVueTick(store);
509
+
510
+ t.is(store.state.internalValue, 0);
511
+ t.is(store.state.disabled, false);
512
+ t.is(store.state.isOpen, false);
513
+ t.end();
514
+ });
490
515
 
491
- t.is(store.state.internalValue, 0);
492
- t.is(store.state.disabled, true);
493
- t.is(store.state.isOpen, false);
516
+ sTest.test('should disable the select when only one option is available for all sources', async (t) => {
517
+ const alphaOptions = getOptions(1, 'alpha');
518
+ const bravoOptions = getOptions(1, 'bravo');
519
+ const store = new Store({
520
+ options: alphaOptions,
521
+ childOptions: bravoOptions,
522
+ params: {
523
+ autoDisabled: true,
524
+ },
525
+ });
526
+ await _.nextVueTick(store);
527
+
528
+ store.commit('isOpen', true);
529
+ await _.nextVueTick(store);
530
+
531
+ /* options 1
532
+ * child 1
533
+ */
534
+ t.is(store.state.disabled, false);
535
+ t.is(store.state.isOpen, true);
536
+
537
+ /* options 1 disabled
538
+ * child 1
539
+ */
540
+ const charlyOptions = getOptions(1, 'charly');
541
+ charlyOptions[0].disabled = true;
542
+ store.props.options = charlyOptions;
543
+ await _.nextVueTick(store);
544
+
545
+ t.is(store.state.disabled, true);
546
+ t.is(store.state.isOpen, false);
547
+
548
+ store.props.options = alphaOptions;
549
+ await _.nextVueTick(store);
550
+ store.commit('isOpen', true);
551
+ await _.nextVueTick(store);
552
+
553
+ /* options 0
554
+ * child 1
555
+ */
556
+ store.props.options = getOptions(0, 'delta');
557
+ await _.nextVueTick(store);
558
+
559
+ t.is(store.state.disabled, true);
560
+ t.is(store.state.isOpen, false);
561
+
562
+ store.props.options = alphaOptions;
563
+ await _.nextVueTick(store);
564
+ store.commit('isOpen', true);
565
+ await _.nextVueTick(store);
566
+
567
+ /* options 1
568
+ * child 1 disabled
569
+ */
570
+ const echoOptions = getOptions(1, 'echo');
571
+ echoOptions[0].disabled = true;
572
+ store.props.childOptions = echoOptions;
573
+ await _.nextVueTick(store);
574
+
575
+ t.is(store.state.disabled, true);
576
+ t.is(store.state.isOpen, false);
577
+
578
+ store.props.childOptions = bravoOptions;
579
+ await _.nextVueTick(store);
580
+ store.commit('isOpen', true);
581
+ await _.nextVueTick(store);
582
+
583
+ /* options 1
584
+ * child 0
585
+ */
586
+ store.props.childOptions = getOptions(0, 'fox');
587
+ await _.nextVueTick(store);
588
+
589
+ t.is(store.state.disabled, true);
590
+ t.is(store.state.isOpen, false);
591
+
592
+ t.end();
593
+ });
494
594
 
495
- store.props.childOptions = getOptions(5, 'beta');
496
- await _.nextVueTick(store);
595
+ sTest.test('should not re-enable the select if disable is set', async (t) => {
596
+ const store = new Store({
597
+ childOptions: getOptions(1, 'alpha'),
598
+ disabled: true,
599
+ params: {
600
+ autoDisabled: true,
601
+ },
602
+ });
603
+ await _.nextVueTick(store);
604
+
605
+ store.commit('isOpen', true);
606
+ await _.nextVueTick(store);
607
+
608
+ t.is(store.state.internalValue, 0);
609
+ t.is(store.state.disabled, true);
610
+ t.is(store.state.isOpen, false);
611
+
612
+ store.props.childOptions = getOptions(5, 'beta');
613
+ await _.nextVueTick(store);
614
+
615
+ t.is(store.state.internalValue, 0);
616
+ t.is(store.state.disabled, true);
617
+ t.is(store.state.isOpen, false);
618
+ t.end();
619
+ });
497
620
 
498
- t.is(store.state.internalValue, 0);
499
- t.is(store.state.disabled, false);
500
- t.is(store.state.isOpen, false);
501
- t.end();
621
+ sTest.test('should fallback to next option source', async (t) => {
622
+ const command = {};
623
+ const spy = {};
624
+
625
+ const store = new Store({
626
+ options: getOptions(10),
627
+ childOptions: getOptions(2, '', 10),
628
+ fetchCallback: buildFetchCb({ total: 4, command, spy }),
629
+ params: {
630
+ optionBehavior: 'force-EDO',
631
+ },
632
+ });
633
+ store.commit('isOpen', true);
634
+ await _.nextVueTick(store);
635
+ t.is(store.state.filteredOptions.length, 2);
636
+
637
+ store.props.childOptions = [];
638
+ await _.nextVueTick(store);
639
+ store.commit('isOpen', true);
640
+ await _.sleep(0);
641
+ command.fetch();
642
+ await _.nextVueTick(store, spy.promise, _.sleep(0) /* await request resolution */);
643
+
644
+ t.is(store.state.filteredOptions.length, 4, 'should fallback to dynamic options');
645
+
646
+ store.props.childOptions = getOptions(2);
647
+ await _.nextVueTick(store);
648
+ store.commit('isOpen', true);
649
+ await _.nextVueTick(store);
650
+
651
+ t.is(store.state.filteredOptions.length, 2, 'should get back to element options');
652
+ t.end();
653
+ });
502
654
  });
655
+ }
503
656
 
504
- sTest.test('should disable the select when only one option is available for all sources', async (t) => {
505
- const alphaOptions = getOptions(1, 'alpha');
506
- const bravoOptions = getOptions(1, 'bravo');
657
+ if (testExclude) {
658
+ subT.test('should change "selectionIsExcluded"', async (t) => {
507
659
  const store = new Store({
508
- options: alphaOptions,
509
- childOptions: bravoOptions,
660
+ fetchCallback: buildFetchCb({ total: 5 }),
661
+ selectionIsExcluded: false,
510
662
  params: {
511
- autoDisabled: true,
663
+ multiple: true,
512
664
  },
513
665
  });
514
- await _.nextVueTick(store);
515
-
516
- store.commit('isOpen', true);
517
- await _.nextVueTick(store);
666
+ store.props.selectionIsExcluded = true;
518
667
 
519
- /* options 1
520
- * child 1
521
- */
522
- t.is(store.state.disabled, false);
523
- t.is(store.state.isOpen, true);
524
-
525
- /* options 1 disabled
526
- * child 1
527
- */
528
- const charlyOptions = getOptions(1, 'charly');
529
- charlyOptions[0].disabled = true;
530
- store.props.options = charlyOptions;
531
668
  await _.nextVueTick(store);
669
+ t.is(store.state.selectionIsExcluded, true);
532
670
 
533
- t.is(store.state.disabled, true);
534
- t.is(store.state.isOpen, false);
671
+ store.props.selectionIsExcluded = false;
535
672
 
536
- store.props.options = alphaOptions;
537
673
  await _.nextVueTick(store);
538
- store.commit('isOpen', true);
539
- await _.nextVueTick(store);
540
-
541
- /* options 0
542
- * child 1
543
- */
544
- store.props.options = getOptions(0, 'delta');
545
- await _.nextVueTick(store);
546
-
547
- t.is(store.state.disabled, true);
548
- t.is(store.state.isOpen, false);
549
-
550
- store.props.options = alphaOptions;
551
- await _.nextVueTick(store);
552
- store.commit('isOpen', true);
553
- await _.nextVueTick(store);
554
-
555
- /* options 1
556
- * child 1 disabled
557
- */
558
- const echoOptions = getOptions(1, 'echo');
559
- echoOptions[0].disabled = true;
560
- store.props.childOptions = echoOptions;
561
- await _.nextVueTick(store);
562
-
563
- t.is(store.state.disabled, true);
564
- t.is(store.state.isOpen, false);
565
-
566
- store.props.childOptions = bravoOptions;
567
- await _.nextVueTick(store);
568
- store.commit('isOpen', true);
569
- await _.nextVueTick(store);
570
-
571
- /* options 1
572
- * child 0
573
- */
574
- store.props.childOptions = getOptions(0, 'fox');
575
- await _.nextVueTick(store);
576
-
577
- t.is(store.state.disabled, true);
578
- t.is(store.state.isOpen, false);
579
-
674
+ t.is(store.state.selectionIsExcluded, false);
580
675
  t.end();
581
676
  });
677
+ }
582
678
 
583
- sTest.test('should not re-enable the select if disable is set', async (t) => {
679
+ if (testDisabled) {
680
+ subT.test('should change "disabled"', async (t) => {
584
681
  const store = new Store({
585
- childOptions: getOptions(1, 'alpha'),
586
- disabled: true,
587
- params: {
588
- autoDisabled: true,
589
- },
682
+ options: getOptions(2),
590
683
  });
591
- await _.nextVueTick(store);
592
684
 
593
- store.commit('isOpen', true);
685
+ store.props.disabled = true;
594
686
  await _.nextVueTick(store);
595
687
 
596
- t.is(store.state.internalValue, 0);
597
688
  t.is(store.state.disabled, true);
598
- t.is(store.state.isOpen, false);
599
689
 
600
- store.props.childOptions = getOptions(5, 'beta');
690
+ store.props.disabled = false;
601
691
  await _.nextVueTick(store);
602
692
 
603
- t.is(store.state.internalValue, 0);
604
- t.is(store.state.disabled, true);
605
- t.is(store.state.isOpen, false);
606
- t.end();
607
- });
608
-
609
- sTest.test('should fallback to next option source', async (t) => {
610
- const command = {};
611
- const spy = {};
612
-
613
- const store = new Store({
614
- options: getOptions(10),
615
- childOptions: getOptions(2, '', 10),
616
- fetchCallback: buildFetchCb({ total: 4, command, spy }),
617
- params: {
618
- optionBehavior: 'force-EDO',
619
- },
620
- });
621
- store.commit('isOpen', true);
622
- await _.nextVueTick(store);
623
- t.is(store.state.filteredOptions.length, 2);
624
-
625
- store.props.childOptions = [];
626
- await _.nextVueTick(store);
627
- store.commit('isOpen', true);
628
- await _.sleep(0);
629
- command.fetch();
630
- await _.nextVueTick(store, spy.promise);
631
-
632
- t.is(store.state.filteredOptions.length, 4, 'should fallback to dynamic options');
633
-
634
- store.props.childOptions = getOptions(2);
635
- await _.nextVueTick(store);
636
- store.commit('isOpen', true);
637
- await _.nextVueTick(store);
693
+ t.is(store.state.disabled, false);
638
694
 
639
- t.is(store.state.filteredOptions.length, 2, 'should get back to element options');
640
695
  t.end();
641
696
  });
642
- });
643
-
644
- subT.test('should change "selectionIsExcluded"', async (t) => {
645
- const store = new Store({
646
- fetchCallback: buildFetchCb({ total: 5 }),
647
- selectionIsExcluded: false,
648
- params: {
649
- multiple: true,
650
- },
651
- });
652
- store.props.selectionIsExcluded = true;
653
-
654
- await _.nextVueTick(store);
655
- t.is(store.state.selectionIsExcluded, true);
656
-
657
- store.props.selectionIsExcluded = false;
658
-
659
- await _.nextVueTick(store);
660
- t.is(store.state.selectionIsExcluded, false);
661
- t.end();
662
- });
663
-
664
- subT.test('should change "disabled"', async (t) => {
665
- const store = new Store({
666
- options: getOptions(2),
667
- });
668
-
669
- store.props.disabled = true;
670
- await _.nextVueTick(store);
671
-
672
- t.is(store.state.disabled, true);
673
-
674
- store.props.disabled = false;
675
- await _.nextVueTick(store);
676
-
677
- t.is(store.state.disabled, false);
678
-
679
- t.end();
680
- });
697
+ }
681
698
  });