< Summary

Class:Tests.SectionLandShould
Assembly:BuilderProjectsPanelTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/SectionLandShould.cs
Covered lines:70
Uncovered lines:0
Coverable lines:70
Total lines:158
Line coverage:100% (70 of 70)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
PrefabSetupCorrectly()0%110100%
SetEmptyCorrectly()0%110100%
SetNotEmptyCorrectly()0%110100%
SetNoSearchResultCorrectly()0%110100%
SetLoadingCorrectly()0%110100%
ShowAndHideCorrectly()0%110100%
SetLandsCorrectly()0%110100%
UpdateLandCorrectly()0%110100%
GetVisibleChildrenAmount(...)0%220100%
CreateLandData(...)0%110100%
CreateLandData(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/SectionLandShould.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL;
 4using NUnit.Framework;
 5using UnityEngine;
 6
 7namespace Tests
 8{
 9    public class SectionLandShould
 10    {
 11        private SectionLandView view;
 12
 13        [SetUp]
 14        public void SetUp()
 15        {
 816            var prefab = Resources.Load<SectionLandView>(SectionLandController.VIEW_PREFAB_PATH);
 817            view = Object.Instantiate(prefab);
 818            WebRequestController.Create();
 819        }
 20
 21        [TearDown]
 22        public void TearDown()
 23        {
 824            Object.Destroy(view.gameObject);
 825            DCL.Environment.i.platform.webRequest.Dispose();
 826        }
 27
 28        [Test]
 29        public void PrefabSetupCorrectly()
 30        {
 131            Assert.AreEqual(1, view.GetLandElementsContainer().childCount);
 132            Assert.NotNull(view.landElementView);
 133        }
 34
 35        [Test]
 36        public void SetEmptyCorrectly()
 37        {
 138            view.SetEmpty();
 139            Assert.IsTrue(view.emptyContainer.activeSelf);
 140            Assert.IsFalse(view.contentContainer.activeSelf);
 141            Assert.IsFalse(view.loadingAnimationContainer.activeSelf);
 142            Assert.IsFalse(view.noSearchResultContainer.activeSelf);
 143        }
 44
 45        [Test]
 46        public void SetNotEmptyCorrectly()
 47        {
 148            view.SetFilled();
 149            Assert.IsTrue(view.contentContainer.activeSelf);
 150            Assert.IsFalse(view.emptyContainer.activeSelf);
 151            Assert.IsFalse(view.loadingAnimationContainer.activeSelf);
 152            Assert.IsFalse(view.noSearchResultContainer.activeSelf);
 153        }
 54
 55        [Test]
 56        public void SetNoSearchResultCorrectly()
 57        {
 158            view.SetNoSearchResult();
 159            Assert.IsFalse(view.contentContainer.activeSelf);
 160            Assert.IsFalse(view.emptyContainer.activeSelf);
 161            Assert.IsFalse(view.loadingAnimationContainer.activeSelf);
 162            Assert.IsTrue(view.noSearchResultContainer.activeSelf);
 163        }
 64
 65        [Test]
 66        public void SetLoadingCorrectly()
 67        {
 168            view.SetLoading();
 169            Assert.IsFalse(view.contentContainer.activeSelf);
 170            Assert.IsFalse(view.emptyContainer.activeSelf);
 171            Assert.IsTrue(view.loadingAnimationContainer.activeSelf);
 172            Assert.IsFalse(view.noSearchResultContainer.activeSelf);
 173        }
 74
 75        [Test]
 76        public void ShowAndHideCorrectly()
 77        {
 178            SectionLandController controller = new SectionLandController(view);
 179            controller.SetVisible(true);
 80
 181            controller.SetVisible(false);
 182            Assert.IsFalse(view.gameObject.activeSelf);
 83
 184            controller.SetVisible(true);
 185            Assert.IsTrue(view.gameObject.activeSelf);
 186            controller.Dispose();
 187        }
 88
 89        [Test]
 90        public void SetLandsCorrectly()
 91        {
 192            SectionLandController controller = new SectionLandController(view);
 193            ILandsListener landsListener = controller;
 94
 195            landsListener.OnSetLands(new[] { CreateLandData("1"), CreateLandData("2") });
 196            Assert.AreEqual(2, GetVisibleChildrenAmount(view.GetLandElementsContainer()));
 197            Assert.IsTrue(view.contentContainer.activeSelf);
 98
 199            landsListener.OnSetLands(new[] { CreateLandData("1") });
 1100            Assert.AreEqual(1, GetVisibleChildrenAmount(view.GetLandElementsContainer()));
 1101            Assert.IsTrue(view.contentContainer.activeSelf);
 102
 1103            landsListener.OnSetLands(new LandWithAccess[] { });
 1104            Assert.AreEqual(0, GetVisibleChildrenAmount(view.GetLandElementsContainer()));
 1105            Assert.IsFalse(view.contentContainer.activeSelf);
 1106            Assert.IsTrue(view.emptyContainer.activeSelf);
 107
 1108            controller.Dispose();
 1109        }
 110
 111        [Test]
 112        public void UpdateLandCorrectly()
 113        {
 114            const string startingName = "Temptation";
 115            const string updatedName = "New Temptation";
 116
 1117            SectionLandController controller = new SectionLandController(view);
 1118            ILandsListener landsListener = controller;
 1119            LandElementView landElementView = view.GetLandElementeBaseView();
 120
 1121            landsListener.OnSetLands(new[] { CreateLandData("1", startingName) });
 1122            Assert.AreEqual(1, GetVisibleChildrenAmount(view.GetLandElementsContainer()));
 1123            Assert.AreEqual(startingName, landElementView.landName.text);
 124
 1125            landsListener.OnSetLands(new[] { CreateLandData("1", updatedName) });
 1126            Assert.AreEqual(1, GetVisibleChildrenAmount(view.GetLandElementsContainer()));
 1127            Assert.AreEqual(updatedName, landElementView.landName.text);
 128
 129
 1130            controller.Dispose();
 1131        }
 132
 13133        private int GetVisibleChildrenAmount(Transform parent) { return parent.Cast<Transform>().Count(child => child.ga
 134
 135        private LandWithAccess CreateLandData(string id)
 136        {
 3137            return new LandWithAccess(
 138                new Land()
 139                {
 140                    id = id,
 141                    parcels = new List<Parcel>()
 142                }
 143            );
 144        }
 145
 146        private LandWithAccess CreateLandData(string id, string name)
 147        {
 2148            return new LandWithAccess(
 149                new Land()
 150                {
 151                    id = id,
 152                    name = name,
 153                    parcels = new List<Parcel>()
 154                }
 155            );
 156        }
 157    }
 158}