fix(alias-list): Editable list wont create empty items

- Update alias coercion to include name by default
This commit is contained in:
Juan Tejada 2016-02-01 12:45:52 -08:00
parent 4861c3e2ab
commit 0cfa9848e7
3 changed files with 17 additions and 2 deletions

View file

@ -39,7 +39,7 @@ class PreferencesAccountDetails extends Component {
const emailRegex = RegExpUtils.emailRegex(); const emailRegex = RegExpUtils.emailRegex();
const match = emailRegex.exec(str); const match = emailRegex.exec(str);
if (!match) { if (!match) {
return `${str} <${account.emailAddress}>`; return `${str || account.name} <${account.emailAddress}>`;
} }
const email = match[0]; const email = match[0];
let name = str.slice(0, Math.max(0, match.index - 1)); let name = str.slice(0, Math.max(0, match.index - 1));

View file

@ -104,6 +104,18 @@ describe('EditableList', ()=> {
expect(onItemCreated).toHaveBeenCalledWith('New Item'); expect(onItemCreated).toHaveBeenCalledWith('New Item');
}); });
it('does not call onItemCreated when no value entered', ()=> {
const onItemCreated = jasmine.createSpy('onItemCreated');
const list = makeList(['1', '2'], {initialState: {creatingItem: true}, onItemCreated});
const createItem = findRenderedDOMComponentWithClass(list, 'create-item-input');
const input = findRenderedDOMComponentWithTag(createItem, 'input');
findDOMNode(input).value = '';
Simulate.keyDown(input, {key: 'Enter'});
expect(onItemCreated).not.toHaveBeenCalled();
});
}); });
describe('_onCreateItem', ()=> { describe('_onCreateItem', ()=> {

View file

@ -116,7 +116,9 @@ class EditableList extends Component {
_createItem = (value)=> { _createItem = (value)=> {
this._clearCreatingState(()=> { this._clearCreatingState(()=> {
this.props.onItemCreated(value); if (value) {
this.props.onItemCreated(value);
}
}); });
} }
@ -132,6 +134,7 @@ class EditableList extends Component {
} }
return this.state.selected; return this.state.selected;
} }
_selectItem = (item, idx)=> { _selectItem = (item, idx)=> {
if (this.props.onSelectItem) { if (this.props.onSelectItem) {
this.props.onSelectItem(item, idx); this.props.onSelectItem(item, idx);