< Summary

Class:Tests.UITextTests
Assembly:UITextTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIText/Tests/UITextTests.cs
Covered lines:60
Uncovered lines:0
Coverable lines:60
Total lines:181
Line coverage:100% (60 of 60)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TestPropertiesAreAppliedCorrectly()0%660100%
TestOnClickEvent()0%660100%
AddedCorrectlyOnInvisibleParent()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIText/Tests/UITextTests.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Helpers;
 3using DCL.Models;
 4using NUnit.Framework;
 5using System.Collections;
 6using Newtonsoft.Json;
 7using UnityEngine;
 8using UnityEngine.TestTools;
 9
 10namespace Tests
 11{
 12    public class UITextTests : UITestsBase
 13    {
 14        [UnityTest]
 15        public IEnumerator TestPropertiesAreAppliedCorrectly()
 16        {
 17            // Create UIScreenSpaceShape
 118            UIScreenSpace screenSpaceShape =
 19                TestHelpers.SharedComponentCreate<UIScreenSpace, UIScreenSpace.Model>(scene,
 20                    CLASS_ID.UI_SCREEN_SPACE_SHAPE);
 21
 122            yield return screenSpaceShape.routine;
 23
 24            // Create UITextShape
 125            UIText uiTextShape = TestHelpers.SharedComponentCreate<UIText, UIText.Model>(scene, CLASS_ID.UI_TEXT_SHAPE,
 26                new UIText.Model { });
 27
 128            yield return uiTextShape.routine;
 29
 30            // Check default properties are applied correctly
 131            Assert.IsTrue(uiTextShape.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
 132            Assert.IsTrue(uiTextShape.referencesContainer.canvasGroup.blocksRaycasts);
 133            Assert.AreEqual(100f, uiTextShape.childHookRectTransform.rect.width);
 134            Assert.AreEqual(50f, uiTextShape.childHookRectTransform.rect.height);
 135            Assert.IsTrue(uiTextShape.referencesContainer.text.enabled);
 136            Assert.AreEqual(Color.white, uiTextShape.referencesContainer.text.color);
 137            Assert.AreEqual(100f, uiTextShape.referencesContainer.text.fontSize);
 138            Assert.AreEqual("", uiTextShape.referencesContainer.text.text);
 139            Assert.AreEqual(int.MaxValue, uiTextShape.referencesContainer.text.maxVisibleLines);
 140            Assert.AreEqual(0, uiTextShape.referencesContainer.text.lineSpacing);
 141            Assert.IsFalse(uiTextShape.referencesContainer.text.enableAutoSizing);
 142            Assert.IsFalse(uiTextShape.referencesContainer.text.enableWordWrapping);
 143            Assert.IsFalse(uiTextShape.referencesContainer.text.fontMaterial.IsKeywordEnabled("UNDERLAY_ON"));
 44
 145            Vector2 alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
 46                uiTextShape.childHookRectTransform.rect);
 147            Assert.AreEqual(alignedPosition.ToString(), uiTextShape.childHookRectTransform.anchoredPosition.ToString());
 48
 149            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.x);
 150            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.y);
 151            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.z);
 152            Assert.AreEqual(0, uiTextShape.referencesContainer.text.margin.w);
 53
 54            // Update UITextShape
 155            yield return TestHelpers.SharedComponentUpdate<UIText>(uiTextShape,
 56                new UIText.Model
 57                {
 58                    isPointerBlocker = true,
 59                    hAlign = "left",
 60                    vAlign = "bottom",
 61                    textModel = new TextShape.Model
 62                    {
 63                        value = "hello world",
 64                        color = Color.green,
 65                        opacity = 0.5f,
 66                        fontSize = 35f,
 67                        paddingTop = 10f,
 68                        paddingRight = 30f,
 69                        paddingBottom = 20f,
 70                        paddingLeft = 15,
 71                        lineSpacing = 0.1f,
 72                        lineCount = 3,
 73                        shadowOffsetX = 0.1f,
 74                        shadowOffsetY = 0.1f,
 75                        shadowColor = Color.yellow,
 76                        textWrapping = true
 77                    }
 78                });
 79
 80            // Check default properties are applied correctly
 181            Assert.IsTrue(uiTextShape.referencesContainer.transform.parent == screenSpaceShape.childHookRectTransform);
 182            Assert.IsTrue(uiTextShape.referencesContainer.text.raycastTarget);
 183            Assert.AreEqual(100f, uiTextShape.childHookRectTransform.rect.width);
 184            Assert.AreEqual(50f, uiTextShape.childHookRectTransform.rect.height);
 185            Assert.AreEqual("hello world", uiTextShape.referencesContainer.text.text);
 186            Assert.IsTrue(uiTextShape.referencesContainer.text.enabled);
 187            Assert.AreEqual(new Color(0f, 1f, 0f, 0.5f), uiTextShape.referencesContainer.text.color);
 188            Assert.AreEqual(35f, uiTextShape.referencesContainer.text.fontSize);
 189            Assert.AreEqual(3, uiTextShape.referencesContainer.text.maxVisibleLines);
 190            Assert.AreEqual(0.1f, uiTextShape.referencesContainer.text.lineSpacing);
 191            Assert.IsTrue(uiTextShape.referencesContainer.text.enableWordWrapping);
 192            Assert.IsTrue(uiTextShape.referencesContainer.text.fontMaterial.IsKeywordEnabled("UNDERLAY_ON"));
 193            Assert.AreEqual(Color.yellow, uiTextShape.referencesContainer.text.fontMaterial.GetColor("_UnderlayColor"));
 94
 195            alignedPosition = CalculateAlignedAnchoredPosition(screenSpaceShape.childHookRectTransform.rect,
 96                uiTextShape.childHookRectTransform.rect, "bottom", "left");
 197            Assert.AreEqual(alignedPosition.ToString(), uiTextShape.childHookRectTransform.anchoredPosition.ToString());
 98
 199            Assert.AreEqual(15f, uiTextShape.referencesContainer.text.margin.x);
 1100            Assert.AreEqual(10f, uiTextShape.referencesContainer.text.margin.y);
 1101            Assert.AreEqual(30f, uiTextShape.referencesContainer.text.margin.z);
 1102            Assert.AreEqual(20f, uiTextShape.referencesContainer.text.margin.w);
 103
 1104            yield return TestHelpers.SharedComponentUpdate<UIText>(uiTextShape,
 105                new UIText.Model
 106                {
 107
 108                    positionX = new UIValue(80),
 109                    positionY = new UIValue(80),
 110                });
 111
 1112            Assert.AreEqual(80f, uiTextShape.model.positionX.value);
 1113            Assert.AreEqual(80f, uiTextShape.model.positionY.value);
 1114        }
 115
 116        [UnityTest]
 117        public IEnumerator TestOnClickEvent()
 118        {
 1119            UIScreenSpace screenSpaceShape =
 120                TestHelpers.SharedComponentCreate<UIScreenSpace, UIScreenSpace.Model>(scene,
 121                    CLASS_ID.UI_SCREEN_SPACE_SHAPE);
 122
 1123            yield return screenSpaceShape.routine;
 124
 1125            Assert.IsFalse(screenSpaceShape == null);
 126
 127            // Create UITextShape
 1128            UIText uiTextShape = TestHelpers.SharedComponentCreate<UIText, UIText.Model>(scene, CLASS_ID.UI_TEXT_SHAPE,
 129                new UIText.Model { });
 130
 1131            yield return uiTextShape.routine;
 132
 133            // Update UITextShape
 1134            yield return TestHelpers.SharedComponentUpdate(
 135                uiTextShape,
 136                new UIText.Model
 137                {
 138                    isPointerBlocker = true,
 139                    hAlign = "left",
 140                    vAlign = "bottom",
 141                    onClick = "UUIDFakeEventId",
 142                    textModel = new TextShape.Model
 143                    {
 144                        value = "hello world",
 145                        color = Color.green,
 146                        opacity = 0.5f,
 147                        fontSize = 35f,
 148                        paddingTop = 10f,
 149                        paddingRight = 30f,
 150                        paddingBottom = 20f,
 151                        paddingLeft = 15,
 152                        lineSpacing = 0.1f,
 153                        lineCount = 3,
 154                        shadowOffsetX = 0.1f,
 155                        shadowOffsetY = 0.1f,
 156                        shadowColor = Color.yellow,
 157                        textWrapping = true,
 158                    }
 159                });
 160
 161            //------------------------------------------------------------------------
 162            // Test click events
 1163            bool eventResult = false;
 164
 1165            yield return TestHelpers.TestUIClickEventPropagation(
 166                scene.sceneData.id,
 167                uiTextShape.model,
 168                uiTextShape.referencesContainer.childHookRectTransform,
 169                (bool res) =>
 170                {
 171                    // Check image object clicking triggers the correct event
 1172                    eventResult = res;
 1173                });
 174
 1175            Assert.IsTrue(eventResult);
 1176        }
 177
 178        [UnityTest]
 2179        public IEnumerator AddedCorrectlyOnInvisibleParent() { yield return TestHelpers.TestUIElementAddedCorrectlyOnInv
 180    }
 181}