define(["require", "exports", "./portalContainsElement", "./setPortalAttribute", "./elementContains", "./getParent"], function (require, exports, portalContainsElement_1, setPortalAttribute_1, elementContains_1, getParent_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var unattachedSvg = document.createElement('svg'); var unattachedDiv = document.createElement('div'); var parentDiv = document.createElement('div'); var childDiv = document.createElement('div'); parentDiv.appendChild(childDiv); describe('elementContains', function () { it('can find a child', function () { expect((0, elementContains_1.elementContains)(parentDiv, childDiv)).toEqual(true); }); it('can return false on an unattached child', function () { expect((0, elementContains_1.elementContains)(parentDiv, unattachedDiv)).toEqual(false); }); it('can return false on a null child', function () { expect((0, elementContains_1.elementContains)(parentDiv, null)).toEqual(false); }); it('can return false on a null parent', function () { expect((0, elementContains_1.elementContains)(null, null)).toEqual(false); }); it('can return false when parent is an svg', function () { expect((0, elementContains_1.elementContains)(unattachedSvg, unattachedDiv)).toEqual(false); }); }); describe('getParent', function () { it('returns correct parent for inner SVG elements', function () { var childSvg = document.createElement('svg'); var svgRectangle = document.createElement('rect'); childSvg.appendChild(svgRectangle); parentDiv.appendChild(childSvg); expect((0, getParent_1.getParent)(svgRectangle)).toEqual(childSvg); expect((0, getParent_1.getParent)(childSvg)).toEqual(parentDiv); }); }); describe('setPortalAttribute', function () { it('sets attribute', function () { var testDiv = document.createElement('div'); expect(testDiv.getAttribute(setPortalAttribute_1.DATA_PORTAL_ATTRIBUTE)).toBeFalsy(); (0, setPortalAttribute_1.setPortalAttribute)(testDiv); expect(testDiv.getAttribute(setPortalAttribute_1.DATA_PORTAL_ATTRIBUTE)).toBeTruthy(); }); }); describe('portalContainsElement', function () { var root; var leaf; var parent; var portal; var unlinked; beforeEach(function () { root = document.createElement('div'); leaf = document.createElement('div'); parent = document.createElement('div'); portal = document.createElement('div'); unlinked = document.createElement('div'); (0, setPortalAttribute_1.setPortalAttribute)(portal); }); it('works with and without parent specified', function () { root.appendChild(parent); parent.appendChild(portal); portal.appendChild(leaf); expect((0, portalContainsElement_1.portalContainsElement)(root)).toBeFalsy(); expect((0, portalContainsElement_1.portalContainsElement)(parent)).toBeFalsy(); expect((0, portalContainsElement_1.portalContainsElement)(portal)).toBeTruthy(); expect((0, portalContainsElement_1.portalContainsElement)(leaf)).toBeTruthy(); expect((0, portalContainsElement_1.portalContainsElement)(leaf, parent)).toBeTruthy(); }); it('works correctly when parent and child are in same portal', function () { root.appendChild(portal); portal.appendChild(parent); parent.appendChild(leaf); expect((0, portalContainsElement_1.portalContainsElement)(parent)).toBeTruthy(); expect((0, portalContainsElement_1.portalContainsElement)(leaf, parent)).toBeFalsy(); }); it('works with hierarchically invalid parents', function () { root.appendChild(parent); parent.appendChild(portal); portal.appendChild(leaf); // When parent is invalid, searches should go to root expect((0, portalContainsElement_1.portalContainsElement)(root, leaf)).toBeFalsy(); expect((0, portalContainsElement_1.portalContainsElement)(parent, leaf)).toBeFalsy(); expect((0, portalContainsElement_1.portalContainsElement)(portal, leaf)).toBeTruthy(); expect((0, portalContainsElement_1.portalContainsElement)(leaf, unlinked)).toBeTruthy(); }); it('works when element is parent', function () { root.appendChild(parent); parent.appendChild(portal); portal.appendChild(leaf); expect((0, portalContainsElement_1.portalContainsElement)(root, root)).toBeFalsy(); expect((0, portalContainsElement_1.portalContainsElement)(parent, parent)).toBeFalsy(); expect((0, portalContainsElement_1.portalContainsElement)(portal, portal)).toBeTruthy(); expect((0, portalContainsElement_1.portalContainsElement)(leaf, leaf)).toBeFalsy(); }); }); }); //# sourceMappingURL=dom.test.js.map