fix error when running formatOptions on items that don't come from the API response (#6824)

This commit is contained in:
Matthew Irish 2019-06-04 12:44:58 -05:00 committed by GitHub
parent 38c0a9d7a5
commit 813c9f0a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -60,7 +60,11 @@ export default Component.extend({
let formattedOptions = this.selectedOptions.map(option => {
let matchingOption = options.findBy('id', option);
options.removeObject(matchingOption);
return { id: option, name: matchingOption.name, searchText: matchingOption.searchText };
return {
id: option,
name: matchingOption ? matchingOption.name : option,
searchText: matchingOption ? matchingOption.searchText : option,
};
});
this.set('selectedOptions', formattedOptions);
if (this.options) {

View File

@ -173,6 +173,16 @@ module('Integration | Component | search select', function(hooks) {
assert.equal(component.options.objectAt(0).text, 'Type to search', 'text of option shows Type to search');
});
test('it shows items not in the returned response', async function(assert) {
const models = ['test'];
this.set('models', models);
this.set('inputValue', ['test', 'two']);
await render(
hbs`{{search-select label="foo" inputValue=inputValue models=models fallbackComponent="string-list" onChange=onChange}}`
);
assert.equal(component.selectedOptions.length, 2, 'renders inputOptions as selectedOptions');
});
test('it shows both name and smaller id for identity endpoints', async function(assert) {
const models = ['identity/entity'];
this.set('models', models);