{"size": 4429, "ext": "js", "max_stars_repo_path": "test/unit/potreelayerprocessing.js", "max_stars_repo_name": "epaizreyes/itowns", "max_stars_repo_stars_event_min_datetime": "2016-01-27T14:39:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T16:11:22.000Z", "max_issues_repo_path": "test/unit/potreelayerprocessing.js", "max_issues_repo_name": "epaizreyes/itowns", "max_issues_repo_issues_event_min_datetime": "2016-01-27T14:11:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:58:42.000Z", "max_forks_repo_path": "test/unit/potreelayerprocessing.js", "max_forks_repo_name": "epaizreyes/itowns", "max_forks_repo_forks_event_min_datetime": "2016-01-27T12:17:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:11:22.000Z"}
{"max_stars_count": 713, "max_issues_count": 848, "max_forks_count": 212, "avg_line_length": 52.1058823529, "max_line_length": 96, "alphanum_fraction": 0.6446150373}
import assert from 'assert';
import PotreeLayer from 'Layer/PotreeLayer';
import PotreeNode from 'Core/PotreeNode';

describe('preUpdate PotreeLayer', function () {
    const context = { camera: { height: 1, camera3D: { fov: 1 } } };
    const layer = {
        id: 'a',
        source: { baseurl: 'server.geo' },
        hierarchyStepSize: 1,
    };
    layer.root = new PotreeNode(4000, 0, layer);
    layer.root.bbox.setFromArray([1000, 1000, 1000, 0, 0, 0]);

    layer.root.add(new PotreeNode(3000, 0, layer), 1, layer.root);
    layer.root.children[0].obj = { layer, isPoints: true };
    layer.root.add(new PotreeNode(3000, 0, layer), 2, layer.root);
    layer.root.children[1].obj = { layer, isPoints: true };
    layer.root.add(new PotreeNode(3000, 0, layer), 3, layer.root);
    layer.root.children[2].obj = { layer, isPoints: true };

    layer.root.children[0].add(new PotreeNode(2000, 0, layer), 1, layer.root);
    layer.root.children[0].children[0].obj = { layer, isPoints: true };
    layer.root.children[0].add(new PotreeNode(2000, 0, layer), 2, layer.root);
    layer.root.children[0].children[1].obj = { layer, isPoints: true };
    layer.root.children[1].add(new PotreeNode(2000, 0, layer), 1, layer.root);
    layer.root.children[1].children[0].obj = { layer, isPoints: true };
    layer.root.children[2].add(new PotreeNode(2000, 0, layer), 2, layer.root);
    layer.root.children[2].children[0].obj = { layer, isPoints: true };
    layer.root.children[2].add(new PotreeNode(2000, 0, layer), 3, layer.root);
    layer.root.children[2].children[1].obj = { layer, isPoints: true };

    layer.root.children[0].children[0].add(new PotreeNode(1000, 0, layer), 1, layer.root);
    layer.root.children[0].children[0].children[0].obj = { layer, isPoints: true };
    layer.root.children[0].children[0].add(new PotreeNode(1000, 0, layer), 5, layer.root);
    layer.root.children[0].children[0].children[1].obj = { layer, isPoints: true };
    layer.root.children[0].children[1].add(new PotreeNode(1000, 0, layer), 4, layer.root);
    layer.root.children[0].children[1].children[0].obj = { layer, isPoints: true };
    layer.root.children[2].children[1].add(new PotreeNode(1000, 0, layer), 1, layer.root);
    layer.root.children[2].children[1].children[0].obj = { layer, isPoints: true };
    layer.root.children[2].children[1].add(new PotreeNode(1000, 0, layer), 2, layer.root);
    layer.root.children[2].children[1].children[1].obj = { layer, isPoints: true };
    layer.root.children[2].children[1].add(new PotreeNode(1000, 0, layer), 3, layer.root);
    layer.root.children[2].children[1].children[2].obj = { layer, isPoints: true };
    layer.root.children[2].children[1].add(new PotreeNode(1000, 0, layer), 4, layer.root);
    layer.root.children[2].children[1].children[3].obj = { layer, isPoints: true };

    it('should return root if no change source', () => {
        const sources = new Set();
        assert.deepStrictEqual(
            layer.root,
            PotreeLayer.prototype.preUpdate.call(layer, context, sources)[0]);
    });

    it('should return root if no common ancestors', () => {
        const sources = new Set();
        sources.add(layer.root.children[0].children[0]);
        sources.add(layer.root.children[2].children[1]);
        assert.deepStrictEqual(
            layer.root,
            PotreeLayer.prototype.preUpdate.call(layer, context, sources)[0]);
    });

    it('should return common ancestor', () => {
        const sources = new Set();
        sources.add(layer.root.children[2].children[0]);
        sources.add(layer.root.children[2].children[1]);
        sources.add(layer.root.children[2].children[1].children[2]);
        sources.add(layer.root.children[2].children[1].children[3]);
        assert.deepStrictEqual(
            layer.root.children[2],
            PotreeLayer.prototype.preUpdate.call(layer, context, sources)[0]);
    });

    it('should not search ancestors if layer are different root if no common ancestors', () => {
        const sources = new Set();
        sources.add(layer.root.children[2].children[0]);
        sources.add(layer.root.children[2].children[1].children[3]);
        layer.root.children[2].children[1].children[3].obj = { layer: {}, isPoints: true };
        assert.deepStrictEqual(
            layer.root.children[2].children[0],
            PotreeLayer.prototype.preUpdate.call(layer, context, sources)[0]);
    });
});
