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 formattedOptions = this.selectedOptions.map(option => {
let matchingOption = options.findBy('id', option); let matchingOption = options.findBy('id', option);
options.removeObject(matchingOption); 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); this.set('selectedOptions', formattedOptions);
if (this.options) { 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'); 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) { test('it shows both name and smaller id for identity endpoints', async function(assert) {
const models = ['identity/entity']; const models = ['identity/entity'];
this.set('models', models); this.set('models', models);