2015-10-26 19:02:28 +03:00
|
|
|
/* jshint expr:true */
|
2016-11-14 16:16:51 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {setupComponentTest} from 'ember-mocha';
|
2016-06-30 13:21:47 +03:00
|
|
|
import {A as emberA} from 'ember-array/utils';
|
|
|
|
import run from 'ember-runloop';
|
2015-10-26 19:02:28 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Unit: Component: gh-selectize', function () {
|
|
|
|
setupComponentTest('gh-selectize', {
|
2015-10-26 19:02:28 +03:00
|
|
|
// Specify the other units that are required for this test
|
|
|
|
// needs: ['component:foo', 'helper:bar'],
|
|
|
|
unit: true
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-10-26 19:02:28 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('re-orders selection when selectize order is changed', function () {
|
|
|
|
let component = this.subject();
|
2015-10-26 19:02:28 +03:00
|
|
|
|
2017-02-01 00:15:17 +03:00
|
|
|
let item1 = {id: '1', name: 'item 1'};
|
|
|
|
let item2 = {id: '2', name: 'item 2'};
|
|
|
|
let item3 = {id: '3', name: 'item 3'};
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
2017-02-01 00:15:17 +03:00
|
|
|
component.set('content', emberA([item1, item2, item3]));
|
|
|
|
component.set('selection', emberA([item2, item3]));
|
2016-11-24 01:50:57 +03:00
|
|
|
component.set('multiple', true);
|
2017-02-01 00:15:17 +03:00
|
|
|
component.set('optionValuePath', 'content.id');
|
|
|
|
component.set('optionLabelPath', 'content.name');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-10-26 19:02:28 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
this.render();
|
2015-10-26 19:02:28 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
2017-02-01 00:15:17 +03:00
|
|
|
component._selectize.setValue(['3', '2']);
|
2015-10-26 19:02:28 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-02-01 00:15:17 +03:00
|
|
|
expect(component.get('selection').toArray(), 'component selection').to.deep.equal([item3, item2]);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|