2015-07-28 12:29:40 -04:00
|
|
|
import componentTest from 'helpers/component-test';
|
2017-12-22 07:08:12 -05:00
|
|
|
moduleForComponent('combo-box', {
|
|
|
|
integration: true,
|
|
|
|
beforeEach: function() {
|
|
|
|
this.set('subject', selectKit());
|
|
|
|
}
|
|
|
|
});
|
2015-07-28 12:29:40 -04:00
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
componentTest('default', {
|
|
|
|
template: '{{combo-box content=items}}',
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2015-07-28 12:29:40 -04:00
|
|
|
this.set('items', [{id: 1, name: 'hello'}, {id: 2, name: 'world'}]);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').header().name(), "hello");
|
|
|
|
assert.equal(this.get('subject').rowByValue(1).name(), "hello");
|
|
|
|
assert.equal(this.get('subject').rowByValue(2).name(), "world");
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
2015-07-28 12:29:40 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
componentTest('with valueAttribute', {
|
2015-08-05 16:19:21 -04:00
|
|
|
template: '{{combo-box content=items valueAttribute="value"}}',
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2015-08-05 16:19:21 -04:00
|
|
|
this.set('items', [{value: 0, name: 'hello'}, {value: 1, name: 'world'}]);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').rowByValue(0).name(), "hello");
|
|
|
|
assert.equal(this.get('subject').rowByValue(1).name(), "world");
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
2015-08-05 16:19:21 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
componentTest('with nameProperty', {
|
|
|
|
template: '{{combo-box content=items nameProperty="text"}}',
|
|
|
|
beforeEach() {
|
|
|
|
this.set('items', [{id: 0, text: 'hello'}, {id: 1, text: 'world'}]);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').rowByValue(0).name(), "hello");
|
|
|
|
assert.equal(this.get('subject').rowByValue(1).name(), "world");
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest('with an array as content', {
|
2015-07-28 12:29:40 -04:00
|
|
|
template: '{{combo-box content=items value=value}}',
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2015-07-28 12:29:40 -04:00
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').rowByValue('evil').name(), "evil");
|
|
|
|
assert.equal(this.get('subject').rowByValue('trout').name(), "trout");
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
2015-07-28 12:29:40 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
componentTest('with value and none as a string', {
|
2015-07-28 12:29:40 -04:00
|
|
|
template: '{{combo-box content=items none="test.none" value=value}}',
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2015-07-28 12:29:40 -04:00
|
|
|
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
2017-10-19 15:51:08 -04:00
|
|
|
this.set('value', 'trout');
|
2015-07-28 12:29:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').noneRow().name(), 'none');
|
|
|
|
assert.equal(this.get('subject').rowByValue("evil").name(), "evil");
|
|
|
|
assert.equal(this.get('subject').rowByValue("trout").name(), "trout");
|
|
|
|
assert.equal(this.get('subject').header().name(), 'trout');
|
2017-10-19 15:51:08 -04:00
|
|
|
assert.equal(this.get('value'), 'trout');
|
|
|
|
});
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').selectNoneRow();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(this.get('value'), null);
|
|
|
|
});
|
2015-07-28 12:29:40 -04:00
|
|
|
}
|
|
|
|
});
|
2017-04-19 23:48:59 -04:00
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
componentTest('with value and none as an object', {
|
|
|
|
template: '{{combo-box content=items none=none value=value}}',
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2017-04-19 23:48:59 -04:00
|
|
|
this.set('none', { id: 'something', name: 'none' });
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
2017-10-19 15:51:08 -04:00
|
|
|
this.set('value', 'evil');
|
2017-04-19 23:48:59 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').noneRow().name(), 'none');
|
|
|
|
assert.equal(this.get('subject').rowByValue("evil").name(), "evil");
|
|
|
|
assert.equal(this.get('subject').rowByValue("trout").name(), "trout");
|
|
|
|
assert.equal(this.get('subject').header().name(), 'evil');
|
2017-10-19 15:51:08 -04:00
|
|
|
assert.equal(this.get('value'), 'evil');
|
|
|
|
});
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').selectNoneRow();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(this.get('value'), null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest('with no value and none as an object', {
|
|
|
|
template: '{{combo-box content=items none=none value=value}}',
|
|
|
|
beforeEach() {
|
|
|
|
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
|
|
|
this.set('none', { id: 'something', name: 'none' });
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
|
|
|
this.set('value', null);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').header().name(), 'none');
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest('with no value and none string', {
|
|
|
|
template: '{{combo-box content=items none=none value=value}}',
|
|
|
|
beforeEach() {
|
|
|
|
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
|
|
|
this.set('none', 'test.none');
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
|
|
|
this.set('value', null);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').header().name(), 'none');
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest('with no value and no none', {
|
|
|
|
template: '{{combo-box content=items value=value}}',
|
|
|
|
beforeEach() {
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
|
|
|
this.set('value', null);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').header().name(), 'evil', 'it sets the first row as value');
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|
2017-04-19 23:48:59 -04:00
|
|
|
}
|
|
|
|
});
|
2017-10-19 17:32:37 -04:00
|
|
|
|
2017-10-19 20:34:56 -04:00
|
|
|
componentTest('with empty string as value', {
|
|
|
|
template: '{{combo-box content=items value=value}}',
|
|
|
|
beforeEach() {
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
|
|
|
this.set('value', '');
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2017-12-22 07:08:12 -05:00
|
|
|
this.get('subject').expand();
|
2017-10-19 20:34:56 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
assert.equal(this.get('subject').header().name(), 'evil', 'it sets the first row as value');
|
2017-10-19 20:34:56 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-03-29 07:42:00 -04:00
|
|
|
|
|
|
|
componentTest('with noneLabel', {
|
|
|
|
template: '{{combo-box content=items allowAutoSelectFirst=false noneLabel=noneLabel}}',
|
|
|
|
beforeEach() {
|
|
|
|
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
|
|
|
this.set('items', ['evil', 'trout', 'hat']);
|
|
|
|
this.set('noneLabel', 'test.none');
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
this.get('subject').expand();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(this.get('subject').header().name(), 'none', 'it displays noneLabel as the header name');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|