"use strict";

var _utils = require("./utils");
describe('utils', () => {
  describe('getScrollParent', () => {
    afterEach(() => {
      document.body.innerHTML = '';
    });
    it('should return the nearest scrollable parent', () => {
      document.body.innerHTML = '<div data-hook="inner">' + '  <div data-hook="scrollable" style="overflow: auto;">' + '    <button id="button"></button>' + '  </div>' + '</div>';
      var button = document.getElementById('button');
      var scrollableDiv = document.querySelector('[data-hook="scrollable"]');
      var result = (0, _utils.getScrollParent)(button);
      expect(result).toBe(scrollableDiv);
    });
    it('should return the body if no scrollable parent is found', () => {
      document.body.innerHTML = '<div data-hook="inner">' + '  <div data-hook="scrollable">' + '    <button id="button"></button>' + '  </div>' + '</div>';
      var button = document.getElementById('button');
      var result = (0, _utils.getScrollParent)(button);
      expect(result).toBe(document.body);
    });
  });
  describe('getByPredicate', () => {
    afterEach(() => {
      document.body.innerHTML = '';
    });
    it('should return the element that matches the predicate', () => {
      document.body.innerHTML = "\n        <div id=\"root\">\n          <div class=\"child\" id=\"child1\"></div>\n          <div class=\"child\" id=\"child2\"></div>\n          <div class=\"child\" id=\"child3\"></div>\n        </div>\n      ";
      var element = document.getElementById('child2');
      var predicate = el => el.id === 'root';
      var result = (0, _utils.getByPredicate)(predicate, element);
      expect(result).not.toBeNull();
      expect(result == null ? void 0 : result.id).toBe('root');
    });
    it('should return null if no element matches the predicate', () => {
      document.body.innerHTML = "\n        <div id=\"root\">\n          <div class=\"child\" id=\"child1\"></div>\n          <div class=\"child\" id=\"child2\"></div>\n          <div class=\"child\" id=\"child3\"></div>\n        </div>\n      ";
      var element = document.getElementById('child4');
      var predicate = el => el.id === 'root';
      var result = (0, _utils.getByPredicate)(predicate, element);
      expect(result).toBeNull();
    });
    it('should return the root element if it matches the predicate', () => {
      document.body.innerHTML = "\n        <div id=\"root\">\n          <div class=\"child\" id=\"child1\"></div>\n          <div class=\"child\" id=\"child2\"></div>\n          <div class=\"child\" id=\"child3\"></div>\n        </div>\n      ";
      var element = document.getElementById('child2');
      var predicate = el => el.id === 'child2';
      var result = (0, _utils.getByPredicate)(predicate, element);
      expect(result).not.toBeNull();
      expect(result == null ? void 0 : result.id).toBe('child2');
    });
    it('should return the html element if no matches found', () => {
      document.body.innerHTML = "\n        <div id=\"root\">\n          <div class=\"child\" id=\"child1\"></div>\n          <div class=\"child\" id=\"child2\"></div>\n          <div class=\"child\" id=\"child3\"></div>\n        </div>\n      ";
      var element = document.getElementById('child2');
      var predicate = el => el.id === 'child4';
      var result = (0, _utils.getByPredicate)(predicate, element);
      expect(result).not.toBeNull();
      expect(result == null ? void 0 : result.nodeName).toBe('HTML');
    });
  });
});
//# sourceMappingURL=utils.spec.js.map