Merge "Expose reply dialog and label score value to plugins."

This commit is contained in:
Viktar Donich
2017-06-02 16:35:55 +00:00
committed by Gerrit Code Review
12 changed files with 399 additions and 62 deletions

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2017 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="../../shared/gr-js-api-interface/gr-js-api-interface.html">
<dom-module id="gr-endpoint-decorator">
<template>
<content></content>
</template>
<script src="gr-endpoint-decorator.js"></script>
</dom-module>

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2017 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-endpoint-decorator',
properties: {
name: String,
},
_import(url) {
return new Promise((resolve, reject) => {
this.importHref(url, resolve, reject);
});
},
_initPluginDomHook(name, plugin) {
const el = document.createElement(name);
el.plugin = plugin;
el.content = this.getContentChildren()[0];
return Polymer.dom(this.root).appendChild(el);
},
ready() {
Gerrit.awaitPluginsLoaded().then(() => Promise.all(
Gerrit._getPluginsForEndpoint(this.name).map(
pluginUrl => this._import(pluginUrl)))
).then(() => {
const modulesData = Gerrit._getEndpointDetails(this.name);
for (const {moduleName, plugin} of modulesData) {
this._initPluginDomHook(moduleName, plugin);
}
});
},
});
})();

View File

@@ -0,0 +1,71 @@
<!DOCTYPE html>
<!--
Copyright (C) 2017 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-endpoint-decorator</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-endpoint-decorator.html">
<test-fixture id="basic">
<template>
<gr-endpoint-decorator name="foo"></gr-endpoint-decorator>
</template>
</test-fixture>
<script>
suite('gr-endpoint-decorator', () => {
let sandbox;
let element;
let plugin;
setup(done => {
sandbox = sinon.sandbox.create();
// NB: Order is important.
Gerrit.install(p => {
plugin = p;
plugin.registerCustomComponent('foo', 'some-module');
}, '0.1', 'http://some/plugin/url.html');
sandbox.stub(Gerrit, 'awaitPluginsLoaded').returns(Promise.resolve());
element = fixture('basic');
sandbox.stub(element, '_initPluginDomHook');
sandbox.stub(element, 'importHref', (url, resolve) => { resolve(); });
flush(done);
});
teardown(() => {
sandbox.restore();
});
test('imports plugin-provided module', () => {
assert.isTrue(
element.importHref.calledWith(new URL('http://some/plugin/url.html')));
});
test('inits plugin-provided dom hook', () => {
assert.isTrue(
element._initPluginDomHook.calledWith('some-module', plugin));
});
});
</script>

View File

@@ -34,24 +34,13 @@
},
ready() {
Gerrit.awaitPluginsLoaded().then(() => {
const sharedStyles = Gerrit._styleModules[this.name];
if (sharedStyles) {
const pluginUrls = [];
const moduleNames = [];
sharedStyles.reduce((result, item) => {
if (!result.pluginUrls.includes(item.pluginUrl)) {
result.pluginUrls.push(item.pluginUrl);
}
result.moduleNames.push(item.moduleName);
return result;
}, {pluginUrls, moduleNames});
Promise.all(pluginUrls.map(this._import.bind(this)))
.then(() => {
for (const name of moduleNames) {
this._applyStyle(name);
}
});
Gerrit.awaitPluginsLoaded().then(() => Promise.all(
Gerrit._getPluginsForEndpoint(this.name).map(
pluginUrl => this._import(pluginUrl)))
).then(() => {
const moduleNames = Gerrit._getModulesForEndoint(this.name);
for (const name of moduleNames) {
this._applyStyle(name);
}
});
},

View File

@@ -30,18 +30,26 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-change-metadata integration tests', () => {
suite('gr-external-style integration tests', () => {
let sandbox;
let element;
setup(done => {
sandbox = sinon.sandbox.create();
// NB: Order is important.
let plugin;
Gerrit.install(p => {
plugin = p;
plugin.registerStyleModule('foo', 'some-module');
}, '0.1', 'http://some/plugin/url.html');
sandbox.stub(Gerrit, 'awaitPluginsLoaded').returns(Promise.resolve());
Gerrit._styleModules = {foo: [{pluginUrl: 'bar', moduleName: 'baz'}]};
element = fixture('basic');
sandbox.stub(element, '_applyStyle');
sandbox.stub(element, 'importHref', (url, resolve) => { resolve(); });
flush(done);
});
@@ -50,11 +58,12 @@ limitations under the License.
});
test('imports plugin-provided module', () => {
assert.isTrue(element.importHref.calledWith('bar'));
assert.isTrue(element.importHref.calledWith(
new URL('http://some/plugin/url.html')));
});
test('applies plugin-provided styles', () => {
assert.isTrue(element._applyStyle.calledWith('baz'));
assert.isTrue(element._applyStyle.calledWith('some-module'));
});
});
</script>