summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html')
-rw-r--r--polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html211
1 files changed, 131 insertions, 80 deletions
diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html
index 3ddc96bd17..9551c79c8b 100644
--- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html
+++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html
@@ -20,9 +20,9 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
+<link rel="import" href="../../../test/common-test-setup.html"/>
<script src="../../../bower_components/page/page.js"></script>
-<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-search-bar.html">
<script src="../../../scripts/util.js"></script>
@@ -35,37 +35,32 @@ limitations under the License.
</test-fixture>
<script>
- suite('gr-search-bar tests', function() {
- var element;
+ suite('gr-search-bar tests', () => {
+ let element;
+ let sandbox;
- setup(function() {
+ setup(() => {
+ sandbox = sinon.sandbox.create();
element = fixture('basic');
});
- test('value is propagated to _inputVal', function() {
+ teardown(() => {
+ sandbox.restore();
+ });
+
+ test('value is propagated to _inputVal', () => {
element.value = 'foo';
assert.equal(element._inputVal, 'foo');
});
- function getActiveElement() {
+ getActiveElement = () => {
return document.activeElement.shadowRoot ?
document.activeElement.shadowRoot.activeElement :
document.activeElement;
- }
+ };
- test('tap on search button triggers nav', function(done) {
- sinon.stub(page, 'show', function() {
- page.show.restore();
- assert.notEqual(getActiveElement(), element.$.searchInput);
- assert.notEqual(getActiveElement(), element.$.searchButton);
- done();
- });
- element.value = 'test';
- MockInteractions.tap(element.$.searchButton);
- });
-
- test('enter in search input triggers nav', function(done) {
- sinon.stub(page, 'show', function() {
+ test('enter in search input triggers nav', done => {
+ sandbox.stub(page, 'show', () => {
page.show.restore();
assert.notEqual(getActiveElement(), element.$.searchInput);
assert.notEqual(getActiveElement(), element.$.searchButton);
@@ -76,106 +71,120 @@ limitations under the License.
null, 'enter');
});
- test('search query should be double-escaped', function() {
- var showStub = sinon.stub(page, 'show');
+ test('search query should be double-escaped', () => {
+ const showStub = sandbox.stub(page, 'show');
element.$.searchInput.text = 'fate/stay';
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
null, 'enter');
assert.equal(showStub.lastCall.args[0], '/q/fate%252Fstay');
- showStub.restore();
});
- test('input blurred after commit', function() {
- var showStub = sinon.stub(page, 'show');
- var blurSpy = sinon.spy(element.$.searchInput.$.input, 'blur');
+ test('input blurred after commit', () => {
+ sandbox.stub(page, 'show');
+ const blurSpy = sandbox.spy(element.$.searchInput.$.input, 'blur');
element.$.searchInput.text = 'fate/stay';
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
null, 'enter');
assert.isTrue(blurSpy.called);
- showStub.restore();
- blurSpy.restore();
});
- test('empty search query does not trigger nav', function() {
- var showSpy = sinon.spy(page, 'show');
+ test('empty search query does not trigger nav', () => {
+ const showSpy = sandbox.spy(page, 'show');
element.value = '';
MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
null, 'enter');
assert.isFalse(showSpy.called);
});
- test('keyboard shortcuts', function() {
- var focusSpy = sinon.spy(element.$.searchInput, 'focus');
- var selectAllSpy = sinon.spy(element.$.searchInput, 'selectAll');
+ test('keyboard shortcuts', () => {
+ const focusSpy = sandbox.spy(element.$.searchInput, 'focus');
+ const selectAllSpy = sandbox.spy(element.$.searchInput, 'selectAll');
MockInteractions.pressAndReleaseKeyOn(document.body, 191, null, '/');
assert.isTrue(focusSpy.called);
assert.isTrue(selectAllSpy.called);
});
- suite('_getSearchSuggestions', function() {
- setup(function() {
- sinon.stub(element.$.restAPI, 'getSuggestedAccounts', function() {
- return Promise.resolve([
+ suite('_getSearchSuggestions', () => {
+ test('Autocompletes accounts', () => {
+ sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
+ Promise.resolve([
{
name: 'fred',
email: 'fred@goog.co',
},
- ]);
- });
- sinon.stub(element.$.restAPI, 'getSuggestedGroups', function() {
- return Promise.resolve({
- Polygerrit: 0,
- gerrit: 0,
- gerrittest: 0,
- });
+ ])
+ );
+ return element._getSearchSuggestions('owner:fr').then(s => {
+ assert.equal(s[0].value, 'owner:fred@goog.co');
});
- sinon.stub(element.$.restAPI, 'getSuggestedProjects', function() {
- return Promise.resolve({
- Polygerrit: 0,
- });
- });
- });
-
- teardown(function() {
- element.$.restAPI.getSuggestedAccounts.restore();
- element.$.restAPI.getSuggestedGroups.restore();
- element.$.restAPI.getSuggestedProjects.restore();
});
- test('Autocompletes accounts', function(done) {
- element._getSearchSuggestions('owner:fr').then(function(s) {
- assert.equal(s[0].value, 'owner:"fred <fred@goog.co>"');
- 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 => {
+ assert.equal(s[0].value, 'owner:self');
+ }).then(() => {
+ element._getSearchSuggestions('owner:selfs').then(s => {
+ assert.notEqual(s[0].value, 'owner:self');
+ done();
+ });
});
});
- 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');
+ 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 => {
+ assert.equal(s[0].value, 'owner:me');
+ }).then(() => {
+ element._getSearchSuggestions('owner:meme').then(s => {
+ assert.notEqual(s[0].value, 'owner:me');
done();
});
});
});
- test('Autocompletes groups', function(done) {
- element._getSearchSuggestions('ownerin:pol').then(function(s) {
+ test('Autocompletes groups', done => {
+ sandbox.stub(element.$.restAPI, 'getSuggestedGroups', () =>
+ Promise.resolve({
+ Polygerrit: 0,
+ gerrit: 0,
+ gerrittest: 0,
+ })
+ );
+ element._getSearchSuggestions('ownerin:pol').then(s => {
assert.equal(s[0].value, 'ownerin:Polygerrit');
done();
});
});
- test('Autocompletes projects', function(done) {
- element._getSearchSuggestions('project:pol').then(function(s) {
+ test('Autocompletes projects', done => {
+ sandbox.stub(element.$.restAPI, 'getSuggestedProjects', () =>
+ Promise.resolve({
+ Polygerrit: 0,
+ })
+ );
+ element._getSearchSuggestions('project:pol').then(s => {
assert.equal(s[0].value, 'project:Polygerrit');
done();
});
});
- test('Autocompletes simple searches', function(done) {
- element._getSearchSuggestions('is:o').then(function(s) {
+ test('Autocompletes simple searches', done => {
+ element._getSearchSuggestions('is:o').then(s => {
assert.equal(s[0].name, 'is:open');
assert.equal(s[0].value, 'is:open');
assert.equal(s[1].name, 'is:owner');
@@ -184,31 +193,73 @@ limitations under the License.
});
});
- test('Does not autocomplete with no match', function(done) {
- element._getSearchSuggestions('asdasdasdasd').then(function(s) {
+ test('Does not autocomplete with no match', done => {
+ element._getSearchSuggestions('asdasdasdasd').then(s => {
assert.equal(s.length, 0);
done();
});
});
- test('Autocomplete doesnt override exact matches to input',
- function(done) {
- element._getSearchSuggestions('ownerin:gerrit').then(function(s) {
+ 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 => {
assert.equal(s[0].value, 'ownerin:gerrit');
done();
});
});
- test('Autocomplete respects spaces', function(done) {
- element._getSearchSuggestions('is:ope').then(function(s) {
+ test('Autocomplete respects spaces', done => {
+ sandbox.stub(element.$.restAPI, 'getSuggestedAccounts', () =>
+ Promise.resolve([
+ {
+ name: 'fred',
+ email: 'fred@goog.co',
+ },
+ ])
+ );
+ element._getSearchSuggestions('is:ope').then(s => {
assert.equal(s[0].name, 'is:open');
assert.equal(s[0].value, 'is:open');
- element._getSearchSuggestions('is:ope ').then(function(s) {
+ element._getSearchSuggestions('is:ope ').then(s => {
assert.equal(s.length, 0);
done();
});
});
});
+
+ 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:fred@goog.co');
+ done();
+ });
+ });
});
});
</script>