{"size": 2235, "ext": "js", "max_stars_repo_path": "tests/unit/vcm/layer/cesium/pointCloudCesium.spec.js", "max_stars_repo_name": "ikabaev/map-core", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/unit/vcm/layer/cesium/pointCloudCesium.spec.js", "max_issues_repo_name": "ikabaev/map-core", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/unit/vcm/layer/cesium/pointCloudCesium.spec.js", "max_forks_repo_name": "ikabaev/map-core", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.4078947368, "max_line_length": 86, "alphanum_fraction": 0.6098434004}
import { Cesium3DTileStyle } from '@vcmap/cesium';
import PointCloud from '../../../../../src/vcs/vcm/layer/pointCloud.js';
import { createTilesetServer, setCesiumMap } from '../../../helpers/cesiumHelpers.js';
import VcsApp from '../../../../../src/vcs/vcm/vcsApp.js';

describe('vcs.vcm.layer.cesium.PointCloudCesium', () => {
  let sandbox;
  /** @type {import("@vcmap/core").PointCloudCesium} */
  let PCL;
  let app;
  let pointCloud;
  let map;

  before(async () => {
    sandbox = sinon.createSandbox();
    app = new VcsApp();
    map = await setCesiumMap(app);
    pointCloud = new PointCloud({ url: 'http://test.com/tileset.json' });
    app.layers.add(pointCloud);
  });

  beforeEach(() => {
    createTilesetServer(sandbox);
    [PCL] = pointCloud.getImplementationsForMap(map);
  });

  afterEach(() => {
    sandbox.restore();
  });

  after(() => {
    app.destroy();
  });

  describe('initialize', () => {
    it('should set the current point size', async () => {
      PCL.pointSize = 3;
      await PCL.initialize();
      expect(PCL.cesium3DTileset)
        .to.have.property('style')
        .and.to.have.property('pointSize')
        .and.to.have.property('expression', '3');
    });
  });

  describe('updatePointSize', () => {
    beforeEach(async () => {
      await PCL.initialize();
    });

    it('should assign a current cesium3DTileset style the _pointSize', () => {
      const style = new Cesium3DTileStyle({ show: true });
      PCL.cesium3DTileset.style = style;
      PCL.updatePointSize(3);
      expect(style).to.have.property('pointSize')
        .and.to.have.property('expression', '3');
    });

    it('should set style dirty, if assigning a new pointSize', () => {
      PCL.cesium3DTileset.style = new Cesium3DTileStyle({ show: true });
      const makeStyleDirty = sandbox.spy(PCL.cesium3DTileset, 'makeStyleDirty');
      PCL.updatePointSize(3);
      expect(makeStyleDirty).to.have.been.called;
    });

    it('should create a style, if none is present on the tileset', () => {
      PCL.updatePointSize(3);

      expect(PCL.cesium3DTileset)
        .to.have.property('style')
        .to.have.property('pointSize')
        .and.to.have.property('expression', '3');
    });
  });
});
