import { removeChildrenOfParents } from '../lib/getFieldsOfInterestFromAll';

describe('#removeChildrenOfParents ', function() {
    it('Should filter out children of parents from simple array', function() {
        const array = ['master.field', 'master', 'bomb'];
        const newArray = removeChildrenOfParents(array);
        assert.lengthOf(newArray, 2);
        assert.equal(newArray[0], 'master');
    });

    it('Should filter out children of parents from more complex array', function() {
        const array = ['master.field.subfield', 'master.field', 'bomb'];
        const newArray = removeChildrenOfParents(array);
        assert.lengthOf(newArray, 2);
        assert.isUndefined(newArray.find(el => el === 'master.field.subfield'));
        assert.isDefined(newArray.find(el => el === 'master.field'));
        assert.isDefined(newArray.find(el => el === 'bomb'));
    });

    it('Should work with more deeper nested fields', function() {
        const array = ['master.slave.field', 'master'];
        const newArray = removeChildrenOfParents(array);

        assert.lengthOf(newArray, 1);
        assert.isDefined(newArray.find(el => el === 'master'));
    });

    it('Should work with a very crazy case', function() {
        const array = [
            'master.slave.field',
            'maste',
            'master.slave.field.subfield',
            'slave.field',
            'slave.field.subfield',
        ];
        const newArray = removeChildrenOfParents(array);

        assert.lengthOf(newArray, 3);
        assert.isDefined(newArray.find(el => el === 'maste'));
        assert.isDefined(newArray.find(el => el === 'master.slave.field'));
        assert.isDefined(newArray.find(el => el === 'slave.field'));
    });
});

@@ -1739,13 +1739,457 @@
 %0A    %7D);
+%0A%0A    it('Should work when field has a top level field as a substring', function() %7B%0A        const array = %5B%0A            'master.slave.field',%0A            'slave.field',%0A            'slave',%0A        %5D;%0A        const newArray = removeChildrenOfParents(array);%0A%0A        assert.lengthOf(newArray, 2);%0A        assert.isDefined(newArray.find(el =%3E el === 'master.slave.field'));%0A        assert.isDefined(newArray.find(el =%3E el === 'slave'));%0A    %7D);
 %0A%7D);%0A

add test for child removal when child has top level field as a substring