< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
HaveScenesContainerEmptyAtInstantiation()0%110100%
ShowCardsInCorrectSortOrder()0%440100%
ShowEmptyCorrectly()0%110100%
ShowFilledCorrectly()0%110100%
ShowNoResultCorrectly()0%110100%
ShowLoadingCorrectly()0%110100%
SetSectionStateCorrectly()0%110100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using NSubstitute;
 4using NUnit.Framework;
 5using UnityEditor;
 6using UnityEngine;
 7
 8namespace Tests
 9{
 10    public class SectionDeployedScenesViewShould
 11    {
 12        private SectionDeployedScenesView view;
 13
 14        [SetUp]
 15        public void SetUp()
 16        {
 717            var prefab = Resources.Load<SectionDeployedScenesView>(SectionDeployedScenesController.VIEW_PREFAB_PATH);
 718            view = Object.Instantiate(prefab);
 719        }
 20
 21        [TearDown]
 1422        public void TearDown() { Object.Destroy(view.gameObject); }
 23
 24        [Test]
 225        public void HaveScenesContainerEmptyAtInstantiation() { Assert.AreEqual(0, view.scenesCardContainer.childCount);
 26
 27        [Test]
 28        public void ShowCardsInCorrectSortOrder()
 29        {
 30            const string prefabAssetPath =
 31                "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/SceneCardView.prefab";
 132            var prefab = AssetDatabase.LoadAssetAtPath<SceneCardView>(prefabAssetPath);
 33
 134            Dictionary<string, ISceneCardView> cardViews = new Dictionary<string, ISceneCardView>();
 35            const int cardsCount = 10;
 2236            for (int i = 0; i < cardsCount; i++)
 37            {
 1038                var card = (ISceneCardView)Object.Instantiate(prefab);
 1039                card.Setup(new SceneData() { size = new Vector2Int(i, i), id = i.ToString() });
 1040                cardViews.Add(i.ToString(), card);
 41            }
 42
 43
 144            SectionDeployedScenesController controller = new SectionDeployedScenesController(view);
 145            controller.searchHandler.SetSortType(SectionSearchHandler.SIZE_SORT_TYPE_ASC);
 46
 147            ((IDeployedSceneListener)controller).OnSetScenes(cardViews);
 48
 149            Assert.AreEqual(cardsCount, view.scenesCardContainer.childCount);
 50
 151            var prev = (ISceneCardView)view.scenesCardContainer.GetChild(0).GetComponent<SceneCardView>();
 2052            for (int i = 1; i < cardsCount; i++)
 53            {
 954                var current = (ISceneCardView)view.scenesCardContainer.GetChild(i).GetComponent<SceneCardView>();
 955                Assert.GreaterOrEqual(current.sceneData.size.x * current.sceneData.size.y, prev.sceneData.size.x * prev.
 956                prev = current;
 57            }
 58
 2259            foreach (var card in cardViews.Values)
 60            {
 1061                card.Dispose();
 62            }
 163            controller.Dispose();
 164        }
 65
 66        [Test]
 67        public void ShowEmptyCorrectly()
 68        {
 169            view.SetEmpty();
 170            Assert.IsFalse(view.contentContainer.activeSelf);
 171            Assert.IsFalse(view.loadingAnimationContainer.activeSelf);
 172            Assert.IsFalse(view.noSearchResultContainer.activeSelf);
 173            Assert.IsTrue(view.emptyContainer.activeSelf);
 174        }
 75
 76        [Test]
 77        public void ShowFilledCorrectly()
 78        {
 179            view.SetFilled();
 180            Assert.IsTrue(view.contentContainer.activeSelf);
 181            Assert.IsFalse(view.loadingAnimationContainer.activeSelf);
 182            Assert.IsFalse(view.noSearchResultContainer.activeSelf);
 183            Assert.IsFalse(view.emptyContainer.activeSelf);
 184        }
 85
 86        [Test]
 87        public void ShowNoResultCorrectly()
 88        {
 189            view.SetNoSearchResult();
 190            Assert.IsFalse(view.contentContainer.activeSelf);
 191            Assert.IsFalse(view.loadingAnimationContainer.activeSelf);
 192            Assert.IsTrue(view.noSearchResultContainer.activeSelf);
 193            Assert.IsFalse(view.emptyContainer.activeSelf);
 194        }
 95
 96        [Test]
 97        public void ShowLoadingCorrectly()
 98        {
 199            view.SetLoading();
 1100            Assert.IsFalse(view.contentContainer.activeSelf);
 1101            Assert.IsTrue(view.loadingAnimationContainer.activeSelf);
 1102            Assert.IsFalse(view.noSearchResultContainer.activeSelf);
 1103            Assert.IsFalse(view.emptyContainer.activeSelf);
 1104        }
 105
 106        [Test]
 107        public void SetSectionStateCorrectly()
 108        {
 1109            SectionDeployedScenesController controller = new SectionDeployedScenesController(view);
 1110            IDeployedSceneListener listener = controller;
 111
 1112            controller.SetFetchingDataState(true);
 1113            listener.OnSetScenes(new Dictionary<string, ISceneCardView>());
 1114            Assert.IsTrue(view.loadingAnimationContainer.activeSelf);
 115
 1116            controller.SetFetchingDataState(false);
 1117            listener.OnSetScenes(new Dictionary<string, ISceneCardView>());
 1118            Assert.IsTrue(view.emptyContainer.activeSelf);
 119
 1120            listener.OnSetScenes(new Dictionary<string, ISceneCardView>() { { "1", Substitute.For<ISceneCardView>() }, {
 1121            Assert.IsTrue(view.contentContainer.activeSelf);
 122
 1123            listener.OnSetScenes(new Dictionary<string, ISceneCardView>() { { "1", Substitute.For<ISceneCardView>() } })
 1124            Assert.IsTrue(view.contentContainer.activeSelf);
 125
 1126            controller.Dispose();
 1127        }
 128    }
 129}