2017-11-21 05:53:09 -05:00
|
|
|
|
import componentTest from 'helpers/component-test';
|
2017-12-22 07:08:12 -05:00
|
|
|
|
moduleForComponent('multi-select', {
|
|
|
|
|
integration: true,
|
|
|
|
|
beforeEach: function() {
|
|
|
|
|
this.set('subject', selectKit());
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
componentTest('with objects and values', {
|
|
|
|
|
template: '{{multi-select content=items values=values}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
this.set('items', [{id: 1, name: 'hello'}, {id: 2, name: 'world'}]);
|
|
|
|
|
this.set('values', [1, 2]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.equal(this.get('subject').header().value(), '1,2');
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
componentTest('with title', {
|
|
|
|
|
template: '{{multi-select title=(i18n "test.title")}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
I18n.translations[I18n.locale].js.test = {title: 'My title'};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
|
andThen(() => assert.equal(selectKit().header().title(), 'My title') );
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2017-11-21 05:53:09 -05:00
|
|
|
|
componentTest('interactions', {
|
|
|
|
|
template: '{{multi-select none=none content=items values=values}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
|
|
|
|
this.set('items', [{id: 1, name: 'regis'}, {id: 2, name: 'sam'}, {id: 3, name: 'robin'}]);
|
|
|
|
|
this.set('values', [1, 2]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').expand();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.equal(
|
|
|
|
|
this.get('subject').highlightedRow().name(),
|
|
|
|
|
'robin',
|
|
|
|
|
'it highlights the first content row'
|
|
|
|
|
);
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.set('none', 'test.none');
|
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.ok(this.get('subject').noneRow().exists());
|
|
|
|
|
assert.equal(
|
|
|
|
|
this.get('subject').highlightedRow().name(),
|
|
|
|
|
'robin',
|
|
|
|
|
'it highlights the first content row'
|
|
|
|
|
);
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').selectRowByValue(3);
|
2018-03-22 06:29:55 -04:00
|
|
|
|
this.get('subject').expand();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.equal(
|
|
|
|
|
this.get('subject').highlightedRow().name(),
|
|
|
|
|
'none',
|
|
|
|
|
'it highlights none row if no content'
|
|
|
|
|
);
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').fillInFilter('joffrey');
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.equal(
|
|
|
|
|
this.get('subject').highlightedRow().name(),
|
|
|
|
|
'joffrey',
|
|
|
|
|
'it highlights create row when filling filter'
|
|
|
|
|
);
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().enter();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.equal(
|
|
|
|
|
this.get('subject').highlightedRow().name(),
|
|
|
|
|
'none',
|
|
|
|
|
'it highlights none row after creating content and no content left'
|
|
|
|
|
);
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().backspace();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
const $lastSelectedName = this.get('subject').header().el().find('.selected-name').last();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
assert.equal($lastSelectedName.attr('data-name'), 'joffrey');
|
|
|
|
|
assert.ok($lastSelectedName.hasClass('is-highlighted'), 'it highlights the last selected name when using backspace');
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().backspace();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
const $lastSelectedName = this.get('subject').header().el().find('.selected-name').last();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
assert.equal($lastSelectedName.attr('data-name'), 'robin', 'it removes the previous highlighted selected content');
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.notOk(this.get('subject').rowByValue('joffrey').exists(), 'generated content shouldn’t appear in content when removed');
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().selectAll();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
const $highlightedSelectedNames = this.get('subject').header().el().find('.selected-name.is-highlighted');
|
2017-11-21 05:53:09 -05:00
|
|
|
|
assert.equal($highlightedSelectedNames.length, 3, 'it highlights each selected name');
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().backspace();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
const $selectedNames = this.get('subject').header().el().find('.selected-name');
|
2017-11-21 05:53:09 -05:00
|
|
|
|
assert.equal($selectedNames.length, 0, 'it removed all selected content');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.ok(this.get('subject').isFocused());
|
|
|
|
|
assert.ok(this.get('subject').isExpanded());
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().escape();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.ok(this.get('subject').isFocused());
|
|
|
|
|
assert.notOk(this.get('subject').isExpanded());
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
|
this.get('subject').keyboard().escape();
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
|
assert.notOk(this.get('subject').isFocused());
|
|
|
|
|
assert.notOk(this.get('subject').isExpanded());
|
2017-11-21 05:53:09 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-01-11 03:54:39 -05:00
|
|
|
|
|
|
|
|
|
componentTest('with limitMatches', {
|
|
|
|
|
template: '{{multi-select content=content limitMatches=2}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
this.set('content', ['sam', 'jeff', 'neil']);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
|
this.get('subject').expand();
|
|
|
|
|
|
|
|
|
|
andThen(() => assert.equal(this.get('subject').el().find(".select-kit-row").length, 2));
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-04-05 10:45:19 -04:00
|
|
|
|
|
|
|
|
|
componentTest('with minimum', {
|
|
|
|
|
template: '{{multi-select content=content minimum=1}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
this.set('content', ['sam', 'jeff', 'neil']);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
|
this.get('subject').expand();
|
|
|
|
|
|
2018-04-09 03:12:01 -04:00
|
|
|
|
andThen(() => assert.equal(this.get('subject').validationMessage(), 'Select at least 1 item.'));
|
2018-04-05 10:45:19 -04:00
|
|
|
|
|
|
|
|
|
this.get('subject').selectRowByValue('sam');
|
|
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
|
assert.equal(this.get('subject').header().label(), 'sam');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('with minimumLabel', {
|
|
|
|
|
template: '{{multi-select content=content minimum=1 minimumLabel="test.minimum"}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
I18n.translations[I18n.locale].js.test = { minimum: 'min %{count}' };
|
|
|
|
|
this.set('content', ['sam', 'jeff', 'neil']);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
|
this.get('subject').expand();
|
|
|
|
|
|
|
|
|
|
andThen(() => assert.equal(this.get('subject').validationMessage(), 'min 1'));
|
|
|
|
|
|
|
|
|
|
this.get('subject').selectRowByValue('jeff');
|
|
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
|
assert.equal(this.get('subject').header().label(), 'jeff');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|