mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-29 03:43:16 +08:00
fix(alias-list): Editable list wont create empty items
- Update alias coercion to include name by default
This commit is contained in:
parent
4861c3e2ab
commit
0cfa9848e7
3 changed files with 17 additions and 2 deletions
|
@ -39,7 +39,7 @@ class PreferencesAccountDetails extends Component {
|
|||
const emailRegex = RegExpUtils.emailRegex();
|
||||
const match = emailRegex.exec(str);
|
||||
if (!match) {
|
||||
return `${str} <${account.emailAddress}>`;
|
||||
return `${str || account.name} <${account.emailAddress}>`;
|
||||
}
|
||||
const email = match[0];
|
||||
let name = str.slice(0, Math.max(0, match.index - 1));
|
||||
|
|
|
@ -104,6 +104,18 @@ describe('EditableList', ()=> {
|
|||
|
||||
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', ()=> {
|
||||
|
|
|
@ -116,7 +116,9 @@ class EditableList extends Component {
|
|||
|
||||
_createItem = (value)=> {
|
||||
this._clearCreatingState(()=> {
|
||||
this.props.onItemCreated(value);
|
||||
if (value) {
|
||||
this.props.onItemCreated(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -132,6 +134,7 @@ class EditableList extends Component {
|
|||
}
|
||||
return this.state.selected;
|
||||
}
|
||||
|
||||
_selectItem = (item, idx)=> {
|
||||
if (this.props.onSelectItem) {
|
||||
this.props.onSelectItem(item, idx);
|
||||
|
|
Loading…
Reference in a new issue