"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("@testing-library/react");
const use_click_away_1 = require("./use-click-away");
describe('useClickAway', () => {
    let ref;
    let onClickAway;
    beforeEach(() => {
        ref = { current: document.createElement('div') };
        onClickAway = jest.fn();
        document.body.appendChild(ref.current);
    });
    afterEach(() => {
        document.body.removeChild(ref.current);
        jest.clearAllMocks();
    });
    it('should call onClickAway when clicking outside the ref element', () => {
        (0, react_1.renderHook)(() => (0, use_click_away_1.useClickAway)(ref, onClickAway));
        const outsideElement = document.createElement('div');
        document.body.appendChild(outsideElement);
        outsideElement.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
        expect(onClickAway).toHaveBeenCalledTimes(1);
        document.body.removeChild(outsideElement);
    });
    it('should not call onClickAway when clicking inside the ref element', () => {
        (0, react_1.renderHook)(() => (0, use_click_away_1.useClickAway)(ref, onClickAway));
        ref.current.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
        expect(onClickAway).not.toHaveBeenCalled();
    });
    it('should clean up event listeners on unmount', () => {
        const { unmount } = (0, react_1.renderHook)(() => (0, use_click_away_1.useClickAway)(ref, onClickAway));
        unmount();
        const outsideElement = document.createElement('div');
        document.body.appendChild(outsideElement);
        outsideElement.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
        expect(onClickAway).not.toHaveBeenCalled();
        document.body.removeChild(outsideElement);
    });
});
