Refactors annotation layer
Formerly, the annotation layer interface provided the GrAnnotation library as a parameter to the `annotate` method. This was so the layer would not necessarily need to import the library at the module level and instead could use it as a utility toolbox. With this change, the library is no-longer part of the interface and the layers are now expected to import it at the module layer (if they have a use for it). Change-Id: I49b96c67ec724708c2861ab6be3ce27a53cc1b05
This commit is contained in:
@@ -286,7 +286,7 @@ limitations under the License.
|
|||||||
// Take a DIV.contentText element and a line object with intraline
|
// Take a DIV.contentText element and a line object with intraline
|
||||||
// differences to highlight and apply them to the element as
|
// differences to highlight and apply them to the element as
|
||||||
// annotations.
|
// annotations.
|
||||||
annotate: function(el, line, GrAnnotation) {
|
annotate: function(el, line) {
|
||||||
var HL_CLASS = 'style-scope gr-diff intraline';
|
var HL_CLASS = 'style-scope gr-diff intraline';
|
||||||
line.highlights.forEach(function(highlight) {
|
line.highlights.forEach(function(highlight) {
|
||||||
// The start and end indices could be the same if a highlight is
|
// The start and end indices could be the same if a highlight is
|
||||||
|
|||||||
@@ -393,7 +393,7 @@
|
|||||||
'lightHighlight' : 'darkHighlight');
|
'lightHighlight' : 'darkHighlight');
|
||||||
|
|
||||||
this.layers.forEach(function(layer) {
|
this.layers.forEach(function(layer) {
|
||||||
layer.annotate(contentText, line, GrAnnotation);
|
layer.annotate(contentText, line);
|
||||||
});
|
});
|
||||||
|
|
||||||
td.appendChild(contentText);
|
td.appendChild(contentText);
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ limitations under the License.
|
|||||||
highlights: [],
|
highlights: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
layer.annotate(el, line, GrAnnotation);
|
layer.annotate(el, line);
|
||||||
|
|
||||||
// The content is unchanged.
|
// The content is unchanged.
|
||||||
assert.isFalse(annotateElementSpy.called);
|
assert.isFalse(annotateElementSpy.called);
|
||||||
@@ -303,7 +303,7 @@ limitations under the License.
|
|||||||
var str3 = slice(str, 18, 22);
|
var str3 = slice(str, 18, 22);
|
||||||
var str4 = slice(str, 22);
|
var str4 = slice(str, 22);
|
||||||
|
|
||||||
layer.annotate(el, line, GrAnnotation);
|
layer.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(annotateElementSpy.called);
|
assert.isTrue(annotateElementSpy.called);
|
||||||
assert.equal(el.childNodes.length, 5);
|
assert.equal(el.childNodes.length, 5);
|
||||||
@@ -335,7 +335,7 @@ limitations under the License.
|
|||||||
var str0 = slice(str, 0, 28);
|
var str0 = slice(str, 0, 28);
|
||||||
var str1 = slice(str, 28);
|
var str1 = slice(str, 28);
|
||||||
|
|
||||||
layer.annotate(el, line, GrAnnotation);
|
layer.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(annotateElementSpy.called);
|
assert.isTrue(annotateElementSpy.called);
|
||||||
assert.equal(el.childNodes.length, 2);
|
assert.equal(el.childNodes.length, 2);
|
||||||
@@ -355,7 +355,7 @@ limitations under the License.
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
layer.annotate(el, line, GrAnnotation);
|
layer.annotate(el, line);
|
||||||
|
|
||||||
assert.isFalse(annotateElementSpy.called);
|
assert.isFalse(annotateElementSpy.called);
|
||||||
assert.equal(el.childNodes.length, 1);
|
assert.equal(el.childNodes.length, 1);
|
||||||
@@ -376,7 +376,7 @@ limitations under the License.
|
|||||||
var str1 = slice(str, 6, 12);
|
var str1 = slice(str, 6, 12);
|
||||||
var str2 = slice(str, 12);
|
var str2 = slice(str, 12);
|
||||||
|
|
||||||
layer.annotate(el, line, GrAnnotation);
|
layer.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(annotateElementSpy.called);
|
assert.isTrue(annotateElementSpy.called);
|
||||||
assert.equal(el.childNodes.length, 3);
|
assert.equal(el.childNodes.length, 3);
|
||||||
@@ -406,7 +406,7 @@ limitations under the License.
|
|||||||
var str0 = slice(str, 0, 6);
|
var str0 = slice(str, 0, 6);
|
||||||
var str1 = slice(str, 6);
|
var str1 = slice(str, 6);
|
||||||
|
|
||||||
layer.annotate(el, line, GrAnnotation);
|
layer.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(annotateElementSpy.called);
|
assert.isTrue(annotateElementSpy.called);
|
||||||
assert.equal(el.childNodes.length, 2);
|
assert.equal(el.childNodes.length, 2);
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ limitations under the License.
|
|||||||
|
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
<dom-module id="gr-ranged-comment-layer">
|
<dom-module id="gr-ranged-comment-layer">
|
||||||
|
<script src="../gr-diff-highlight/gr-annotation.js"></script>
|
||||||
<script src="gr-ranged-comment-layer.js"></script>
|
<script src="gr-ranged-comment-layer.js"></script>
|
||||||
</dom-module>
|
</dom-module>
|
||||||
|
|||||||
@@ -44,9 +44,8 @@
|
|||||||
* @param {HTMLElement} el The DIV.contentText element to apply the
|
* @param {HTMLElement} el The DIV.contentText element to apply the
|
||||||
* annotation to.
|
* annotation to.
|
||||||
* @param {GrDiffLine} line The line object.
|
* @param {GrDiffLine} line The line object.
|
||||||
* @param {Object} GrAnnotation The annotation library.
|
|
||||||
*/
|
*/
|
||||||
annotate: function(el, line, GrAnnotation) {
|
annotate: function(el, line) {
|
||||||
var ranges = [];
|
var ranges = [];
|
||||||
if (line.type === GrDiffLine.Type.REMOVE || (
|
if (line.type === GrDiffLine.Type.REMOVE || (
|
||||||
line.type === GrDiffLine.Type.BOTH &&
|
line.type === GrDiffLine.Type.BOTH &&
|
||||||
|
|||||||
@@ -90,25 +90,31 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite('annotate', function() {
|
suite('annotate', function() {
|
||||||
var GrAnnotation;
|
var sandbox;
|
||||||
var el;
|
var el;
|
||||||
var line;
|
var line;
|
||||||
|
var annotateElementStub;
|
||||||
|
|
||||||
setup(function() {
|
setup(function() {
|
||||||
GrAnnotation = {annotateElement: sinon.stub()};
|
sandbox = sinon.sandbox.create();
|
||||||
|
annotateElementStub = sandbox.stub(GrAnnotation, 'annotateElement');
|
||||||
el = document.createElement('div');
|
el = document.createElement('div');
|
||||||
el.setAttribute('data-side', 'left');
|
el.setAttribute('data-side', 'left');
|
||||||
line = new GrDiffLine(GrDiffLine.Type.BOTH);
|
line = new GrDiffLine(GrDiffLine.Type.BOTH);
|
||||||
line.text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit,';
|
line.text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit,';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
teardown(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
test('type=Remove no-comment', function() {
|
test('type=Remove no-comment', function() {
|
||||||
line.type = GrDiffLine.Type.REMOVE;
|
line.type = GrDiffLine.Type.REMOVE;
|
||||||
line.beforeNumber = 40;
|
line.beforeNumber = 40;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isFalse(GrAnnotation.annotateElement.called);
|
assert.isFalse(annotateElementStub.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('type=Remove has-comment', function() {
|
test('type=Remove has-comment', function() {
|
||||||
@@ -117,10 +123,10 @@ limitations under the License.
|
|||||||
var expectedStart = 6;
|
var expectedStart = 6;
|
||||||
var expectedLength = line.text.length - expectedStart;
|
var expectedLength = line.text.length - expectedStart;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(GrAnnotation.annotateElement.called);
|
assert.isTrue(annotateElementStub.called);
|
||||||
var lastCall = GrAnnotation.annotateElement.lastCall;
|
var lastCall = annotateElementStub.lastCall;
|
||||||
assert.equal(lastCall.args[0], el);
|
assert.equal(lastCall.args[0], el);
|
||||||
assert.equal(lastCall.args[1], expectedStart);
|
assert.equal(lastCall.args[1], expectedStart);
|
||||||
assert.equal(lastCall.args[2], expectedLength);
|
assert.equal(lastCall.args[2], expectedLength);
|
||||||
@@ -135,10 +141,10 @@ limitations under the License.
|
|||||||
var expectedStart = 6;
|
var expectedStart = 6;
|
||||||
var expectedLength = line.text.length - expectedStart;
|
var expectedLength = line.text.length - expectedStart;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(GrAnnotation.annotateElement.called);
|
assert.isTrue(annotateElementStub.called);
|
||||||
var lastCall = GrAnnotation.annotateElement.lastCall;
|
var lastCall = annotateElementStub.lastCall;
|
||||||
assert.equal(lastCall.args[0], el);
|
assert.equal(lastCall.args[0], el);
|
||||||
assert.equal(lastCall.args[1], expectedStart);
|
assert.equal(lastCall.args[1], expectedStart);
|
||||||
assert.equal(lastCall.args[2], expectedLength);
|
assert.equal(lastCall.args[2], expectedLength);
|
||||||
@@ -152,10 +158,10 @@ limitations under the License.
|
|||||||
var expectedStart = 6;
|
var expectedStart = 6;
|
||||||
var expectedLength = line.text.length - expectedStart;
|
var expectedLength = line.text.length - expectedStart;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(GrAnnotation.annotateElement.called);
|
assert.isTrue(annotateElementStub.called);
|
||||||
var lastCall = GrAnnotation.annotateElement.lastCall;
|
var lastCall = annotateElementStub.lastCall;
|
||||||
assert.equal(lastCall.args[0], el);
|
assert.equal(lastCall.args[0], el);
|
||||||
assert.equal(lastCall.args[1], expectedStart);
|
assert.equal(lastCall.args[1], expectedStart);
|
||||||
assert.equal(lastCall.args[2], expectedLength);
|
assert.equal(lastCall.args[2], expectedLength);
|
||||||
@@ -170,9 +176,9 @@ limitations under the License.
|
|||||||
var expectedStart = 6;
|
var expectedStart = 6;
|
||||||
var expectedLength = line.text.length - expectedStart;
|
var expectedLength = line.text.length - expectedStart;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isFalse(GrAnnotation.annotateElement.called);
|
assert.isFalse(annotateElementStub.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('type=Add has-comment', function() {
|
test('type=Add has-comment', function() {
|
||||||
@@ -183,10 +189,10 @@ limitations under the License.
|
|||||||
var expectedStart = 0;
|
var expectedStart = 0;
|
||||||
var expectedLength = 22;
|
var expectedLength = 22;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(GrAnnotation.annotateElement.called);
|
assert.isTrue(annotateElementStub.called);
|
||||||
var lastCall = GrAnnotation.annotateElement.lastCall;
|
var lastCall = annotateElementStub.lastCall;
|
||||||
assert.equal(lastCall.args[0], el);
|
assert.equal(lastCall.args[0], el);
|
||||||
assert.equal(lastCall.args[1], expectedStart);
|
assert.equal(lastCall.args[1], expectedStart);
|
||||||
assert.equal(lastCall.args[2], expectedLength);
|
assert.equal(lastCall.args[2], expectedLength);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
* @param {!HTMLElement} el
|
* @param {!HTMLElement} el
|
||||||
* @param {!GrDiffLine} line
|
* @param {!GrDiffLine} line
|
||||||
*/
|
*/
|
||||||
annotate: function(el, line, GrAnnotation) {
|
annotate: function(el, line) {
|
||||||
// Determine the side.
|
// Determine the side.
|
||||||
var side;
|
var side;
|
||||||
if (line.type === GrDiffLine.Type.REMOVE || (
|
if (line.type === GrDiffLine.Type.REMOVE || (
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ limitations under the License.
|
|||||||
var line = new GrDiffLine(GrDiffLine.Type.REMOVE);
|
var line = new GrDiffLine(GrDiffLine.Type.REMOVE);
|
||||||
line.beforeNumber = 12;
|
line.beforeNumber = 12;
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isFalse(annotationSpy.called);
|
assert.isFalse(annotationSpy.called);
|
||||||
});
|
});
|
||||||
@@ -77,7 +77,7 @@ limitations under the License.
|
|||||||
className: className,
|
className: className,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
element.annotate(el, line, GrAnnotation);
|
element.annotate(el, line);
|
||||||
|
|
||||||
assert.isTrue(annotationSpy.called);
|
assert.isTrue(annotationSpy.called);
|
||||||
assert.equal(annotationSpy.lastCall.args[0], el);
|
assert.equal(annotationSpy.lastCall.args[0], el);
|
||||||
|
|||||||
Reference in New Issue
Block a user