Add 'self' to account autocomplete options

Adds 'self' as an autocomplete option when the expression supplied is
a beginning substring of 'self'.

Bug: Issue 5695
Change-Id: I25437f51b420e1229dadeafd0be5559a3ad0d1e4
This commit is contained in:
Kasper Nilsson
2017-03-03 12:54:38 -08:00
parent edca4c985b
commit 47666fab39
2 changed files with 20 additions and 2 deletions

View File

@@ -80,6 +80,8 @@
'tr',
];
var SELF_EXPRESSION = 'self';
var MAX_AUTOCOMPLETE_RESULTS = 10;
var TOKENIZE_REGEX = /(?:[^\s"]+|"[^"]*")+\s*/g;
@@ -170,6 +172,12 @@
return accounts.map(function(acct) {
return predicate + ':"' + acct.name + ' <' + acct.email + '>"';
});
}).then(function(accounts) {
// When the expression supplied is a beginning substring of 'self',
// add it as an autocomplete option.
return SELF_EXPRESSION.indexOf(expression) === 0 ?
accounts.concat([predicate + ':' + SELF_EXPRESSION]) :
accounts;
});
},

View File

@@ -110,8 +110,7 @@ limitations under the License.
assert.isTrue(selectAllSpy.called);
});
suite('_getSearchSuggestions',
function() {
suite('_getSearchSuggestions', function() {
setup(function() {
sinon.stub(element.$.restAPI, 'getSuggestedAccounts', function() {
return Promise.resolve([
@@ -148,6 +147,17 @@ limitations under the License.
});
});
test('Inserts self as option when valid', function(done) {
element._getSearchSuggestions('owner:s').then(function(s) {
assert.equal(s[0].value, 'owner:self');
}).then(function() {
element._getSearchSuggestions('owner:selfs').then(function(s) {
assert.notEqual(s[0].value, 'owner:self');
done();
});
});
});
test('Autocompletes groups', function(done) {
element._getSearchSuggestions('ownerin:pol').then(function(s) {
assert.equal(s[0].value, 'ownerin:Polygerrit');