@@ -192,6 +192,48 @@ module('Integration | Component | sortable-js', function(hooks) {
192
192
assert . deepEqual ( listBOrder , expectedListBOrder ) ;
193
193
} ) ;
194
194
195
+ test ( 'it dynamically sets options' , async function ( assert ) {
196
+ let options = {
197
+ animation : 150 ,
198
+ ghostClass : 'ghost-class' ,
199
+ } ;
200
+
201
+ this . set ( 'options' , options ) ;
202
+
203
+ // Template block usage:
204
+ await render ( hbs `
205
+ <SortableJs
206
+ class="list-group"
207
+ @items={{this.list}}
208
+ @options={{options}}
209
+ as |list|
210
+ >
211
+ {{#each list as |item| }}
212
+ <div data-testid="one" class="list-group-item">{{item.value}}</div>
213
+ {{/each}}
214
+ </SortableJs>
215
+ ` ) ;
216
+
217
+ const element = find ( '.list-group' ) ;
218
+ const sortableKey = Object . keys ( element ) . pop ( ) ;
219
+ const sortableInstance = element [ sortableKey ] ;
220
+
221
+ assert . equal ( sortableInstance . option ( 'ghostClass' ) , 'ghost-class' ) ;
222
+ assert . equal ( sortableInstance . option ( 'animation' ) , 150 ) ;
223
+
224
+ options = {
225
+ animation : 100 ,
226
+ ghostClass : 'foo' ,
227
+ } ;
228
+
229
+ this . set ( 'options' , options ) ;
230
+
231
+ assert . equal ( sortableInstance . option ( 'ghostClass' ) , 'foo' ) ;
232
+ assert . equal ( sortableInstance . option ( 'animation' ) , 100 ) ;
233
+ } ) ;
234
+
235
+
236
+
195
237
// test('it reorders a list', async function(assert) {
196
238
// const done = assert.async();
197
239
// const onChoose = () => assert.ok(true, 'onChosse was called');
@@ -329,72 +371,6 @@ module('Integration | Component | sortable-js', function(hooks) {
329
371
// assert.equal(bItems.children.length, 6, 'list b has a cloned item');
330
372
// });
331
373
332
- // test('it dynamically sets options', async function(assert) {
333
- // let count = 0;
334
- // const done = assert.async();
335
- // const onChoose = () => assert.ok(true, 'onChosse was called');
336
- // const onStart = () => assert.ok(true, 'onStart was called');
337
- // const onMove = () => assert.ok(true, 'onMove was called');
338
- // const onEnd = (event, sortableInstance) => {
339
- // assert.ok(true, 'onEnd was called');
340
- // count += 1;
341
- // if (count === 2) {
342
- // assert.equal(sortableInstance.option('animation'), 100, 'Animation was changed to 100');
343
- // assert.equal(sortableInstance.option('ghostClass'), 'foo', 'Ghost class was changed to foo');
344
- // done();
345
- // }
346
- // }
347
-
348
- // let options = {
349
- // animation: 150,
350
- // ghostClass: 'ghost-class',
351
- // };
352
-
353
- // this.set('onChoose', onChoose);
354
- // this.set('onStart', onStart);
355
- // this.set('onMove', onMove);
356
- // this.set('onEnd', onEnd);
357
- // this.set('options', options);
358
-
359
- // // Template block usage:
360
- // await render(hbs`
361
- // <SortableJs
362
- // class="list-group"
363
- // @options ={{options}}
364
- // @onChoose ={{action onChoose}}
365
- // @onStart ={{action onStart}}
366
- // @onMove ={{action onMove}}
367
- // @onEnd ={{action onEnd}}
368
- // >
369
- // <div data-testid="one" class="list-group-item">Item 1</div>
370
- // <div data-testid="two" class="list-group-item">Item 2</div>
371
- // <div data-testid="three" class="list-group-item">Item 3</div>
372
- // <div data-testid="four" class="list-group-item">Item 4</div>
373
- // <div data-testid="five" class="list-group-item">Item 5</div>
374
- // </SortableJs>
375
- // `);
376
-
377
- // const listItemOne = find('div[data-testid="one"]');
378
- // const listItemFour = find('div[data-testid="four"]');
379
- // const listItemTwo = find('div[data-testid="two"]');
380
-
381
- // await simulateDrag(listItemOne, listItemFour);
382
-
383
- // const listItems = document.querySelector('.list-group').children;
384
- // assert.equal(listItemOne, listItems[3], 'dragged successful');
385
-
386
- // options = {
387
- // animation: 100,
388
- // ghostClass: 'foo',
389
- // };
390
-
391
- // this.set('options', options);
392
-
393
- // await new Promise((resolve) => setTimeout(() => resolve(), 1000));
394
-
395
- // await simulateDrag(listItemTwo, listItemOne)
396
- // });
397
-
398
374
// test('calls onSpill when dropped outside the sortable regioin', async function(assert) {
399
375
// this.onSpill = function() {
400
376
// assert.ok(true, 'onSpill was invoked');
0 commit comments