UNPKG

nexshop-web-contents

Version:

Nexshop Web Contents Project

51 lines (37 loc) 1.73 kB
import React from 'react'; import {expect} from 'chai'; import {isElementInParent} from "../../src/helpers/dom-helper"; describe('Dom Helper Spec', () => { let parentElement = { getBoundingClientRect: () => {} }; const stubBoundingClientRect = (rect) => { let element = { getBoundingClientRect: () => {return Object.assign({top: 60, right: 250, bottom: 120, left: 0, width: 250},rect)} }; return element; }; beforeEach(() => { parentElement = stubBoundingClientRect({top: 60, right: 250, bottom: 773, left: 0, width: 250}); }); it('returns true parentElement contains childElement', () => { let childElement = stubBoundingClientRect({}); expect(isElementInParent(childElement , parentElement)).to.be.true; }); it('returns false left of childElement is not in parentElement', () => { let childElement = stubBoundingClientRect({left: -10}); expect(isElementInParent(childElement , parentElement)).to.be.false; }); it('returns false right of childElement is not in parentElement', () => { let childElement = stubBoundingClientRect({right: 260}); expect(isElementInParent(childElement , parentElement)).to.be.false; }); it('returns false top of childElement is not in parentElement', () => { let childElement = stubBoundingClientRect({top: 50}); expect(isElementInParent(childElement , parentElement)).to.be.false; }); it('returns false bottom of childElement is not in parentElement', () => { let childElement = stubBoundingClientRect({bottom: 800}); expect(isElementInParent(childElement , parentElement)).to.be.false; }); });