< Summary

Class:LoadableShapesMiscTests
Assembly:LoadableShapesTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/Tests/LoadableShapesMiscTests.cs
Covered lines:45
Uncovered lines:0
Coverable lines:45
Total lines:111
Line coverage:100% (45 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OBJShapeUpdate()0%440100%
PreExistentShapeUpdate()0%770100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/Tests/LoadableShapesMiscTests.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Helpers;
 3using DCL.Models;
 4using Newtonsoft.Json;
 5using NUnit.Framework;
 6using System.Collections;
 7using UnityEngine;
 8using UnityEngine.TestTools;
 9
 10public class LoadableShapesMiscTests : IntegrationTestSuite_Legacy
 11{
 12    [UnityTest]
 13    public IEnumerator OBJShapeUpdate()
 14    {
 115        string entityId = "1";
 116        TestHelpers.CreateSceneEntity(scene, entityId);
 17
 118        Material placeholderLoadingMaterial = Resources.Load<Material>("Materials/AssetLoading");
 19
 120        yield return null;
 21
 122        Assert.IsTrue(scene.entities[entityId].meshRootGameObject == null,
 23            "Since the shape hasn't been updated yet, the child mesh shouldn't exist");
 24
 125        TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.OBJ_SHAPE, JsonConvert.SerializeObject(
 26            new
 27            {
 28                src = TestAssetsUtils.GetPath() + "/OBJ/teapot.obj"
 29            }));
 30
 131        LoadWrapper objShape = LoadableShape.GetLoaderForEntity(scene.entities[entityId]);
 332        yield return new WaitUntil(() => objShape.alreadyLoaded);
 33
 134        Assert.IsTrue(scene.entities[entityId].meshRootGameObject != null,
 35            "Every entity with a shape should have the mandatory 'Mesh' object as a child");
 36
 137        var childRenderer = scene.entities[entityId].meshRootGameObject.GetComponentInChildren<MeshRenderer>();
 138        Assert.IsTrue(childRenderer != null,
 39            "Since the shape has already been updated, the child renderer should exist");
 140        Assert.AreNotSame(placeholderLoadingMaterial, childRenderer.sharedMaterial,
 41            "Since the shape has already been updated, the child renderer found shouldn't have the 'AssetLoading' placeh
 142    }
 43
 44    [UnityTest]
 45    public IEnumerator PreExistentShapeUpdate()
 46    {
 147        string entityId = "1";
 148        TestHelpers.CreateSceneEntity(scene, entityId);
 149        var entity = scene.entities[entityId];
 50
 151        Assert.IsTrue(entity.meshRootGameObject == null, "meshGameObject should be null");
 52
 53        // Set its shape as a BOX
 154        var componentId = TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}");
 155        yield return ((scene.GetSharedComponent(componentId)) as IDelayedComponent).routine;
 56
 157        var meshName = entity.meshRootGameObject.GetComponent<MeshFilter>().mesh.name;
 158        Assert.AreEqual("DCL Box Instance", meshName);
 59
 60        // Update its shape to a cylinder
 161        TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.CYLINDER_SHAPE, "{}");
 162        yield return (scene.GetSharedComponent(componentId) as IDelayedComponent).routine;
 63
 164        Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject should not be null");
 65
 166        meshName = entity.meshRootGameObject.GetComponent<MeshFilter>().mesh.name;
 167        Assert.AreEqual("DCL Cylinder Instance", meshName);
 168        Assert.IsTrue(entity.meshRootGameObject.GetComponent<MeshFilter>() != null,
 69            "After updating the entity shape to a basic shape, the mesh filter shouldn't be removed from the object");
 70
 171        Assert.IsTrue(entity.meshesInfo.currentShape != null, "current shape must exist 1");
 172        Assert.IsTrue(entity.meshesInfo.currentShape is CylinderShape, "current shape is BoxShape");
 73
 74        // Update its shape to a GLTF
 175        TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(
 76            new
 77            {
 78                src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb"
 79            }));
 80
 181        LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]);
 1382        yield return new WaitUntil(() => gltfShape.alreadyLoaded);
 83
 184        Assert.IsTrue(entity.meshesInfo.currentShape != null, "current shape must exist 2");
 185        Assert.IsTrue(entity.meshesInfo.currentShape is GLTFShape, "current shape is GLTFShape");
 86
 187        Assert.IsTrue(entity.meshRootGameObject != null);
 88
 189        Assert.IsTrue(entity.meshRootGameObject.GetComponent<MeshFilter>() == null,
 90            "After updating the entity shape to a GLTF shape, the mesh filter should be removed from the object");
 191        Assert.IsTrue(
 92            scene.entities[entityId].gameObject.GetComponentInChildren<UnityGLTF.InstantiatedGLTFObject>() != null,
 93            "'GLTFScene' child object with 'InstantiatedGLTF' component should exist if the GLTF was loaded correctly");
 94
 95        // Update its shape to a sphere
 196        TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.SPHERE_SHAPE, "{}");
 197        yield return (scene.GetSharedComponent(componentId) as IDelayedComponent).routine;
 98
 199        yield return null;
 100
 1101        Assert.IsTrue(entity.meshRootGameObject != null);
 102
 1103        meshName = entity.meshRootGameObject.GetComponent<MeshFilter>().mesh.name;
 104
 1105        Assert.AreEqual("DCL Sphere Instance", meshName);
 106
 1107        Assert.IsTrue(
 108            scene.entities[entityId].gameObject.GetComponentInChildren<UnityGLTF.InstantiatedGLTFObject>() == null,
 109            "'GLTFScene' child object with 'InstantiatedGLTF' component shouldn't exist after the shape is updated to a 
 1110    }
 111}