/*!
 * Custom elements for Nanopore-Digital Web applications
 */
/* eslint-disable */
/* tslint:disable */
/**
 * Utility function that mocks the `IntersectionObserver` API. Necessary for components that rely
 * on it, otherwise the tests will crash. Recommended to execute inside `beforeEach`.
 * @param intersectionObserverMock - Parameter that is sent to the `Object.defineProperty`
 * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
 * mock the intersection observer, but its methods.
 * You can manually fire an intersection entry:
 * @example
 *
 * ```
 * let fireIo;
 * setupIntersectionObserverMock({
 *   observe: function () {
 *     fireIo = this.cb;
 *   },
 * });
 * ...
 * fireIo([{ isIntersecting: true, target: yourMockElemenet }]);
 * ```
 */
export function setupIntersectionObserverMock({ root = null, rootMargin = '', thresholds = [], disconnect = () => null, observe = (_element) => null, takeRecords = () => [], unobserve = () => null, } = {}) {
    const fns = [];
    class MockIntersectionObserver {
        root = root;
        rootMargin = rootMargin;
        thresholds = thresholds;
        disconnect = disconnect;
        observe = observe;
        takeRecords = takeRecords;
        unobserve = unobserve;
        cb = e => {
            fns.forEach(fn => {
                fn.call(this, e);
            });
        };
        constructor(fn) {
            fns.push(fn);
        }
    }
    Object.defineProperty(window, 'IntersectionObserver', {
        writable: true,
        configurable: true,
        value: MockIntersectionObserver,
    });
    Object.defineProperty(global, 'IntersectionObserver', {
        writable: true,
        configurable: true,
        value: MockIntersectionObserver,
    });
    Object.defineProperty(globalThis, 'IntersectionObserver', {
        writable: true,
        configurable: true,
        value: MockIntersectionObserver,
    });
    return MockIntersectionObserver;
}
