Add support for Documentation search
Bug: Issue 6200 Change-Id: Ibcad93bd77835106977e72dea7d62159d5518b67
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<!--
|
||||
@license
|
||||
Copyright (C) 2018 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
|
||||
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/gr-list-view-behavior/gr-list-view-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
|
||||
<link rel="import" href="../../../styles/gr-table-styles.html">
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
<link rel="import" href="../../shared/gr-list-view/gr-list-view.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
|
||||
<dom-module id="gr-documentation-search">
|
||||
<template>
|
||||
<style include="shared-styles"></style>
|
||||
<style include="gr-table-styles"></style>
|
||||
<gr-list-view
|
||||
filter="[[_filter]]"
|
||||
items=false
|
||||
offset=0
|
||||
loading="[[_loading]]"
|
||||
path="[[_path]]">
|
||||
<table id="list" class="genericList">
|
||||
<tr class="headerRow">
|
||||
<th class="name topHeader">Name</th>
|
||||
<th class="name topHeader"></th>
|
||||
<th class="name topHeader"></th>
|
||||
</tr>
|
||||
<tr id="loading" class$="loadingMsg [[computeLoadingClass(_loading)]]">
|
||||
<td>Loading...</td>
|
||||
</tr>
|
||||
<tbody class$="[[computeLoadingClass(_loading)]]">
|
||||
<template is="dom-repeat" items="[[_documentationSearches]]">
|
||||
<tr class="table">
|
||||
<td class="name">
|
||||
<a href$="[[_computeSearchUrl(item.url)]]">[[item.title]]</a>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
</gr-list-view>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
</template>
|
||||
<script src="gr-documentation-search.js"></script>
|
||||
</dom-module>
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
Polymer({
|
||||
is: 'gr-documentation-search',
|
||||
|
||||
properties: {
|
||||
/**
|
||||
* URL params passed from the router.
|
||||
*/
|
||||
params: {
|
||||
type: Object,
|
||||
observer: '_paramsChanged',
|
||||
},
|
||||
|
||||
_path: {
|
||||
type: String,
|
||||
readOnly: true,
|
||||
value: '/Documentation',
|
||||
},
|
||||
_documentationSearches: Array,
|
||||
|
||||
_loading: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
},
|
||||
_filter: {
|
||||
type: String,
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
|
||||
behaviors: [
|
||||
Gerrit.ListViewBehavior,
|
||||
],
|
||||
|
||||
attached() {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent('title-change', {title: 'Documentation Search'}));
|
||||
},
|
||||
|
||||
_paramsChanged(params) {
|
||||
this._loading = true;
|
||||
this._filter = this.getFilterValue(params);
|
||||
|
||||
return this._getDocumentationSearches(this._filter);
|
||||
},
|
||||
|
||||
_getDocumentationSearches(filter) {
|
||||
this._documentationSearches = [];
|
||||
return this.$.restAPI.getDocumentationSearches(filter)
|
||||
.then(searches => {
|
||||
// Late response.
|
||||
if (filter !== this._filter || !searches) { return; }
|
||||
this._documentationSearches = searches;
|
||||
this._loading = false;
|
||||
});
|
||||
},
|
||||
|
||||
_computeSearchUrl(url) {
|
||||
if (!url) { return ''; }
|
||||
return this.getBaseUrl() + '/' + url;
|
||||
},
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,120 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
@license
|
||||
Copyright (C) 2018 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
||||
<title>gr-documentation-search</title>
|
||||
|
||||
<script src="../../../bower_components/page/page.js"></script>
|
||||
<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"/>
|
||||
<link rel="import" href="gr-documentation-search.html">
|
||||
|
||||
<script>void(0);</script>
|
||||
|
||||
<test-fixture id="basic">
|
||||
<template>
|
||||
<gr-documentation-search></gr-documentation-search>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
let counter;
|
||||
const documentationGenerator = () => {
|
||||
return {
|
||||
title: `Gerrit Code Review - REST API Developers Notes${++counter}`,
|
||||
url: 'Documentation/dev-rest-api.html',
|
||||
};
|
||||
};
|
||||
|
||||
suite('gr-documentation-search tests', () => {
|
||||
let element;
|
||||
let documentationSearches;
|
||||
let sandbox;
|
||||
let value;
|
||||
|
||||
setup(() => {
|
||||
sandbox = sinon.sandbox.create();
|
||||
sandbox.stub(page, 'show');
|
||||
element = fixture('basic');
|
||||
counter = 0;
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
suite('list with searches for documentation', () => {
|
||||
setup(done => {
|
||||
documentationSearches = _.times(26, documentationGenerator);
|
||||
stub('gr-rest-api-interface', {
|
||||
getDocumentationSearches() {
|
||||
return Promise.resolve(documentationSearches);
|
||||
},
|
||||
});
|
||||
element._paramsChanged(value).then(() => { flush(done); });
|
||||
});
|
||||
|
||||
test('test for test repo in the list', done => {
|
||||
flush(() => {
|
||||
assert.equal(element._documentationSearches[0].title,
|
||||
'Gerrit Code Review - REST API Developers Notes1');
|
||||
assert.equal(element._documentationSearches[0].url,
|
||||
'Documentation/dev-rest-api.html');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('filter', () => {
|
||||
setup(() => {
|
||||
documentationSearches = _.times(25, documentationGenerator);
|
||||
documentationSearchesFiltered = _.times(1, documentationSearches);
|
||||
});
|
||||
|
||||
test('_paramsChanged', done => {
|
||||
sandbox.stub(element.$.restAPI, 'getDocumentationSearches', () => {
|
||||
return Promise.resolve(documentationSearches);
|
||||
});
|
||||
const value = {
|
||||
filter: 'test',
|
||||
};
|
||||
element._paramsChanged(value).then(() => {
|
||||
assert.isTrue(element.$.restAPI.getDocumentationSearches.lastCall
|
||||
.calledWithExactly('test'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('loading', () => {
|
||||
test('correct contents are displayed', () => {
|
||||
assert.isTrue(element._loading);
|
||||
assert.equal(element.computeLoadingClass(element._loading), 'loading');
|
||||
assert.equal(getComputedStyle(element.$.loading).display, 'block');
|
||||
|
||||
element._loading = false;
|
||||
element._repos = _.times(25, documentationGenerator);
|
||||
|
||||
flushAsynchronousOperations();
|
||||
assert.equal(element.computeLoadingClass(element._loading), '');
|
||||
assert.equal(getComputedStyle(element.$.loading).display, 'none');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user