< Summary

Class:Tests.WelcomeHUDViewShould
Assembly:WelcomeHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WelcomeHUD/Tests/WelcomeHUDShould.cs
Covered lines:20
Uncovered lines:0
Coverable lines:20
Total lines:149
Line coverage:100% (20 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
CreateViewProperly()0%110100%
SetUICorrectly()0%110100%
SetButtonsCorrectly()0%110100%
TearDown()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WelcomeHUD/Tests/WelcomeHUDShould.cs

#LineLine coverage
 1using DCL.Helpers;
 2using NUnit.Framework;
 3using System.Collections;
 4using NSubstitute;
 5using NSubstitute.Extensions;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.Events;
 9using UnityEngine.UI;
 10
 11namespace Tests
 12{
 13    public class WelcomeHUDControllerShould : IntegrationTestSuite_Legacy
 14    {
 15        [Test]
 16        public void CreateTheView()
 17        {
 18            // Arrange
 19            WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>();
 20
 21            // Assert
 22            Assert.IsNotNull(controller.view);
 23
 24            controller.Dispose();
 25        }
 26
 27        // TODO(Santi): Check with Brian how to adapt this test to the new async flow of the WelcomeHUD
 28        [Test]
 29        [TestCase(0)]
 30        [TestCase(1)]
 31        [Explicit]
 32        [Category("Explicit")]
 33        public void ReactToViewOnButtonConfirm(int buttonIndexToPress)
 34        {
 35            // Arrange
 36            IWelcomeHUDView mockView = Substitute.For<IWelcomeHUDView>();
 37            mockView.When(x => x.Initialize(Arg.Any<UnityAction<int>>(), Arg.Any<UnityAction>(), Arg.Any<MessageOfTheDay
 38                    .Do(x => x.ArgAt<UnityAction<int>>(0).Invoke(buttonIndexToPress));
 39            WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>();
 40
 41            // Act
 42            controller.Initialize(null);
 43
 44            // Assert
 45            controller.Received().OnConfirmPressed(buttonIndexToPress);
 46            mockView.Received().SetVisible(false);
 47
 48            controller.Dispose();
 49        }
 50
 51        [Test]
 52        public void CallButtonAction()
 53        {
 54            // Arrange
 55            WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>();
 56            controller.Initialize(new MessageOfTheDayConfig
 57            {
 58                buttons = new[]
 59                {
 60                    new MessageOfTheDayConfig.Button { action = "action0" },
 61                    new MessageOfTheDayConfig.Button { action = "action1" }
 62                }
 63            });
 64
 65            // Act
 66            controller.OnConfirmPressed(1);
 67
 68            // Assert
 69            controller.Received().SendAction("action1");
 70
 71            controller.Dispose();
 72        }
 73
 74        [Test]
 75        public void ProcessOutOfBoundsButtonsProperly()
 76        {
 77            // Arrange
 78            WelcomeHUDController controller = Substitute.ForPartsOf<WelcomeHUDController>();
 79            controller.Initialize(new MessageOfTheDayConfig { buttons = new MessageOfTheDayConfig.Button[0] });
 80
 81            // Act
 82            controller.OnConfirmPressed(-1);
 83            controller.OnConfirmPressed(1);
 84
 85            // Assert
 86            controller.DidNotReceiveWithAnyArgs().SendAction(default);
 87
 88            controller.Dispose();
 89        }
 90    }
 91
 92    public class WelcomeHUDViewShould : IntegrationTestSuite_Legacy
 93    {
 94        private WelcomeHUDView view;
 95
 96        protected override IEnumerator SetUp()
 97        {
 398            yield return base.SetUp();
 399            view = WelcomeHUDView.CreateView();
 3100        }
 101
 102        [Test]
 103        public void CreateViewProperly()
 104        {
 1105            Assert.IsNotNull(view);
 1106            Assert.IsNotNull(view.gameObject);
 1107        }
 108
 109        [Test]
 110        public void SetUICorrectly()
 111        {
 1112            view.Initialize(null, null,
 113                new MessageOfTheDayConfig
 114                {
 115                    title = "title",
 116                    body = "body",
 117                });
 118
 1119            Assert.AreEqual("title", view.titleText.text);
 1120            Assert.AreEqual("body", view.bodyText.text);
 1121        }
 122
 123        [Test]
 124        public void SetButtonsCorrectly()
 125        {
 1126            view.Initialize(null, null,
 127                new MessageOfTheDayConfig
 128                {
 129                    buttons = new[]
 130                    {
 131                        new MessageOfTheDayConfig.Button { caption = "button0", tint = Color.green },
 132                        new MessageOfTheDayConfig.Button { caption = "button1", tint = Color.blue },
 133                    }
 134                });
 135
 1136            Assert.AreEqual("button0", view.buttonsParent.GetChild(0).GetComponentInChildren<TextMeshProUGUI>().text);
 1137            Assert.AreEqual(Color.green, view.buttonsParent.GetChild(0).GetComponentInChildren<Image>().color);
 1138            Assert.AreEqual("button1", view.buttonsParent.GetChild(1).GetComponentInChildren<TextMeshProUGUI>().text);
 1139            Assert.AreEqual(Color.blue, view.buttonsParent.GetChild(1).GetComponentInChildren<Image>().color);
 1140        }
 141
 142        protected override IEnumerator TearDown()
 143        {
 3144            if (view != null && view.gameObject != null)
 3145                Object.Destroy(view.gameObject);
 3146            yield return base.TearDown();
 3147        }
 148    }
 149}