Remove dependency on gr-js-api from gr-diff-builder

* Move getDiffLayers API call from gr-diff-builder to gr-diff-host
  to remove dependency on gr-js-api

Change-Id: I58b8b227d4f0a839152e58b6bf7662307e9f557a
This commit is contained in:
Dhruv Srivastava
2019-09-19 15:46:29 +02:00
parent d8546f610e
commit 7ebdb77783
7 changed files with 56 additions and 20 deletions

View File

@@ -138,6 +138,10 @@ limitations under the License.
* @type {?Object}
*/
_cancelableRenderPromise: Object,
pluginLayers: {
type: Array,
value: [],
},
},
behaviors: [
@@ -223,12 +227,7 @@ limitations under the License.
this.$.coverageLayerLeft,
this.$.coverageLayerRight,
];
// Get layers from plugins (if any).
for (const pluginLayer of this.$.jsAPI.getDiffLayers(
this.diffPath, this.changeNum, this.patchNum)) {
layers.push(pluginLayer);
}
layers.push(...this.pluginLayers);
this._layers = layers;
},

View File

@@ -36,8 +36,8 @@ limitations under the License.
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-diff-builder>
<template is="dom-template">
<gr-diff-builder plugin-layers="[[pluginLayers]]">
<table id="diffTable"></table>
</gr-diff-builder>
</template>
@@ -593,28 +593,34 @@ limitations under the License.
suite('layers from plugins', () => {
let element;
let initialLayersCount;
let withPluginLayerCount;
setup(() => {
element = fixture('basic');
const pluginLayers = [];
element = fixture('basic', {pluginLayers});
element._showTrailingWhitespace = true;
element._setupAnnotationLayers();
initialLayersCount = element._layers.length;
});
test('no plugin layers', () => {
const getDiffLayersStub = sinon.stub(element.$.jsAPI, 'getDiffLayers')
.returns([]);
element._setupAnnotationLayers();
assert.isTrue(getDiffLayersStub.called);
assert.equal(element._layers.length, initialLayersCount);
});
test('with plugin layers', () => {
const getDiffLayersStub = sinon.stub(element.$.jsAPI, 'getDiffLayers')
.returns([{}, {}]);
element._setupAnnotationLayers();
assert.isTrue(getDiffLayersStub.called);
assert.equal(element._layers.length, initialLayersCount + 2);
suite('with plugin layers', () => {
const pluginLayers = [{}, {}];
setup(() => {
element = fixture('basic', {pluginLayers});
element._showTrailingWhitespace = true;
element._setupAnnotationLayers();
withPluginLayerCount = element._layers.length;
});
test('with plugin layers', () => {
element._setupAnnotationLayers();
assert.equal(element._layers.length, withPluginLayerCount);
assert.equal(initialLayersCount + pluginLayers.length,
withPluginLayerCount);
});
});
});

View File

@@ -49,6 +49,7 @@ limitations under the License.
revision-image=[[_revisionImage]]
coverage-ranges="[[_coverageRanges]]"
blame="[[_blame]]"
plugin-layers="[[pluginLayers]]"
diff="[[_diff]]"></gr-diff>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>

View File

@@ -204,6 +204,11 @@
type: Number,
computed: '_computeParentIndex(patchRange.*)',
},
pluginLayers: {
type: Array,
value: [],
},
},
behaviors: [
@@ -253,6 +258,14 @@
this._errorMessage = null;
const whitespaceLevel = this._getIgnoreWhitespace();
const pluginLayers = [];
// Get layers from plugins (if any).
for (const pluginLayer of this.$.jsAPI.getDiffLayers(
this.diffPath, this.changeNum, this.patchNum)) {
pluginLayers.push(pluginLayer);
}
this.push('pluginLayers', ...pluginLayers);
this._coverageRanges = [];
const {changeNum, path, patchRange: {basePatchNum, patchNum}} = this;
this.$.jsAPI.getCoverageRanges(changeNum, path, basePatchNum, patchNum).

View File

@@ -51,7 +51,6 @@ limitations under the License.
time: sandbox.stub(),
timeEnd: sandbox.stub(),
});
element = fixture('basic');
});
@@ -59,6 +58,22 @@ limitations under the License.
sandbox.restore();
});
suite('plugin layers', () => {
const pluginLayers = [{}, {}];
setup(() => {
stub('gr-js-api-interface', {
getDiffLayers() { return pluginLayers; },
});
element = fixture('basic');
});
test('plugin layers requested', () => {
element.patchRange = {};
element.reload();
assert(element.$.jsAPI.getDiffLayers.called);
});
});
suite('handle comment-update', () => {
setup(() => {
sandbox.stub(element, '_commentsChanged');

View File

@@ -378,6 +378,7 @@ limitations under the License.
line-wrapping="[[lineWrapping]]"
is-image-diff="[[isImageDiff]]"
base-image="[[baseImage]]"
plugin-layers="[[pluginLayers]]"
revision-image="[[revisionImage]]">
<table
id="diffTable"

View File

@@ -271,6 +271,7 @@
/** Set by Polymer. */
isAttached: Boolean,
pluginLayers: Array,
},
behaviors: [