"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const dom_1 = require("@quilted/react-testing/dom");
const Popper_1 = require("./Popper");
const context_1 = require("./context");
const offsets_1 = require("./utilities/offsets");
const defaultProps = {
    activator: null,
};
describe('<Popper />', () => {
    it('render its children', () => {
        const content = 'content';
        const popper = dom_1.mount(<Popper_1.Popper {...defaultProps}>{content}</Popper_1.Popper>);
        expect(popper).toContainReactText('content');
    });
    it('wraps children with PopperContext', () => {
        const content = 'content';
        const placement = 'blockEnd';
        const popper = dom_1.mount(<Popper_1.Popper placement={placement} {...defaultProps}>
        {content}
      </Popper_1.Popper>);
        expect(popper).toProvideReactContext(context_1.PopperContext, {
            offsets: {
                x: 0,
                y: 0,
            },
            clipping: { left: 0, right: 0 },
            spacing: 0,
            placement,
            popperRect: {
                bottom: 0,
                height: 0,
                left: 0,
                right: 0,
                top: 0,
                width: 0,
            },
            referenceRect: null,
        });
    });
    describe('computeOffsets', () => {
        it('computes default offsets when reference and popper rect are null', () => {
            const { offsets } = offsets_1.computeOffsets('blockStart', null, null);
            expect(offsets).toStrictEqual({ x: 0, y: 0 });
        });
        it('computes top center offsets with reference larger than popper', () => {
            const referenceWidth = 100;
            const referenceHeight = 40;
            const popperWidth = 40;
            const popperHeight = 20;
            const referenceRect = {
                bottom: 100 + referenceHeight,
                height: referenceHeight,
                top: 100,
                left: 100,
                width: referenceWidth,
                right: 100 + referenceWidth,
            };
            const popperRect = {
                bottom: popperHeight,
                height: popperHeight,
                right: popperWidth,
                width: popperWidth,
            };
            const { offsets } = offsets_1.computeOffsets('blockStart', popperRect, referenceRect);
            expect(offsets).toStrictEqual({ x: 130, y: 80 });
            expect(offsets.x).toBeGreaterThan(referenceRect.left);
            expect(offsets.y).toBeLessThan(referenceRect.top);
        });
        it('computes bottom center offsets with reference larger than popper', () => {
            const referenceWidth = 100;
            const referenceHeight = 40;
            const popperWidth = 40;
            const popperHeight = 20;
            const referenceRect = {
                bottom: 100 + referenceHeight,
                height: referenceHeight,
                top: 100,
                left: 100,
                width: referenceWidth,
                right: 100 + referenceWidth,
            };
            const popperRect = {
                bottom: popperHeight,
                height: popperHeight,
                right: popperWidth,
                width: popperWidth,
            };
            const { offsets } = offsets_1.computeOffsets('blockEnd', popperRect, referenceRect);
            expect(offsets).toStrictEqual({ x: 130, y: 140 });
            expect(offsets.x).toBeGreaterThan(referenceRect.left);
            expect(offsets.y).toBeGreaterThan(referenceRect.top);
        });
        it('computes top center offsets with reference smaller than popper', () => {
            const referenceWidth = 40;
            const referenceHeight = 20;
            const popperWidth = 100;
            const popperHeight = 40;
            const referenceRect = {
                bottom: 100 + referenceHeight,
                height: referenceHeight,
                top: 100,
                left: 100,
                width: referenceWidth,
                right: 100 + referenceWidth,
            };
            const popperRect = {
                bottom: popperHeight,
                height: popperHeight,
                right: popperWidth,
                width: popperWidth,
            };
            const { offsets } = offsets_1.computeOffsets('blockStart', popperRect, referenceRect);
            expect(offsets).toStrictEqual({ x: 70, y: 60 });
            expect(offsets.x).toBeLessThan(referenceRect.left);
            expect(offsets.y).toBeLessThan(referenceRect.top);
        });
        it('computes bottom center offsets with reference smaller than popper', () => {
            const referenceWidth = 40;
            const referenceHeight = 20;
            const popperWidth = 100;
            const popperHeight = 40;
            const referenceRect = {
                bottom: 100 + referenceHeight,
                height: referenceHeight,
                top: 100,
                left: 100,
                width: referenceWidth,
                right: 100 + referenceWidth,
            };
            const popperRect = {
                bottom: popperHeight,
                height: popperHeight,
                right: popperWidth,
                width: popperWidth,
            };
            const { offsets } = offsets_1.computeOffsets('blockEnd', popperRect, referenceRect);
            expect(offsets).toStrictEqual({ x: 70, y: 120 });
            expect(offsets.x).toBeLessThan(referenceRect.left);
            expect(offsets.y).toBeGreaterThan(referenceRect.top);
        });
        it('computes offsets with reference larger than popper and sameInlineSize option', () => {
            const referenceWidth = 100;
            const referenceHeight = 40;
            const popperWidth = 40;
            const popperHeight = 20;
            const referenceRect = {
                bottom: 100 + referenceHeight,
                height: referenceHeight,
                top: 100,
                left: 100,
                width: referenceWidth,
                right: 100 + referenceWidth,
            };
            const popperRect = {
                bottom: popperHeight,
                height: popperHeight,
                right: popperWidth,
                width: popperWidth,
            };
            const { offsets } = offsets_1.computeOffsets('blockStart', popperRect, referenceRect, {
                sameInlineSize: true,
            });
            expect(offsets).toStrictEqual({ x: 100, y: 80 });
            expect(offsets.x).toBe(referenceRect.left);
            expect(offsets.y).toBeLessThan(referenceRect.top);
        });
    });
});
