< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputTextCreate()0%770100%
TestOnClickEvent()0%550100%
TestPropertiesAreAppliedCorrectly()0%330100%
AddedCorrectlyOnInvisibleParent()0%330100%
TestOnFocus()0%330100%
TestOnSubmit()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UI/UIInputText/Tests/UIInputTextTests.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Helpers;
 3using DCL.Interface;
 4using DCL.Models;
 5using NUnit.Framework;
 6using System.Collections;
 7using UnityEngine;
 8using UnityEngine.TestTools;
 9using Color = UnityEngine.Color;
 10
 11namespace Tests
 12{
 13    public class UIInputTextTests : IntegrationTestSuite_Legacy
 14    {
 15        UIScreenSpace ssshape;
 16        UIInputText textInput;
 17        Camera mockCamera;
 18
 19        public IEnumerator InputTextCreate()
 20        {
 421            ssshape = TestHelpers.SharedComponentCreate<UIScreenSpace, UIScreenSpace.Model>(
 22                scene,
 23                DCL.Models.CLASS_ID.UI_SCREEN_SPACE_SHAPE);
 24
 425            yield return ssshape.routine;
 26
 427            if (mockCamera == null)
 28            {
 429                GameObject go = new GameObject("Mock camera");
 430                mockCamera = go.AddComponent<Camera>();
 431                mockCamera.clearFlags = CameraClearFlags.Color;
 432                mockCamera.backgroundColor = Color.black;
 33            }
 34
 435            textInput = TestHelpers.SharedComponentCreate<UIInputText, UIInputText.Model>(
 36                scene,
 37                DCL.Models.CLASS_ID.UI_INPUT_TEXT_SHAPE,
 38                new UIInputText.Model()
 39                {
 40                    textModel = new DCL.Components.TextShape.Model()
 41                    {
 42                        color = Color.white,
 43                        opacity = 1,
 44                    },
 45
 46                    isPointerBlocker = true,
 47                    placeholder = "Chat here!",
 48                    placeholderColor = Color.grey,
 49                    focusedBackground = Color.black,
 50                    parentComponent = ssshape.id,
 51                    positionX = new UIValue(0.5f, UIValue.Unit.PERCENT),
 52                    positionY = new UIValue(0.5f, UIValue.Unit.PERCENT),
 53                    height = new UIValue(100),
 54                    width = new UIValue(100),
 55                    onClick = "UUIDFakeEventId"
 56                });
 57
 458            yield return textInput.routine;
 459            yield return null;
 60
 461            if (mockCamera != null)
 462                Object.Destroy(mockCamera.gameObject);
 463        }
 64
 65        [UnityTest]
 66        public IEnumerator TestOnClickEvent()
 67        {
 168            yield return InputTextCreate();
 69
 70            //------------------------------------------------------------------------
 71            // Test click events
 172            TMPro.TMP_InputField inputField = textInput.referencesContainer.inputField;
 73
 174            string targetEventType = "SceneEvent";
 75
 176            var onClickEvent = new WebInterface.OnClickEvent();
 177            onClickEvent.uuid = textInput.model.onClick;
 78
 179            var sceneEvent = new WebInterface.SceneEvent<WebInterface.OnClickEvent>();
 180            sceneEvent.sceneId = scene.sceneData.id;
 181            sceneEvent.payload = onClickEvent;
 182            sceneEvent.eventType = "uuidEvent";
 183            string eventJSON = JsonUtility.ToJson(sceneEvent);
 84
 185            bool eventTriggered = false;
 86
 87
 188            yield return TestHelpers.WaitForMessageFromEngine(targetEventType, eventJSON,
 89                () =>
 90                {
 191                    UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(inputField.gameObject, null);
 192                    inputField.ActivateInputField();
 193                    inputField.Select();
 194                },
 295                () => { eventTriggered = true; });
 96
 197            yield return null;
 98
 199            Assert.IsTrue(eventTriggered);
 1100        }
 101
 102        [UnityTest]
 103        public IEnumerator TestPropertiesAreAppliedCorrectly()
 104        {
 1105            yield return InputTextCreate();
 106
 1107            Assert.AreEqual(Color.white, textInput.model.textModel.color);
 1108            Assert.AreEqual(1, textInput.model.textModel.opacity);
 1109            Assert.AreEqual("Chat here!", textInput.inputField.text);
 1110            Assert.IsTrue(textInput.referencesContainer != null, "Ref container is null?!");
 1111            Assert.AreEqual(textInput.referencesContainer.transform.parent, ssshape.childHookRectTransform);
 1112            Assert.AreEqual(textInput.model.focusedBackground.r, textInput.referencesContainer.bgImage.color.r);
 1113            Assert.AreEqual(textInput.model.focusedBackground.g, textInput.referencesContainer.bgImage.color.g);
 1114            Assert.AreEqual(textInput.model.focusedBackground.b, textInput.referencesContainer.bgImage.color.b);
 1115            Assert.AreEqual(textInput.model.textModel.opacity, textInput.referencesContainer.bgImage.color.a);
 116
 1117            ssshape.Dispose();
 1118            textInput.Dispose();
 1119            Object.DestroyImmediate(mockCamera.gameObject);
 1120        }
 121
 122        [UnityTest]
 2123        public IEnumerator AddedCorrectlyOnInvisibleParent() { yield return TestHelpers.TestUIElementAddedCorrectlyOnInv
 124
 125        [UnityTest]
 126        public IEnumerator TestOnFocus()
 127        {
 1128            yield return InputTextCreate();
 129
 1130            textInput.OnFocus("");
 131
 1132            Assert.IsTrue(textInput.inputField.caretColor == Color.white);
 1133            Assert.IsTrue(textInput.inputField.text == "");
 134
 1135            textInput.OnBlur("");
 136
 1137            Assert.IsTrue(textInput.inputField.text == textInput.model.placeholder);
 1138            Assert.IsTrue(textInput.inputField.caretColor == Color.clear);
 139
 1140            ssshape.Dispose();
 1141            textInput.Dispose();
 1142            Object.DestroyImmediate(mockCamera.gameObject);
 1143        }
 144
 145        [UnityTest]
 146        public IEnumerator TestOnSubmit()
 147        {
 1148            yield return InputTextCreate();
 149
 1150            textInput.inputField.text = "hello world";
 1151            textInput.OnSubmit("");
 152
 1153            Assert.IsTrue(textInput.inputField.text == "");
 1154            Assert.IsTrue(textInput.inputField.caretColor == Color.white);
 155
 1156            ssshape.Dispose();
 1157            textInput.Dispose();
 1158            Object.DestroyImmediate(mockCamera.gameObject);
 1159        }
 160    }
 161}