wix-style-react
Version:
wix-style-react
134 lines (110 loc) • 3.52 kB
JavaScript
;
var _TooltipPosition = require('./TooltipPosition');
var _TooltipPosition2 = _interopRequireDefault(_TooltipPosition);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
describe('Tooltip position calculation helper', function () {
var anchor = void 0,
element = void 0;
beforeEach(function () {
anchor = new Rect();
element = new Rect();
anchor.at(500, 500).size(100, 100);
element.size(50, 50);
});
it('should not include window scroll X and Y props', function () {
window.scrollX = window.scrollY = 100;
expect((0, _TooltipPosition2.default)(anchor, element, params('top', 'left'))).toEqual({
left: 500,
top: 440
});
});
it('should position top-left ', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('top', 'left'))).toEqual({
left: 500,
top: 440
});
});
it('should position top-center ', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('top', 'center'))).toEqual({
left: 525,
top: 440
});
});
it('should position top-right ', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('top', 'right'))).toEqual({
left: 550,
top: 440
});
});
it('should position right-top', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('right', 'top'))).toEqual({
left: 610,
top: 500
});
});
it('should position right-center', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('right', 'center'))).toEqual({
left: 610,
top: 525
});
});
it('should position right-bottom', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('right', 'bottom'))).toEqual({
left: 610,
top: 550
});
});
it('should position bottom-left', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('bottom', 'left'))).toEqual({
left: 500,
top: 610
});
});
it('should position bottom-center', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('bottom', 'center'))).toEqual({
left: 525,
top: 610
});
});
it('should position bottom-right', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('bottom', 'right'))).toEqual({
left: 550,
top: 610
});
});
it('should position left-top', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('left', 'top'))).toEqual({
left: 440,
top: 500
});
});
it('should position left-center', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('left', 'center'))).toEqual({
left: 440,
top: 525
});
});
it('should position left-bottom', function () {
expect((0, _TooltipPosition2.default)(anchor, element, params('left', 'bottom'))).toEqual({
left: 440,
top: 550
});
});
});
function params(placement, alignment) {
var margin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
return { placement: placement, alignment: alignment, margin: margin };
}
function Rect() {
var _this = this;
this.at = function (left, top) {
_this.left = left;
_this.top = top;
return _this;
};
this.size = function (width, height) {
_this.width = width;
_this.height = height;
return _this;
};
}