< Summary

Class:Tests.MaterialTransitionControllerTests
Assembly:MaterialTransitionControllerTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MaterialTransitionController/Tests/MaterialTransitionControllerTests.cs
Covered lines:23
Uncovered lines:35
Coverable lines:58
Total lines:141
Line coverage:39.6% (23 of 58)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MaterialTransitionWithGLTF()0%1101000%
MaterialTransitionWithParametrizableMeshes()0%10.1510088.46%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MaterialTransitionController/Tests/MaterialTransitionControllerTests.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Configuration;
 3using DCL.Helpers;
 4using DCL.Models;
 5using NUnit.Framework;
 6using System.Collections;
 7using UnityEngine;
 8using UnityEngine.TestTools;
 9
 10namespace Tests
 11{
 12    public class MaterialTransitionControllerTests : IntegrationTestSuite_Legacy
 13    {
 14        [UnityTest]
 15        [Category("Explicit")]
 16        [Explicit("Test is too slow")]
 17        public IEnumerator MaterialTransitionWithGLTF()
 18        {
 019            var entity1 = TestHelpers.CreateSceneEntity(scene);
 20
 021            ParcelSettings.VISUAL_LOADING_ENABLED = true;
 22
 023            var prevLoadingType = RendereableAssetLoadHelper.loadingType;
 024            RendereableAssetLoadHelper.loadingType = RendereableAssetLoadHelper.LoadingType.GLTF_ONLY;
 25
 026            Shader hologramShader = Shader.Find("DCL/FX/Hologram");
 27
 028            Assert.IsTrue(hologramShader != null, "Hologram shader == null??");
 29
 030            IDCLEntity entity = null;
 31
 032            GLTFShape shape = TestHelpers.InstantiateEntityWithShape<GLTFShape, GLTFShape.Model>
 33            (scene,
 34                DCL.Models.CLASS_ID.GLTF_SHAPE,
 35                Vector3.zero,
 36                out entity,
 37                new GLTFShape.Model() { src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb" });
 38
 039            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity);
 040            yield return new WaitUntil(() => gltfShape.alreadyLoaded);
 41
 042            float timeout = 0;
 43
 044            while (timeout < 10)
 45            {
 046                timeout += Time.deltaTime;
 47
 048                if (entity.meshRootGameObject != null)
 49                {
 050                    var c = entity.meshRootGameObject.GetComponentInChildren<MaterialTransitionController>();
 51
 052                    if (c != null && c.placeholder != null) // NOTE(Brian): Wait for it
 53                    {
 054                        Assert.IsTrue(c.useHologram, "useHologram must be true");
 055                        Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null");
 056                        Assert.AreEqual(c.gameObject.transform, c.placeholder.transform.parent,
 57                            "MaterialTransitionController is not parented correctly");
 058                        Assert.IsTrue(c.placeholder.GetComponent<MeshFilter>() != null,
 59                            "MeshFilter missing from placeholder object");
 060                        Assert.IsTrue(c.placeholder.GetComponent<Renderer>() != null,
 61                            "Renderer missing from placeholder object");
 062                        Assert.IsTrue(c.placeholder.GetComponent<Renderer>().sharedMaterial != null,
 63                            "SharedMaterial missing from placeholder's renderer");
 064                        Assert.AreEqual(hologramShader, c.placeholder.GetComponent<Renderer>().sharedMaterial.shader,
 65                            "Placeholder is not hologram");
 66
 067                        yield return new WaitForSeconds(2f);
 68
 069                        Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!");
 70
 071                        break;
 72                    }
 073                }
 74
 075                yield return null;
 76            }
 77
 078            Assert.Less(timeout, 10.1f, "Timeout! MaterialTransitionController never appeared?");
 79
 080            RendereableAssetLoadHelper.loadingType = prevLoadingType;
 81
 082            yield return null;
 083        }
 84
 85        [UnityTest]
 86        public IEnumerator MaterialTransitionWithParametrizableMeshes()
 87        {
 188            DCL.Configuration.EnvironmentSettings.DEBUG = true;
 89
 190            var entity1 = TestHelpers.CreateSceneEntity(scene);
 91
 192            ParcelSettings.VISUAL_LOADING_ENABLED = true;
 93
 194            IDCLEntity entity = null;
 195            ConeShape shape = TestHelpers.InstantiateEntityWithShape<ConeShape, ConeShape.Model>
 96            (
 97                scene,
 98                DCL.Models.CLASS_ID.CONE_SHAPE,
 99                new Vector3(2, 1, 3),
 100                out entity,
 101                new ConeShape.Model());
 102
 1103            yield return null;
 104
 1105            float timeout = 0f;
 1106            float maxTime = 20f;
 1107            while (timeout < maxTime)
 108            {
 1109                timeout += Time.deltaTime;
 110
 1111                if (timeout > maxTime)
 0112                    timeout = maxTime;
 113
 1114                if (entity.meshRootGameObject != null)
 115                {
 1116                    var c = entity.meshRootGameObject.GetComponentInChildren<MaterialTransitionController>();
 117
 1118                    if (c != null) // NOTE(Brian): Wait for it
 119                    {
 1120                        Assert.IsTrue(!c.useHologram, "useHologram must be false");
 1121                        Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null");
 1122                        Assert.IsTrue(c.placeholder == null,
 123                            "placeholder must be null because we're not using holograms with parametric shapes.");
 124
 1125                        yield return new WaitForSeconds(0.5f);
 126
 1127                        Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!");
 128
 1129                        break;
 130                    }
 0131                }
 132
 0133                yield return null;
 134            }
 135
 1136            Assert.Less(timeout, maxTime + 0.1f, "Timeout! MaterialTransitionController never appeared?");
 137
 1138            yield return null;
 1139        }
 140    }
 141}