All files / nexshop-web-contents/spec/helpers dom-helper-spec.js

100% Statements 26/26
100% Branches 0/0
90% Functions 9/10
100% Lines 26/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x 1x 1x   1x 1x       1x 10x 10x     10x     1x 5x     1x 1x   1x     1x 1x   1x     1x 1x   1x     1x 1x   1x     1x 1x   1x    
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;
    });
});