@@ -353,6 +363,44 @@
expectToBasicallyEqual(contentRect.top, divRect.height + tooltip.offset);
});
+ test('tooltip is fitted correctly if in bounds', function() {
+ var f = fixture('basic-fitted');
+ var target = f.querySelector('#target');
+ var tooltip = f.querySelector('paper-tooltip');
+
+ var actualTooltip = dom(tooltip.root).querySelector('#tooltip');
+ assert.isTrue(isHidden(actualTooltip));
+
+ MockInteractions.focus(target);
+ assert.isFalse(isHidden(actualTooltip));
+
+ console.log('divrect')
+ var divRect = target.getBoundingClientRect();
+ expectToBasicallyEqual(divRect.width, 100);
+ expectToBasicallyEqual(divRect.height, 20);
+
+ console.log('contentrect')
+ var divRect = target.getBoundingClientRect();
+ var contentRect = tooltip.getBoundingClientRect();
+ expectToBasicallyEqual(contentRect.width, 70);
+ expectToBasicallyEqual(contentRect.height, 30);
+
+ console.log('positioning')
+ console.log('content left' + contentRect.left)
+ console.log('content top' + contentRect.top)
+ // The target div width is 100, and the tooltip width is 70, and
+ // it's centered. The height of the target div is 20, and the
+ // tooltip is 14px below.
+ expectToBasicallyEqual(contentRect.left, (100 - 70) / 2);
+ expectToBasicallyEqual(contentRect.top, 20 + 14);
+
+ console.log('positioning2')
+ // Also check the math, just in case.
+ expectToBasicallyEqual(
+ contentRect.left, (divRect.width - contentRect.width) / 2);
+ expectToBasicallyEqual(contentRect.top, divRect.height + tooltip.offset);
+ });
+
test(
'tooltip is positioned correctly after being dynamically set',
function() {