Skip to content

Commit 2d42fdc

Browse files
remaOko-Tester
authored andcommitted
test: extend EntityClusterSpec to cover declusteredEvent
1 parent ce32d42 commit 2d42fdc

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

packages/engine/Specs/DataSources/EntityClusterSpec.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,187 @@ describe(
692692
expect(cluster._billboardCollection).toBeDefined();
693693
expect(cluster._billboardCollection.length).toEqual(2);
694694
});
695+
696+
it("has declusteredEvent property", function () {
697+
cluster = new EntityCluster();
698+
expect(cluster.declusteredEvent).toBeDefined();
699+
expect(typeof cluster.declusteredEvent.addEventListener).toEqual(
700+
"function",
701+
);
702+
});
703+
704+
it("provides access to clustering data via new API methods", function () {
705+
cluster = new EntityCluster();
706+
cluster._initialize(scene);
707+
708+
expect(typeof cluster.getLastClusteredEntities).toEqual("function");
709+
expect(typeof cluster.getLastDeclusteredEntities).toEqual("function");
710+
expect(typeof cluster.getAllProcessedEntities).toEqual("function");
711+
712+
expect(cluster.getLastClusteredEntities()).toEqual([]);
713+
expect(cluster.getLastDeclusteredEntities()).toEqual([]);
714+
expect(cluster.getAllProcessedEntities()).toEqual([]);
715+
});
716+
717+
it("fires declusteredEvent with both clustered and declustered entities", function () {
718+
cluster = new EntityCluster();
719+
cluster._initialize(scene);
720+
721+
let receivedData = null;
722+
cluster.declusteredEvent.addEventListener(function (data) {
723+
receivedData = data;
724+
});
725+
726+
const entity1 = new Entity();
727+
const point1 = cluster.getPoint(entity1);
728+
point1.id = entity1;
729+
point1.pixelSize = 1;
730+
point1.position = SceneTransforms.drawingBufferToWorldCoordinates(
731+
scene,
732+
new Cartesian2(0.0, 0.0),
733+
depth,
734+
);
735+
736+
const entity2 = new Entity();
737+
const point2 = cluster.getPoint(entity2);
738+
point2.id = entity2;
739+
point2.pixelSize = 1;
740+
point2.position = SceneTransforms.drawingBufferToWorldCoordinates(
741+
scene,
742+
new Cartesian2(1.0, 1.0),
743+
depth,
744+
);
745+
746+
const entity3 = new Entity();
747+
const point3 = cluster.getPoint(entity3);
748+
point3.id = entity3;
749+
point3.pixelSize = 1;
750+
point3.position = SceneTransforms.drawingBufferToWorldCoordinates(
751+
scene,
752+
new Cartesian2(scene.canvas.clientWidth, scene.canvas.clientHeight),
753+
farDepth,
754+
);
755+
756+
cluster.enabled = true;
757+
return updateUntilDone(cluster).then(function () {
758+
expect(receivedData).toBeDefined();
759+
expect(receivedData.clustered).toBeDefined();
760+
expect(receivedData.declustered).toBeDefined();
761+
expect(Array.isArray(receivedData.clustered)).toEqual(true);
762+
expect(Array.isArray(receivedData.declustered)).toEqual(true);
763+
});
764+
});
765+
766+
it("maintains backward compatibility - original clusterEvent still works", function () {
767+
cluster = new EntityCluster();
768+
cluster._initialize(scene);
769+
770+
let originalEventFired = false;
771+
let newEventFired = false;
772+
773+
cluster.clusterEvent.addEventListener(function (entities, clusterObj) {
774+
originalEventFired = true;
775+
expect(Array.isArray(entities)).toEqual(true);
776+
expect(clusterObj).toBeDefined();
777+
});
778+
779+
cluster.declusteredEvent.addEventListener(function (data) {
780+
newEventFired = true;
781+
expect(data.clustered).toBeDefined();
782+
expect(data.declustered).toBeDefined();
783+
});
784+
785+
const entity1 = new Entity();
786+
const point1 = cluster.getPoint(entity1);
787+
point1.id = entity1;
788+
point1.pixelSize = 1;
789+
point1.position = SceneTransforms.drawingBufferToWorldCoordinates(
790+
scene,
791+
new Cartesian2(0.0, 0.0),
792+
depth,
793+
);
794+
795+
const entity2 = new Entity();
796+
const point2 = cluster.getPoint(entity2);
797+
point2.id = entity2;
798+
point2.pixelSize = 1;
799+
point2.position = SceneTransforms.drawingBufferToWorldCoordinates(
800+
scene,
801+
new Cartesian2(1.0, 1.0),
802+
depth,
803+
);
804+
805+
cluster.enabled = true;
806+
return updateUntilDone(cluster).then(function () {
807+
expect(originalEventFired).toEqual(true);
808+
expect(newEventFired).toEqual(true);
809+
});
810+
});
811+
812+
it("tracks processed entities correctly", function () {
813+
cluster = new EntityCluster();
814+
cluster._initialize(scene);
815+
816+
const entity1 = new Entity();
817+
const point1 = cluster.getPoint(entity1);
818+
point1.id = entity1;
819+
point1.pixelSize = 1;
820+
point1.position = SceneTransforms.drawingBufferToWorldCoordinates(
821+
scene,
822+
new Cartesian2(0.0, 0.0),
823+
depth,
824+
);
825+
826+
const entity2 = new Entity();
827+
const point2 = cluster.getPoint(entity2);
828+
point2.id = entity2;
829+
point2.pixelSize = 1;
830+
point2.position = SceneTransforms.drawingBufferToWorldCoordinates(
831+
scene,
832+
new Cartesian2(scene.canvas.clientWidth, scene.canvas.clientHeight),
833+
farDepth,
834+
);
835+
836+
cluster.enabled = true;
837+
return updateUntilDone(cluster).then(function () {
838+
const clusteredEntities = cluster.getLastClusteredEntities();
839+
const declusteredEntities = cluster.getLastDeclusteredEntities();
840+
const allProcessed = cluster.getAllProcessedEntities();
841+
842+
expect(allProcessed.length).toBeGreaterThan(0);
843+
expect(
844+
clusteredEntities.length + declusteredEntities.length,
845+
).toBeLessThanOrEqual(allProcessed.length);
846+
});
847+
});
848+
849+
it("cleans up tracking arrays on destroy", function () {
850+
cluster = new EntityCluster();
851+
cluster._initialize(scene);
852+
853+
const entity = new Entity();
854+
const point = cluster.getPoint(entity);
855+
point.id = entity;
856+
point.pixelSize = 1;
857+
point.position = SceneTransforms.drawingBufferToWorldCoordinates(
858+
scene,
859+
new Cartesian2(0.0, 0.0),
860+
depth,
861+
);
862+
863+
cluster.enabled = true;
864+
return updateUntilDone(cluster).then(function () {
865+
expect(cluster._allProcessedEntities).toBeDefined();
866+
expect(cluster._lastClusteredEntities).toBeDefined();
867+
expect(cluster._lastDeclusteredEntities).toBeDefined();
868+
869+
cluster.destroy();
870+
871+
expect(cluster._allProcessedEntities).toEqual([]);
872+
expect(cluster._lastClusteredEntities).toEqual([]);
873+
expect(cluster._lastDeclusteredEntities).toEqual([]);
874+
});
875+
});
695876
},
696877
"WebGL",
697878
);

0 commit comments

Comments
 (0)