Make gr-selection-action-box_test cross-platform
Change-Id: Ie60fb4d7cffaca76ac40eebbd35b0196cd63e8e9
This commit is contained in:
		@@ -42,6 +42,16 @@
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    placeAbove: function(el) {
 | 
			
		||||
      var rect = this._getTargetBoundingRect(el);
 | 
			
		||||
      var boxRect = this.getBoundingClientRect();
 | 
			
		||||
      var parentRect = this.parentElement.getBoundingClientRect();
 | 
			
		||||
      this.style.top =
 | 
			
		||||
          rect.top - parentRect.top - boxRect.height - 4 + 'px';
 | 
			
		||||
      this.style.left =
 | 
			
		||||
          rect.left - parentRect.left + (rect.width - boxRect.width)/2 + 'px';
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    _getTargetBoundingRect: function(el) {
 | 
			
		||||
      var rect;
 | 
			
		||||
      if (!(el instanceof Element)) {
 | 
			
		||||
        var range = document.createRange();
 | 
			
		||||
@@ -51,12 +61,7 @@
 | 
			
		||||
      } else {
 | 
			
		||||
        rect = el.getBoundingClientRect();
 | 
			
		||||
      }
 | 
			
		||||
      var boxRect = this.getBoundingClientRect();
 | 
			
		||||
      var parentRect = this.parentElement.getBoundingClientRect();
 | 
			
		||||
      this.style.top =
 | 
			
		||||
          rect.top - parentRect.top - boxRect.height - 4 + 'px';
 | 
			
		||||
      this.style.left =
 | 
			
		||||
          rect.left - parentRect.left + (rect.width - boxRect.width)/2 + 'px';
 | 
			
		||||
      return rect;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    _handleKey: function(e) {
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,7 @@ limitations under the License.
 | 
			
		||||
        target = container.querySelector('.target');
 | 
			
		||||
        sinon.stub(container, 'getBoundingClientRect').returns(
 | 
			
		||||
            {top:1, bottom: 2, left: 3, right: 4, width: 50, height: 6});
 | 
			
		||||
        sinon.stub(target, 'getBoundingClientRect').returns(
 | 
			
		||||
        sinon.stub(element, '_getTargetBoundingRect').returns(
 | 
			
		||||
            {top:42, bottom: 20, left: 30, right: 40, width: 100, height: 60});
 | 
			
		||||
        sinon.stub(element, 'getBoundingClientRect').returns(
 | 
			
		||||
            {width: 10, height: 10});
 | 
			
		||||
@@ -93,7 +93,7 @@ limitations under the License.
 | 
			
		||||
      teardown(function() {
 | 
			
		||||
        element.getBoundingClientRect.restore();
 | 
			
		||||
        container.getBoundingClientRect.restore();
 | 
			
		||||
        target.getBoundingClientRect.restore();
 | 
			
		||||
        element._getTargetBoundingRect.restore();
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      test('placeAbove for Element argument', function() {
 | 
			
		||||
@@ -104,7 +104,17 @@ limitations under the License.
 | 
			
		||||
 | 
			
		||||
      test('placeAbove for Text Node argument', function() {
 | 
			
		||||
        element.placeAbove(target.firstChild);
 | 
			
		||||
        assert.equal(element.style.top, '-7px');
 | 
			
		||||
        assert.equal(element.style.top, '27px');
 | 
			
		||||
        assert.equal(element.style.left, '72px');
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      test('uses document.createRange', function() {
 | 
			
		||||
        sinon.spy(document, 'createRange');
 | 
			
		||||
        element._getTargetBoundingRect.restore();
 | 
			
		||||
        sinon.spy(element, '_getTargetBoundingRect');
 | 
			
		||||
        element.placeAbove(target.firstChild);
 | 
			
		||||
        assert.isTrue(document.createRange.called);
 | 
			
		||||
        document.createRange.restore();
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user