< Summary

Class:Tests.UUIDComponentShould
Assembly:UUIDComponentTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UUIDComponent/Tests/UUIDComponentShould.cs
Covered lines:78
Uncovered lines:1
Coverable lines:79
Total lines:206
Line coverage:98.7% (78 of 79)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CreateRuntimeContext()0%110100%
CreatePlatformContext()0%110100%
SetUp()0%330100%
BeDestroyedCorrectlyWhenReceivingComponentDestroyMessage()0%330100%
NotCreateCollidersOnLoadingShape()0%550100%
NotRecreateCollidersWhenShapeDoesntChange()0%550100%
NotLeaveCollidersOnRecycledMeshes()0%6.036090.91%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UUIDComponent/Tests/UUIDComponentShould.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Linq;
 4using DCL;
 5using DCL.Components;
 6using DCL.Configuration;
 7using DCL.Controllers;
 8using DCL.Helpers;
 9using DCL.Models;
 10using Newtonsoft.Json;
 11using NUnit.Framework;
 12using UnityEngine;
 13using UnityEngine.TestTools;
 14using UnityGLTF;
 15using Environment = DCL.Environment;
 16using WaitUntil = UnityEngine.WaitUntil;
 17
 18namespace Tests
 19{
 20    public class UUIDComponentShould : IntegrationTestSuite
 21    {
 22        private ParcelScene scene;
 23
 24        protected override WorldRuntimeContext CreateRuntimeContext()
 25        {
 426            return DCL.Tests.WorldRuntimeContextFactory.CreateWithCustomMocks
 27            (
 28                sceneController: new SceneController(),
 29                state: new WorldState(),
 30                componentFactory: new RuntimeComponentFactory()
 31            );
 32        }
 33
 34        protected override PlatformContext CreatePlatformContext()
 35        {
 436            return DCL.Tests.PlatformContextFactory.CreateWithGenericMocks(
 37                WebRequestController.Create()
 38            );
 39        }
 40
 41        [UnitySetUp]
 42        protected override IEnumerator SetUp()
 43        {
 444            yield return base.SetUp();
 445            scene = Environment.i.world.sceneController.CreateTestScene() as ParcelScene;
 446        }
 47
 48        [UnityTest]
 49        public IEnumerator BeDestroyedCorrectlyWhenReceivingComponentDestroyMessage()
 50        {
 151            var shape = TestHelpers.CreateEntityWithBoxShape(scene, Vector3.zero, true);
 152            IDCLEntity entity = shape.attachedEntities.First();
 53
 154            yield return shape.routine;
 55
 156            string onPointerId = "pointerevent-1";
 157            var model = new OnClick.Model()
 58            {
 59                type = OnClick.NAME,
 60                uuid = onPointerId
 61            };
 62
 163            TestHelpers.EntityComponentCreate<OnClick, OnClick.Model>(scene, entity,
 64                model, CLASS_ID_COMPONENT.UUID_CALLBACK);
 65
 166            model.type = OnPointerDown.NAME;
 67
 168            TestHelpers.EntityComponentCreate<OnPointerDown, OnPointerDown.Model>(scene, entity,
 69                model, CLASS_ID_COMPONENT.UUID_CALLBACK);
 70
 171            model.type = OnPointerUp.NAME;
 72
 173            TestHelpers.EntityComponentCreate<OnPointerUp, OnPointerUp.Model>(scene, entity,
 74                model, CLASS_ID_COMPONENT.UUID_CALLBACK);
 75
 176            Assert.IsTrue( entity.components.ContainsKey( CLASS_ID_COMPONENT.UUID_ON_CLICK ));
 177            Assert.IsTrue( entity.components.ContainsKey( CLASS_ID_COMPONENT.UUID_ON_UP ));
 178            Assert.IsTrue( entity.components.ContainsKey( CLASS_ID_COMPONENT.UUID_ON_DOWN ));
 79
 180            scene.EntityComponentRemove(entity.entityId, OnPointerDown.NAME);
 181            scene.EntityComponentRemove(entity.entityId, OnPointerUp.NAME);
 182            scene.EntityComponentRemove(entity.entityId, OnClick.NAME);
 83
 184            Assert.IsFalse( entity.components.ContainsKey( CLASS_ID_COMPONENT.UUID_ON_CLICK ));
 185            Assert.IsFalse( entity.components.ContainsKey( CLASS_ID_COMPONENT.UUID_ON_UP ));
 186            Assert.IsFalse( entity.components.ContainsKey( CLASS_ID_COMPONENT.UUID_ON_DOWN ));
 187        }
 88
 89        [UnityTest]
 90        public IEnumerator NotCreateCollidersOnLoadingShape()
 91        {
 92            // 1. Instantiate entity and add an OnPointerDown component
 193            string entityId = "1";
 194            var entity = TestHelpers.CreateSceneEntity(scene, entityId);
 95
 196            string onPointerId = "pointerevent-1";
 197            var model = new OnPointerEvent.Model()
 98            {
 99                type = OnPointerDown.NAME,
 100                uuid = onPointerId
 101            };
 1102            var onPointerDownComponent = TestHelpers.EntityComponentCreate<OnPointerDown, OnPointerEvent.Model>(scene, e
 103                model, CLASS_ID_COMPONENT.UUID_CALLBACK);
 104
 105            // 2. Attach a shape
 1106            var shapeModel = new LoadableShape.Model();
 1107            shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 1108            var componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert
 109
 110            // 3. Change a shape component property while it loads
 1111            shapeModel.visible = false;
 1112            TestHelpers.UpdateShape(scene, componentId, JsonConvert.SerializeObject(shapeModel));
 113
 1114            var pointerEventColliders = onPointerDownComponent.pointerEventHandler.eventColliders.colliders;
 1115            Assert.IsTrue(pointerEventColliders == null || pointerEventColliders.Length == 0);
 116
 1117            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]);
 11118            yield return new WaitUntil(() => gltfShape.alreadyLoaded);
 119
 120            // 4. Check if the PointerEvent colliders were created
 1121            pointerEventColliders = onPointerDownComponent.pointerEventHandler.eventColliders.colliders;
 1122            Assert.IsTrue(pointerEventColliders != null && pointerEventColliders.Length > 0);
 1123        }
 124
 125        [UnityTest]
 126        public IEnumerator NotRecreateCollidersWhenShapeDoesntChange()
 127        {
 128            // 1. Instantiate entity and add an OnPointerDown component
 1129            string entityId = "1";
 1130            var entity = TestHelpers.CreateSceneEntity(scene, entityId);
 131
 1132            string onPointerId = "pointerevent-1";
 1133            var model = new OnPointerDown.Model()
 134            {
 135                type = OnPointerDown.NAME,
 136                uuid = onPointerId
 137            };
 1138            var onPointerDownComponent = TestHelpers.EntityComponentCreate<OnPointerDown, OnPointerDown.Model>(scene, en
 139                model, CLASS_ID_COMPONENT.UUID_CALLBACK);
 140
 141            // 2. Attach a shape
 1142            var shapeModel = new LoadableShape<LoadWrapper_GLTF, LoadableShape.Model>.Model();
 1143            shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 1144            var componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert
 145
 1146            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]);
 11147            yield return new WaitUntil(() => gltfShape.alreadyLoaded);
 148
 1149            var pointerEventColliders = onPointerDownComponent.pointerEventHandler.eventColliders.colliders;
 1150            Assert.IsTrue(pointerEventColliders != null || pointerEventColliders.Length > 0);
 151
 152            // 3. Change a shape component property conserving the same glb
 1153            shapeModel.visible = false;
 1154            TestHelpers.UpdateShape(scene, componentId, JsonConvert.SerializeObject(shapeModel));
 1155            yield return null;
 156
 157            // 4. Check the same colliders were kept
 1158            Assert.IsTrue(pointerEventColliders == onPointerDownComponent.pointerEventHandler.eventColliders.colliders);
 1159        }
 160
 161        [UnityTest]
 162        public IEnumerator NotLeaveCollidersOnRecycledMeshes()
 163        {
 164            // 1. Instantiate entity and add an OnPointerDown component
 1165            string entity1Id = "1";
 1166            var entity1 = TestHelpers.CreateSceneEntity(scene, entity1Id);
 167
 1168            string onPointerId = "pointerevent-1";
 1169            var onPointerEventModel = new OnPointerDown.Model()
 170            {
 171                type = OnPointerDown.NAME,
 172                uuid = onPointerId
 173            };
 1174            var onPointerDownComponent = TestHelpers.EntityComponentCreate<OnPointerDown, OnPointerDown.Model>(scene, en
 175                onPointerEventModel, CLASS_ID_COMPONENT.UUID_CALLBACK);
 176
 177            // 2. Attach a shape
 1178            var shapeModel = new LoadableShape<LoadWrapper_GLTF, LoadableShape.Model>.Model();
 1179            shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 1180            var shapeComponentId = TestHelpers.CreateAndSetShape(scene, entity1Id, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonC
 181
 1182            LoadWrapper gltfShapeLoader1 = GLTFShape.GetLoaderForEntity(scene.entities[entity1Id]);
 183
 11184            yield return new WaitUntil(() => gltfShapeLoader1.alreadyLoaded);
 1185            yield return null;
 186
 187            // 3. Save the mesh GO reference
 1188            Transform shapeInstanceRootTransform = entity1.meshRootGameObject.transform.GetChild(0);
 1189            Debug.Log("saved mesh GO: ", shapeInstanceRootTransform);
 190
 191            // 4. Remove shape so that it returns to its pool
 1192            entity1.RemoveSharedComponent(typeof(BaseShape));
 1193            yield return null;
 194
 195            // 5. Check that the pooled mesh doesn't have the collider children and the onPointerEvent component
 196            // doesn't have any instantiated collider (since its entity doesn't have a mesh now)
 1197            var childMeshColliders = shapeInstanceRootTransform.GetComponentsInChildren<MeshCollider>(true);
 2198            foreach (MeshCollider collider in childMeshColliders)
 199            {
 0200                Assert.IsTrue(collider.gameObject.layer != PhysicsLayers.onPointerEventLayer);
 201            }
 202
 1203            Assert.IsNull(onPointerDownComponent.pointerEventHandler.eventColliders.colliders);
 1204        }
 205    }
 206}