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.
@@ -8,6 +8,9 @@ const tape = require('tape');
8
8
  const StoreFile = require('../dist/Store.js');
9
9
  const Store = StoreFile.default;
10
10
 
11
+ const testSingle = true;
12
+ const testMultiple = true;
13
+
11
14
  tape.test('selectGroup()', (st) => {
12
15
  function getStaticOptions() {
13
16
  const group1 = getOptions(10, 'gp1-', 0, 'group1');
@@ -26,364 +29,368 @@ tape.test('selectGroup()', (st) => {
26
29
  const group2Ids = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29];
27
30
  const group3Ids = [31, 32, 33, 34, 37, 38];
28
31
 
29
- st.test('when "multiple" is false', (section) => {
30
- section.test('with static mode', (sTest) => {
31
- function getStore() {
32
- const options = getStaticOptions();
33
- const store = new Store({
34
- options: options,
35
- params: {
36
- multiple: false,
37
- autoSelect: false,
38
- strictValue: true,
39
- },
40
- });
32
+ if (testSingle) {
33
+ st.test('when "multiple" is false', (section) => {
34
+ section.test('with static mode', (sTest) => {
35
+ function getStore() {
36
+ const options = getStaticOptions();
37
+ const store = new Store({
38
+ options: options,
39
+ params: {
40
+ multiple: false,
41
+ autoSelect: false,
42
+ strictValue: true,
43
+ },
44
+ });
41
45
 
42
- return store;
43
- }
46
+ return store;
47
+ }
44
48
 
45
- sTest.test('should not change selection', async (t) => {
46
- const store = getStore();
47
- await _.nextVueTick(store);
48
- store.commit('isOpen', true);
49
- await _.sleep(0);
49
+ sTest.test('should not change selection', async (t) => {
50
+ const store = getStore();
51
+ await _.nextVueTick(store);
52
+ store.commit('isOpen', true);
53
+ await _.sleep(0);
50
54
 
51
- t.is(store.state.internalValue, null, 'initialization');
55
+ t.is(store.state.internalValue, null, 'initialization');
52
56
 
53
- store.selectGroup('group1', true);
57
+ store.selectGroup('group1', true);
54
58
 
55
- t.is(store.state.internalValue, null);
56
- t.is(store.state.status.hasChanged, false);
59
+ t.is(store.state.internalValue, null);
60
+ t.is(store.state.status.hasChanged, false);
57
61
 
58
- /* Check if it also not changed value when there is one */
62
+ /* Check if it also not changed value when there is one */
59
63
 
60
- store.selectItem(5, true);
61
- /* reset status to check that it is modified */
62
- store.state.status.hasChanged = false;
64
+ store.selectItem(5, true);
65
+ /* reset status to check that it is modified */
66
+ store.state.status.hasChanged = false;
63
67
 
64
- store.selectGroup('group2', true);
68
+ store.selectGroup('group2', true);
65
69
 
66
- t.is(store.state.internalValue, 5);
67
- t.is(store.state.status.hasChanged, false);
70
+ t.is(store.state.internalValue, 5);
71
+ t.is(store.state.status.hasChanged, false);
68
72
 
69
- t.end();
73
+ t.end();
74
+ });
70
75
  });
71
- });
72
76
 
73
- section.test('with dynamic mode', (sTest) => {
74
- sTest.test('should not select any value', async (t) => {
75
- const command = {};
76
- const spy = {};
77
-
78
- const store = new Store({
79
- fetchCallback: buildFetchCb({
80
- total: 300,
81
- group: [{
82
- name: 'g1',
83
- offset: 0,
77
+ section.test('with dynamic mode', (sTest) => {
78
+ sTest.test('should not select any value', async (t) => {
79
+ const command = {};
80
+ const spy = {};
81
+
82
+ const store = new Store({
83
+ fetchCallback: buildFetchCb({
84
+ total: 300,
85
+ group: [{
86
+ name: 'g1',
87
+ offset: 0,
88
+ }, {
89
+ name: 'g2',
90
+ offset: 20,
91
+ }, {
92
+ name: 'g3',
93
+ offset: 250,
94
+ }],
95
+ command,
96
+ spy,
97
+ }),
98
+ groups: [{
99
+ id: 'g1',
100
+ name: 'Group 1',
84
101
  }, {
85
- name: 'g2',
86
- offset: 20,
102
+ id: 'g2',
103
+ name: 'Group 2',
87
104
  }, {
88
- name: 'g3',
89
- offset: 250,
105
+ id: 'g3',
106
+ name: 'Group 3',
90
107
  }],
91
- command,
92
- spy,
93
- }),
94
- groups: [{
95
- id: 'g1',
96
- name: 'Group 1',
97
- }, {
98
- id: 'g2',
99
- name: 'Group 2',
100
- }, {
101
- id: 'g3',
102
- name: 'Group 3',
103
- }],
104
- });
105
- await _.nextVueTick(store);
106
- store.commit('isOpen', true);
107
- command.fetch();
108
- resetCall(spy);
108
+ });
109
109
 
110
- await _.nextVueTick(store, command.promise);
110
+ await _.nextVueTick(store);
111
+ store.commit('isOpen', true);
112
+ command.fetch();
113
+ resetCall(spy);
114
+ await _.nextVueTick(store, command.promise, _.sleep(0) /* await request resolution */);
111
115
 
112
- t.is(store.state.internalValue, null, 'initialization');
113
- t.is(store.state.filteredOptions[0].id, 'g1', 'initialization checks group is visible');
116
+ t.is(store.state.internalValue, null, 'initialization');
117
+ t.is(store.state.filteredOptions[0].id, 'g1', 'initialization checks group is visible');
114
118
 
115
- store.selectGroup('g1', true);
119
+ store.selectGroup('g1', true);
116
120
 
117
- /* Currently selection is blocked for dynamic mode */
121
+ /* Currently selection is blocked for dynamic mode */
118
122
 
119
- t.is(store.state.internalValue, null);
120
- t.is(store.state.status.hasChanged, false);
123
+ t.is(store.state.internalValue, null);
124
+ t.is(store.state.status.hasChanged, false);
121
125
 
122
- t.end();
126
+ t.end();
127
+ });
123
128
  });
124
129
  });
125
- });
126
-
127
- st.test('when "multiple" is true', (section) => {
128
- section.test('with static mode', (sTest) => {
129
- function getStore() {
130
- const options = getStaticOptions();
131
- const store = new Store({
132
- options: options,
133
- params: {
134
- multiple: true,
135
- strictValue: true,
136
- },
137
- });
130
+ }
138
131
 
139
- return store;
140
- }
132
+ if (testMultiple) {
133
+ st.test('when "multiple" is true', (section) => {
134
+ section.test('with static mode', (sTest) => {
135
+ function getStore() {
136
+ const options = getStaticOptions();
137
+ const store = new Store({
138
+ options: options,
139
+ params: {
140
+ multiple: true,
141
+ strictValue: true,
142
+ },
143
+ });
141
144
 
142
- sTest.test('should select several value', async (t) => {
143
- const store = getStore();
144
- await _.nextVueTick(store);
145
- store.commit('isOpen', true);
146
- await _.sleep(0);
145
+ return store;
146
+ }
147
147
 
148
- t.deepEqual(store.state.internalValue, [], 'initialization');
148
+ sTest.test('should select several value', async (t) => {
149
+ const store = getStore();
150
+ await _.nextVueTick(store);
151
+ store.commit('isOpen', true);
152
+ await _.sleep(0);
149
153
 
150
- store.selectGroup('group1', true);
154
+ t.deepEqual(store.state.internalValue, [], 'initialization');
151
155
 
152
- t.deepEqual(store.state.internalValue, group1Ids);
153
- t.is(store.state.status.hasChanged, true);
156
+ store.selectGroup('group1', true);
154
157
 
155
- /* it should add selection to the current selection */
158
+ t.deepEqual(store.state.internalValue, group1Ids);
159
+ t.is(store.state.status.hasChanged, true);
156
160
 
157
- /* reset status to check that it is modified */
158
- store.state.status.hasChanged = false;
161
+ /* it should add selection to the current selection */
159
162
 
160
- store.selectGroup('group2', true);
163
+ /* reset status to check that it is modified */
164
+ store.state.status.hasChanged = false;
161
165
 
162
- t.deepEqual(store.state.internalValue, group1Ids.concat(group2Ids));
163
- t.is(store.state.status.hasChanged, true);
166
+ store.selectGroup('group2', true);
164
167
 
165
- t.end();
166
- });
168
+ t.deepEqual(store.state.internalValue, group1Ids.concat(group2Ids));
169
+ t.is(store.state.status.hasChanged, true);
167
170
 
168
- sTest.test('should not duplicate already selected values', async (t) => {
169
- const store = getStore();
170
- await _.nextVueTick(store);
171
- store.commit('isOpen', true);
172
- await _.sleep(0);
171
+ t.end();
172
+ });
173
173
 
174
- store.selectItem(1, true);
175
- store.selectItem(6, true);
176
- store.selectItem(11, true);
177
- t.deepEqual(store.state.internalValue, [1, 6, 11], 'initialization');
174
+ sTest.test('should not duplicate already selected values', async (t) => {
175
+ const store = getStore();
176
+ await _.nextVueTick(store);
177
+ store.commit('isOpen', true);
178
+ await _.sleep(0);
178
179
 
179
- store.selectGroup('group1', true);
180
+ store.selectItem(1, true);
181
+ store.selectItem(6, true);
182
+ store.selectItem(11, true);
183
+ t.deepEqual(store.state.internalValue, [1, 6, 11], 'initialization');
180
184
 
181
- t.deepEqual(store.state.internalValue, [1, 6, 11, 0, 2, 3, 4, 5, 7, 8, 9]);
182
- t.is(store.state.status.hasChanged, true);
185
+ store.selectGroup('group1', true);
183
186
 
184
- /* reset status to check that it is modified */
185
- store.state.status.hasChanged = false;
187
+ t.deepEqual(store.state.internalValue, [1, 6, 11, 0, 2, 3, 4, 5, 7, 8, 9]);
188
+ t.is(store.state.status.hasChanged, true);
186
189
 
187
- store.selectGroup('group1', true);
190
+ /* reset status to check that it is modified */
191
+ store.state.status.hasChanged = false;
188
192
 
189
- t.deepEqual(store.state.internalValue, [1, 6, 11, 0, 2, 3, 4, 5, 7, 8, 9]);
190
- t.is(store.state.status.hasChanged, false,
191
- 'should not considered as changed if no new elements are added');
193
+ store.selectGroup('group1', true);
192
194
 
193
- t.end();
194
- });
195
+ t.deepEqual(store.state.internalValue, [1, 6, 11, 0, 2, 3, 4, 5, 7, 8, 9]);
196
+ t.is(store.state.status.hasChanged, false,
197
+ 'should not considered as changed if no new elements are added');
195
198
 
196
- sTest.test('should not select disabled and exclusive values', async (t) => {
197
- const store = getStore();
198
- await _.nextVueTick(store);
199
- store.commit('isOpen', true);
200
- await _.sleep(0);
199
+ t.end();
200
+ });
201
201
 
202
- t.deepEqual(store.state.internalValue, [], 'initialization');
202
+ sTest.test('should not select disabled and exclusive values', async (t) => {
203
+ const store = getStore();
204
+ await _.nextVueTick(store);
205
+ store.commit('isOpen', true);
206
+ await _.sleep(0);
203
207
 
204
- store.selectGroup('group3', true);
208
+ t.deepEqual(store.state.internalValue, [], 'initialization');
205
209
 
206
- t.deepEqual(store.state.internalValue, group3Ids, 'should not contains disabled and exclusive items');
207
- t.is(store.state.status.hasChanged, true);
210
+ store.selectGroup('group3', true);
208
211
 
209
- t.end();
210
- });
212
+ t.deepEqual(store.state.internalValue, group3Ids, 'should not contains disabled and exclusive items');
213
+ t.is(store.state.status.hasChanged, true);
211
214
 
212
- sTest.test('should unselect values', async (t) => {
213
- const store = getStore();
214
- await _.nextVueTick(store);
215
- store.commit('isOpen', true);
216
- await _.sleep(0);
217
- store.selectItem(1, true);
218
- store.selectItem(6, true);
219
- store.selectItem(11, true);
220
- store.selectGroup('group2', true);
221
- store.selectItem(31, true);
215
+ t.end();
216
+ });
222
217
 
223
- t.deepEqual(store.state.internalValue, [1, 6, 11, 10, ...group2Ids.slice(2), 31], 'initialization');
218
+ sTest.test('should unselect values', async (t) => {
219
+ const store = getStore();
220
+ await _.nextVueTick(store);
221
+ store.commit('isOpen', true);
222
+ await _.sleep(0);
223
+ store.selectItem(1, true);
224
+ store.selectItem(6, true);
225
+ store.selectItem(11, true);
226
+ store.selectGroup('group2', true);
227
+ store.selectItem(31, true);
224
228
 
225
- store.selectGroup('group2', false);
229
+ t.deepEqual(store.state.internalValue, [1, 6, 11, 10, ...group2Ids.slice(2), 31], 'initialization');
226
230
 
227
- t.deepEqual(store.state.internalValue, [1, 6, 31]);
228
- t.is(store.state.status.hasChanged, true);
231
+ store.selectGroup('group2', false);
229
232
 
230
- /* Remove already not selected group */
231
- /* reset status to check that it is modified */
232
- store.state.status.hasChanged = false;
233
+ t.deepEqual(store.state.internalValue, [1, 6, 31]);
234
+ t.is(store.state.status.hasChanged, true);
233
235
 
234
- store.selectGroup('group2', false);
236
+ /* Remove already not selected group */
237
+ /* reset status to check that it is modified */
238
+ store.state.status.hasChanged = false;
235
239
 
236
- t.deepEqual(store.state.internalValue, [1, 6, 31], 'should not changed');
237
- t.is(store.state.status.hasChanged, false,
238
- 'should not considered as changed if no new elements are removed');
240
+ store.selectGroup('group2', false);
239
241
 
240
- /* should remove partial selection */
242
+ t.deepEqual(store.state.internalValue, [1, 6, 31], 'should not changed');
243
+ t.is(store.state.status.hasChanged, false,
244
+ 'should not considered as changed if no new elements are removed');
241
245
 
242
- store.selectGroup('group1', false);
246
+ /* should remove partial selection */
243
247
 
244
- t.deepEqual(store.state.internalValue, [31]);
245
- t.is(store.state.status.hasChanged, true);
248
+ store.selectGroup('group1', false);
246
249
 
247
- t.end();
248
- });
250
+ t.deepEqual(store.state.internalValue, [31]);
251
+ t.is(store.state.status.hasChanged, true);
249
252
 
250
- sTest.test('should apply only on filtered elements', async (t) => {
251
- const store = getStore();
252
- await _.nextVueTick(store);
253
- store.commit('isOpen', true);
254
- store.commit('searchText', '1');
255
- store.selectItem(37, true);
256
- await _.sleep(0);
253
+ t.end();
254
+ });
257
255
 
258
- t.deepEqual(store.state.internalValue, [37], 'initialization');
256
+ sTest.test('should apply only on filtered elements', async (t) => {
257
+ const store = getStore();
258
+ await _.nextVueTick(store);
259
+ store.commit('isOpen', true);
260
+ store.commit('searchText', '1');
261
+ store.selectItem(37, true);
262
+ await _.sleep(0);
259
263
 
260
- store.selectGroup('group2', true);
264
+ t.deepEqual(store.state.internalValue, [37], 'initialization');
261
265
 
262
- t.deepEqual(store.state.internalValue, [37, ...group2FilteredIds]);
263
- t.is(store.state.status.hasChanged, true);
266
+ store.selectGroup('group2', true);
264
267
 
265
- /* it should remove selection */
268
+ t.deepEqual(store.state.internalValue, [37, ...group2FilteredIds]);
269
+ t.is(store.state.status.hasChanged, true);
266
270
 
267
- /* reset status to check that it is modified */
268
- store.state.status.hasChanged = false;
271
+ /* it should remove selection */
269
272
 
270
- store.selectGroup('group2', false);
273
+ /* reset status to check that it is modified */
274
+ store.state.status.hasChanged = false;
271
275
 
272
- t.deepEqual(store.state.internalValue, [37]);
273
- t.is(store.state.status.hasChanged, true);
276
+ store.selectGroup('group2', false);
274
277
 
275
- /* it should remove only filtered selection */
278
+ t.deepEqual(store.state.internalValue, [37]);
279
+ t.is(store.state.status.hasChanged, true);
276
280
 
277
- store.selectItem(31, true);
281
+ /* it should remove only filtered selection */
278
282
 
279
- /* reset status to check that it is modified */
280
- store.state.status.hasChanged = false;
283
+ store.selectItem(31, true);
281
284
 
282
- store.selectGroup('group3', false);
285
+ /* reset status to check that it is modified */
286
+ store.state.status.hasChanged = false;
283
287
 
284
- t.deepEqual(store.state.internalValue, [37]);
285
- t.is(store.state.status.hasChanged, true);
288
+ store.selectGroup('group3', false);
286
289
 
287
- t.end();
288
- });
290
+ t.deepEqual(store.state.internalValue, [37]);
291
+ t.is(store.state.status.hasChanged, true);
289
292
 
290
- sTest.test('should have set items as selected', async (t) => {
291
- const store = getStore();
292
- await _.nextVueTick(store);
293
- store.commit('isOpen', true);
294
- await _.sleep(0);
295
-
296
- store.selectGroup('group1', true);
297
- t.is(store.state.filteredOptions[0].selected, true, 'should select the group');
298
- t.is(store.state.filteredOptions[1].selected, true); // id: 0
299
- t.is(store.state.filteredOptions[2].selected, true);
300
- t.is(store.state.filteredOptions[3].selected, true);
301
- t.is(store.state.filteredOptions[4].selected, true);
302
- t.is(store.state.filteredOptions[5].selected, true);
303
- t.is(store.state.filteredOptions[6].selected, true);
304
- t.is(store.state.filteredOptions[7].selected, true);
305
- t.is(store.state.filteredOptions[8].selected, true);
306
- t.is(store.state.filteredOptions[9].selected, true);
307
- t.is(store.state.filteredOptions[10].selected, true);
308
- t.is(store.state.filteredOptions[11].selected, false);
309
-
310
- store.selectItem(5, false);
311
- t.is(store.state.filteredOptions[0].selected, false, 'should unselect the group');
312
- t.is(store.state.filteredOptions[6].selected, false); // id: 5
313
-
314
- t.end();
315
- });
293
+ t.end();
294
+ });
316
295
 
317
- sTest.test('should not close list', async (t) => {
318
- const store = getStore();
319
- await _.nextVueTick(store);
320
- store.commit('isOpen', true);
321
- await _.sleep(0);
296
+ sTest.test('should have set items as selected', async (t) => {
297
+ const store = getStore();
298
+ await _.nextVueTick(store);
299
+ store.commit('isOpen', true);
300
+ await _.sleep(0);
301
+
302
+ store.selectGroup('group1', true);
303
+ t.is(store.state.filteredOptions[0].selected, true, 'should select the group');
304
+ t.is(store.state.filteredOptions[1].selected, true); // id: 0
305
+ t.is(store.state.filteredOptions[2].selected, true);
306
+ t.is(store.state.filteredOptions[3].selected, true);
307
+ t.is(store.state.filteredOptions[4].selected, true);
308
+ t.is(store.state.filteredOptions[5].selected, true);
309
+ t.is(store.state.filteredOptions[6].selected, true);
310
+ t.is(store.state.filteredOptions[7].selected, true);
311
+ t.is(store.state.filteredOptions[8].selected, true);
312
+ t.is(store.state.filteredOptions[9].selected, true);
313
+ t.is(store.state.filteredOptions[10].selected, true);
314
+ t.is(store.state.filteredOptions[11].selected, false);
315
+
316
+ store.selectItem(5, false);
317
+ t.is(store.state.filteredOptions[0].selected, false, 'should unselect the group');
318
+ t.is(store.state.filteredOptions[6].selected, false); // id: 5
319
+
320
+ t.end();
321
+ });
322
322
 
323
- store.selectGroup('group1', true);
324
- t.is(store.state.isOpen, true);
323
+ sTest.test('should not close list', async (t) => {
324
+ const store = getStore();
325
+ await _.nextVueTick(store);
326
+ store.commit('isOpen', true);
327
+ await _.sleep(0);
325
328
 
326
- store.selectItem('group1', false);
327
- t.is(store.state.isOpen, true);
329
+ store.selectGroup('group1', true);
330
+ t.is(store.state.isOpen, true);
328
331
 
329
- t.end();
332
+ store.selectItem('group1', false);
333
+ t.is(store.state.isOpen, true);
334
+
335
+ t.end();
336
+ });
330
337
  });
331
- });
332
338
 
333
- section.test('with dynamic mode', (sTest) => {
334
- sTest.test('should not select any value', async (t) => {
335
- const command = {};
336
- const spy = {};
337
-
338
- const store = new Store({
339
- params: {
340
- multiple: true,
341
- },
342
- fetchCallback: buildFetchCb({
343
- total: 300,
344
- group: [{
345
- name: 'g1',
346
- offset: 0,
339
+ section.test('with dynamic mode', (sTest) => {
340
+ sTest.test('should not select any value', async (t) => {
341
+ const command = {};
342
+ const spy = {};
343
+
344
+ const store = new Store({
345
+ params: {
346
+ multiple: true,
347
+ },
348
+ fetchCallback: buildFetchCb({
349
+ total: 300,
350
+ group: [{
351
+ name: 'g1',
352
+ offset: 0,
353
+ }, {
354
+ name: 'g2',
355
+ offset: 20,
356
+ }, {
357
+ name: 'g3',
358
+ offset: 250,
359
+ }],
360
+ command,
361
+ spy,
362
+ }),
363
+ groups: [{
364
+ id: 'g1',
365
+ name: 'Group 1',
347
366
  }, {
348
- name: 'g2',
349
- offset: 20,
367
+ id: 'g2',
368
+ name: 'Group 2',
350
369
  }, {
351
- name: 'g3',
352
- offset: 250,
370
+ id: 'g3',
371
+ name: 'Group 3',
353
372
  }],
354
- command,
355
- spy,
356
- }),
357
- groups: [{
358
- id: 'g1',
359
- name: 'Group 1',
360
- }, {
361
- id: 'g2',
362
- name: 'Group 2',
363
- }, {
364
- id: 'g3',
365
- name: 'Group 3',
366
- }],
367
- });
368
- await _.nextVueTick(store);
369
- store.commit('isOpen', true);
370
- command.fetch();
371
- resetCall(spy);
373
+ });
374
+ await _.nextVueTick(store);
375
+ store.commit('isOpen', true);
376
+ command.fetch();
377
+ resetCall(spy);
372
378
 
373
- await _.nextVueTick(store, command.promise);
379
+ await _.nextVueTick(store, command.promise, _.sleep(0) /* await request resolution */);
374
380
 
375
- t.deepEqual(store.state.internalValue, [], 'initialization');
376
- t.is(store.state.filteredOptions[0].id, 'g1', 'initialization checks group is visible');
381
+ t.deepEqual(store.state.internalValue, [], 'initialization');
382
+ t.is(store.state.filteredOptions[0].id, 'g1', 'initialization checks group is visible');
377
383
 
378
- store.selectGroup('g1', true);
384
+ store.selectGroup('g1', true);
379
385
 
380
- /* Currently selection is blocked for dynamic mode */
386
+ /* Currently selection is blocked for dynamic mode */
381
387
 
382
- t.deepEqual(store.state.internalValue, []);
383
- t.is(store.state.status.hasChanged, false);
388
+ t.deepEqual(store.state.internalValue, []);
389
+ t.is(store.state.status.hasChanged, false);
384
390
 
385
- t.end();
391
+ t.end();
392
+ });
386
393
  });
387
394
  });
388
- });
395
+ }
389
396
  });