PolyGerrit: Fix search bar not to show user email if it's undefined
GWTUI does not show the email if it's undefined. Other wise it will fail with "Server error: )]}' "User test \u003cundefined\u003e not found"" Change-Id: I00bc79f5463aa7b4ac6e16387a29ccc246c474ce
This commit is contained in:
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<link rel="import" href="../../../behaviors/gr-anonymous-name-behavior/gr-anonymous-name-behavior.html">
|
||||||
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
||||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
|
|||||||
@@ -94,6 +94,7 @@
|
|||||||
is: 'gr-search-bar',
|
is: 'gr-search-bar',
|
||||||
|
|
||||||
behaviors: [
|
behaviors: [
|
||||||
|
Gerrit.AnonymousNameBehavior,
|
||||||
Gerrit.KeyboardShortcutBehavior,
|
Gerrit.KeyboardShortcutBehavior,
|
||||||
Gerrit.URLEncodingBehavior,
|
Gerrit.URLEncodingBehavior,
|
||||||
],
|
],
|
||||||
@@ -128,6 +129,13 @@
|
|||||||
type: Number,
|
type: Number,
|
||||||
value: 1,
|
value: 1,
|
||||||
},
|
},
|
||||||
|
_config: Object,
|
||||||
|
},
|
||||||
|
|
||||||
|
attached() {
|
||||||
|
this.$.restAPI.getConfig().then(cfg => {
|
||||||
|
this._config = cfg;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_valueChanged(value) {
|
_valueChanged(value) {
|
||||||
@@ -161,6 +169,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_accountOrAnon(name) {
|
||||||
|
return this.getUserName(this._config, name, false);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from the API the predicted accounts.
|
* Fetch from the API the predicted accounts.
|
||||||
* @param {string} predicate - The first part of the search term, e.g.
|
* @param {string} predicate - The first part of the search term, e.g.
|
||||||
@@ -177,8 +189,14 @@
|
|||||||
MAX_AUTOCOMPLETE_RESULTS)
|
MAX_AUTOCOMPLETE_RESULTS)
|
||||||
.then(accounts => {
|
.then(accounts => {
|
||||||
if (!accounts) { return []; }
|
if (!accounts) { return []; }
|
||||||
return accounts.map(acct =>
|
return accounts.map(acct => {
|
||||||
predicate + ':"' + acct.name + ' <' + acct.email + '>"');
|
if (acct.email) {
|
||||||
|
return predicate + ':"' + this._accountOrAnon(acct) +
|
||||||
|
' <' + acct.email + '>"';
|
||||||
|
} else {
|
||||||
|
return predicate + ':"' + this._accountOrAnon(acct) + '"';
|
||||||
|
}
|
||||||
|
});
|
||||||
}).then(accounts => {
|
}).then(accounts => {
|
||||||
// When the expression supplied is a beginning substring of 'self',
|
// When the expression supplied is a beginning substring of 'self',
|
||||||
// add it as an autocomplete option.
|
// add it as an autocomplete option.
|
||||||
|
|||||||
@@ -37,11 +37,17 @@ limitations under the License.
|
|||||||
<script>
|
<script>
|
||||||
suite('gr-search-bar tests', () => {
|
suite('gr-search-bar tests', () => {
|
||||||
let element;
|
let element;
|
||||||
|
let sandbox;
|
||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
teardown(() => {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
test('value is propagated to _inputVal', () => {
|
test('value is propagated to _inputVal', () => {
|
||||||
element.value = 'foo';
|
element.value = 'foo';
|
||||||
assert.equal(element._inputVal, 'foo');
|
assert.equal(element._inputVal, 'foo');
|
||||||
@@ -54,7 +60,7 @@ limitations under the License.
|
|||||||
};
|
};
|
||||||
|
|
||||||
test('tap on search button triggers nav', done => {
|
test('tap on search button triggers nav', done => {
|
||||||
sinon.stub(page, 'show', () => {
|
sandbox.stub(page, 'show', () => {
|
||||||
page.show.restore();
|
page.show.restore();
|
||||||
assert.notEqual(getActiveElement(), element.$.searchInput);
|
assert.notEqual(getActiveElement(), element.$.searchInput);
|
||||||
assert.notEqual(getActiveElement(), element.$.searchButton);
|
assert.notEqual(getActiveElement(), element.$.searchButton);
|
||||||
@@ -65,7 +71,7 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('enter in search input triggers nav', done => {
|
test('enter in search input triggers nav', done => {
|
||||||
sinon.stub(page, 'show', () => {
|
sandbox.stub(page, 'show', () => {
|
||||||
page.show.restore();
|
page.show.restore();
|
||||||
assert.notEqual(getActiveElement(), element.$.searchInput);
|
assert.notEqual(getActiveElement(), element.$.searchInput);
|
||||||
assert.notEqual(getActiveElement(), element.$.searchButton);
|
assert.notEqual(getActiveElement(), element.$.searchButton);
|
||||||
@@ -77,27 +83,24 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('search query should be double-escaped', () => {
|
test('search query should be double-escaped', () => {
|
||||||
const showStub = sinon.stub(page, 'show');
|
const showStub = sandbox.stub(page, 'show');
|
||||||
element.$.searchInput.text = 'fate/stay';
|
element.$.searchInput.text = 'fate/stay';
|
||||||
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
null, 'enter');
|
null, 'enter');
|
||||||
assert.equal(showStub.lastCall.args[0], '/q/fate%252Fstay');
|
assert.equal(showStub.lastCall.args[0], '/q/fate%252Fstay');
|
||||||
showStub.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('input blurred after commit', () => {
|
test('input blurred after commit', () => {
|
||||||
const showStub = sinon.stub(page, 'show');
|
sandbox.stub(page, 'show');
|
||||||
const blurSpy = sinon.spy(element.$.searchInput.$.input, 'blur');
|
const blurSpy = sandbox.spy(element.$.searchInput.$.input, 'blur');
|
||||||
element.$.searchInput.text = 'fate/stay';
|
element.$.searchInput.text = 'fate/stay';
|
||||||
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
null, 'enter');
|
null, 'enter');
|
||||||
assert.isTrue(blurSpy.called);
|
assert.isTrue(blurSpy.called);
|
||||||
showStub.restore();
|
|
||||||
blurSpy.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('empty search query does not trigger nav', () => {
|
test('empty search query does not trigger nav', () => {
|
||||||
const showSpy = sinon.spy(page, 'show');
|
const showSpy = sandbox.spy(page, 'show');
|
||||||
element.value = '';
|
element.value = '';
|
||||||
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
|
||||||
null, 'enter');
|
null, 'enter');
|
||||||
@@ -105,16 +108,16 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('keyboard shortcuts', () => {
|
test('keyboard shortcuts', () => {
|
||||||
const focusSpy = sinon.spy(element.$.searchInput, 'focus');
|
const focusSpy = sandbox.spy(element.$.searchInput, 'focus');
|
||||||
const selectAllSpy = sinon.spy(element.$.searchInput, 'selectAll');
|
const selectAllSpy = sandbox.spy(element.$.searchInput, 'selectAll');
|
||||||
MockInteractions.pressAndReleaseKeyOn(document.body, 191, null, '/');
|
MockInteractions.pressAndReleaseKeyOn(document.body, 191, null, '/');
|
||||||
assert.isTrue(focusSpy.called);
|
assert.isTrue(focusSpy.called);
|
||||||
assert.isTrue(selectAllSpy.called);
|
assert.isTrue(selectAllSpy.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('_getSearchSuggestions', () => {
|
suite('_getSearchSuggestions', () => {
|
||||||
setup(() => {
|
test('Autocompletes accounts', done => {
|
||||||
sinon.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
||||||
Promise.resolve([
|
Promise.resolve([
|
||||||
{
|
{
|
||||||
name: 'fred',
|
name: 'fred',
|
||||||
@@ -122,27 +125,6 @@ limitations under the License.
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
sinon.stub(element.$.restAPI, 'getSuggestedGroups', () =>
|
|
||||||
Promise.resolve({
|
|
||||||
Polygerrit: 0,
|
|
||||||
gerrit: 0,
|
|
||||||
gerrittest: 0,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
sinon.stub(element.$.restAPI, 'getSuggestedProjects', () =>
|
|
||||||
Promise.resolve({
|
|
||||||
Polygerrit: 0,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
teardown(() => {
|
|
||||||
element.$.restAPI.getSuggestedAccounts.restore();
|
|
||||||
element.$.restAPI.getSuggestedGroups.restore();
|
|
||||||
element.$.restAPI.getSuggestedProjects.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Autocompletes accounts', done => {
|
|
||||||
element._getSearchSuggestions('owner:fr').then(s => {
|
element._getSearchSuggestions('owner:fr').then(s => {
|
||||||
assert.equal(s[0].value, 'owner:"fred <fred@goog.co>"');
|
assert.equal(s[0].value, 'owner:"fred <fred@goog.co>"');
|
||||||
done();
|
done();
|
||||||
@@ -150,6 +132,14 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Inserts self as option when valid', done => {
|
test('Inserts self as option when valid', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
name: 'fred',
|
||||||
|
email: 'fred@goog.co',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
element._getSearchSuggestions('owner:s').then(s => {
|
element._getSearchSuggestions('owner:s').then(s => {
|
||||||
assert.equal(s[0].value, 'owner:self');
|
assert.equal(s[0].value, 'owner:self');
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
@@ -161,6 +151,14 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Inserts me as option when valid', done => {
|
test('Inserts me as option when valid', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
name: 'fred',
|
||||||
|
email: 'fred@goog.co',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
element._getSearchSuggestions('owner:m').then(s => {
|
element._getSearchSuggestions('owner:m').then(s => {
|
||||||
assert.equal(s[0].value, 'owner:me');
|
assert.equal(s[0].value, 'owner:me');
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
@@ -172,6 +170,13 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Autocompletes groups', done => {
|
test('Autocompletes groups', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedGroups', () =>
|
||||||
|
Promise.resolve({
|
||||||
|
Polygerrit: 0,
|
||||||
|
gerrit: 0,
|
||||||
|
gerrittest: 0,
|
||||||
|
})
|
||||||
|
);
|
||||||
element._getSearchSuggestions('ownerin:pol').then(s => {
|
element._getSearchSuggestions('ownerin:pol').then(s => {
|
||||||
assert.equal(s[0].value, 'ownerin:Polygerrit');
|
assert.equal(s[0].value, 'ownerin:Polygerrit');
|
||||||
done();
|
done();
|
||||||
@@ -179,6 +184,11 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Autocompletes projects', done => {
|
test('Autocompletes projects', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedProjects', () =>
|
||||||
|
Promise.resolve({
|
||||||
|
Polygerrit: 0,
|
||||||
|
})
|
||||||
|
);
|
||||||
element._getSearchSuggestions('project:pol').then(s => {
|
element._getSearchSuggestions('project:pol').then(s => {
|
||||||
assert.equal(s[0].value, 'project:Polygerrit');
|
assert.equal(s[0].value, 'project:Polygerrit');
|
||||||
done();
|
done();
|
||||||
@@ -203,6 +213,13 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Autocomplete doesnt override exact matches to input', done => {
|
test('Autocomplete doesnt override exact matches to input', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedGroups', () =>
|
||||||
|
Promise.resolve({
|
||||||
|
Polygerrit: 0,
|
||||||
|
gerrit: 0,
|
||||||
|
gerrittest: 0,
|
||||||
|
})
|
||||||
|
);
|
||||||
element._getSearchSuggestions('ownerin:gerrit').then(s => {
|
element._getSearchSuggestions('ownerin:gerrit').then(s => {
|
||||||
assert.equal(s[0].value, 'ownerin:gerrit');
|
assert.equal(s[0].value, 'ownerin:gerrit');
|
||||||
done();
|
done();
|
||||||
@@ -210,6 +227,14 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Autocomplete respects spaces', done => {
|
test('Autocomplete respects spaces', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
name: 'fred',
|
||||||
|
email: 'fred@goog.co',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
element._getSearchSuggestions('is:ope').then(s => {
|
element._getSearchSuggestions('is:ope').then(s => {
|
||||||
assert.equal(s[0].name, 'is:open');
|
assert.equal(s[0].name, 'is:open');
|
||||||
assert.equal(s[0].value, 'is:open');
|
assert.equal(s[0].value, 'is:open');
|
||||||
@@ -219,6 +244,34 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Autocompletes accounts with no email', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
name: 'fred',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
|
element._getSearchSuggestions('owner:fr').then(s => {
|
||||||
|
assert.equal(s[0].value, 'owner:"fred"');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Autocompletes accounts with email', done => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
|
||||||
|
Promise.resolve([
|
||||||
|
{
|
||||||
|
email: 'fred@goog.co',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
|
element._getSearchSuggestions('owner:fr').then(s => {
|
||||||
|
assert.equal(s[0].value, 'owner:"Anonymous <fred@goog.co>"');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user