< Summary

Class:Tests.FontTests
Assembly:FontTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Font/Tests/FontTests.cs
Covered lines:37
Uncovered lines:0
Coverable lines:37
Total lines:104
Line coverage:100% (37 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CreateRuntimeContext()0%110100%
SetUp()0%330100%
BuiltInFontCreateAndLoadTest()0%440100%
BuiltInFontHandleErrorProperly()0%550100%
BuiltInFontAttachCorrectlyOnTextComponentUpdate()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Font/Tests/FontTests.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Helpers;
 4using DCL.Models;
 5using NUnit.Framework;
 6using System.Collections;
 7using DCL.Controllers;
 8using UnityEngine;
 9using UnityEngine.TestTools;
 10using TMPro;
 11
 12namespace Tests
 13{
 14    public class FontTests : IntegrationTestSuite
 15    {
 16        const string TEST_BUILTIN_FONT_NAME = "builtin:SF-UI-Text-Regular SDF";
 17
 18        private ParcelScene scene;
 19
 20        protected override WorldRuntimeContext CreateRuntimeContext()
 21        {
 322            return DCL.Tests.WorldRuntimeContextFactory.CreateWithCustomMocks
 23            (
 24                sceneController: new SceneController(),
 25                state: new WorldState(),
 26                componentFactory: new RuntimeComponentFactory()
 27            );
 28        }
 29
 30        [UnitySetUp]
 31        protected override IEnumerator SetUp()
 32        {
 333            yield return base.SetUp();
 334            scene = Environment.i.world.sceneController.CreateTestScene() as ParcelScene;
 335        }
 36
 37        [UnityTest]
 38        public IEnumerator BuiltInFontCreateAndLoadTest()
 39        {
 140            DCLFont font =
 41                TestHelpers.SharedComponentCreate<DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { sr
 142            yield return font.routine;
 43
 144            var entity = TestHelpers.CreateSceneEntity(scene);
 45
 146            TextShape textShape =
 47                TestHelpers.EntityComponentCreate<TextShape, TextShape.Model>(scene, entity, new TextShape.Model() { fon
 148            yield return textShape.routine;
 49
 150            Assert.IsTrue(font.loaded, "Built-in font didn't load");
 151            Assert.IsFalse(font.error, "Built-in font has error");
 52
 153            TextMeshPro tmpro = textShape.GetComponentInChildren<TextMeshPro>();
 154            Assert.IsTrue(font.fontAsset == tmpro.font, "Built-in font didn't apply correctly");
 155        }
 56
 57        [UnityTest]
 58        public IEnumerator BuiltInFontHandleErrorProperly()
 59        {
 160            var entity = TestHelpers.CreateSceneEntity(scene);
 61
 162            TextShape textShape =
 63                TestHelpers.EntityComponentCreate<TextShape, TextShape.Model>(scene, entity, new TextShape.Model());
 164            yield return textShape.routine;
 65
 166            TMP_FontAsset defaultFont = textShape.GetComponentInChildren<TextMeshPro>().font;
 67
 168            DCLFont font =
 69                TestHelpers.SharedComponentCreate<DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { sr
 170            yield return font.routine;
 71
 172            scene.EntityComponentUpdate(entity, CLASS_ID_COMPONENT.TEXT_SHAPE,
 73                JsonUtility.ToJson(new TextShape.Model { font = font.id }));
 174            yield return textShape.routine;
 75
 176            Assert.IsTrue(font.error, "Built-in font error has not araise properly");
 177            Assert.IsTrue(textShape.GetComponentInChildren<TextMeshPro>().font == defaultFont, "Built-in font didn't app
 178        }
 79
 80        [UnityTest]
 81        public IEnumerator BuiltInFontAttachCorrectlyOnTextComponentUpdate()
 82        {
 183            var entity = TestHelpers.CreateSceneEntity(scene);
 84
 185            TextShape textShape =
 86                TestHelpers.EntityComponentCreate<TextShape, TextShape.Model>(scene, entity, new TextShape.Model());
 187            yield return textShape.routine;
 88
 189            DCLFont font =
 90                TestHelpers.SharedComponentCreate<DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { sr
 191            yield return font.routine;
 92
 193            scene.EntityComponentUpdate(entity, CLASS_ID_COMPONENT.TEXT_SHAPE,
 94                JsonUtility.ToJson(new TextShape.Model { font = font.id }));
 195            yield return textShape.routine;
 96
 197            Assert.IsTrue(font.loaded, "Built-in font didn't load");
 198            Assert.IsFalse(font.error, "Built-in font has error");
 99
 1100            TextMeshPro tmpro = textShape.GetComponentInChildren<TextMeshPro>();
 1101            Assert.IsTrue(font.fontAsset == tmpro.font, "Built-in font didn't apply correctly");
 1102        }
 103    }
 104}