< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
HavePrefabSetupCorrectly()0%110100%
ShowEmptyScreenWhenNoScenes()0%110100%
ShowAndHideCardsCorrectly()0%220100%
GetVisibleChildrenAmount(...)0%220100%

File(s)

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

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEditor;
 5using UnityEngine;
 6
 7namespace Tests
 8{
 9    public class SectionScenesShould
 10    {
 11        private SectionScenesController sectionController;
 12        private IScenesViewController scenesController;
 13
 14        [SetUp]
 15        public void SetUp()
 16        {
 17            const string sceneCardPrefabPath =
 18                "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/SceneCardView.prefab";
 319            var sceneCardPrefab = AssetDatabase.LoadAssetAtPath<SceneCardView>(sceneCardPrefabPath);
 20
 321            sectionController = new SectionScenesController();
 322            scenesController = new ScenesViewController(sceneCardPrefab);
 23
 324            scenesController.AddListener((IDeployedSceneListener)sectionController);
 325            scenesController.AddListener((IProjectSceneListener)sectionController);
 326        }
 27
 28        [TearDown]
 29        public void TearDown()
 30        {
 331            scenesController.Dispose();
 332            sectionController.Dispose();
 333        }
 34
 35        [Test]
 36        public void HavePrefabSetupCorrectly()
 37        {
 138            Assert.AreEqual(0, sectionController.view.deployedSceneContainer.transform.childCount, "InWorldCardsContaine
 139            Assert.AreEqual(0, sectionController.view.projectSceneContainer.transform.childCount, "ProjectsCardsContaine
 140        }
 41
 42        [Test]
 43        public void ShowEmptyScreenWhenNoScenes()
 44        {
 145            Assert.IsTrue(sectionController.view.emptyScreen.activeSelf);
 146            Assert.IsFalse(sectionController.view.contentScreen.activeSelf);
 147        }
 48
 49        [Test]
 50        public void ShowAndHideCardsCorrectly()
 51        {
 152            List<ISceneData> scenes = new List<ISceneData>();
 153            Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf);
 154            Assert.IsFalse(sectionController.view.projectsContainer.activeSelf);
 55
 56            //add project scene
 157            scenes.Add(new SceneData() { isDeployed = false, id = "Project1" });
 158            scenesController.SetScenes(scenes.ToArray());
 159            Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf);
 160            Assert.IsTrue(sectionController.view.projectsContainer.activeSelf);
 61
 62            //add deployed scenes
 163            scenes.Add(new SceneData() { isDeployed = true, id = "Deployed1" });
 164            scenes.Add(new SceneData() { isDeployed = true, id = "Deployed2" });
 165            scenes.Add(new SceneData() { isDeployed = true, id = "Deployed3" });
 166            scenesController.SetScenes(scenes.ToArray());
 167            Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf);
 168            Assert.IsTrue(sectionController.view.projectsContainer.activeSelf);
 169            Assert.AreEqual(1, sectionController.view.projectSceneContainer.childCount);
 170            Assert.AreEqual(3, sectionController.view.deployedSceneContainer.childCount);
 171            Assert.AreEqual(1, GetVisibleChildrenAmount(sectionController.view.projectSceneContainer));
 172            Assert.AreEqual(3, GetVisibleChildrenAmount(sectionController.view.deployedSceneContainer));
 173            Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun
 174            Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co
 75
 76            //add deployed scene
 177            scenes.Add(new SceneData() { isDeployed = true, id = "Deployed4" });
 178            scenesController.SetScenes(scenes.ToArray());
 179            Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf);
 180            Assert.IsTrue(sectionController.view.projectsContainer.activeSelf);
 181            Assert.AreEqual(1, sectionController.view.projectSceneContainer.childCount);
 182            Assert.AreEqual(4, sectionController.view.deployedSceneContainer.childCount);
 183            Assert.AreEqual(1, GetVisibleChildrenAmount(sectionController.view.projectSceneContainer));
 184            Assert.AreEqual(3, GetVisibleChildrenAmount(sectionController.view.deployedSceneContainer));
 185            Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun
 186            Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co
 87
 88            //remove deployed scene
 689            scenes = scenes.FindAll((data) => data.id != "Deployed3");
 190            scenesController.SetScenes(scenes.ToArray());
 191            Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf);
 192            Assert.IsTrue(sectionController.view.projectsContainer.activeSelf);
 193            Assert.AreEqual(1, sectionController.view.projectSceneContainer.childCount);
 194            Assert.AreEqual(3, sectionController.view.deployedSceneContainer.childCount);
 195            Assert.AreEqual(1, GetVisibleChildrenAmount(sectionController.view.projectSceneContainer));
 196            Assert.AreEqual(3, GetVisibleChildrenAmount(sectionController.view.deployedSceneContainer));
 197            Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun
 198            Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co
 99
 100            //remove all deployed
 1101            scenes = new List<ISceneData>() { new SceneData() { isDeployed = false, id = "Project1" } };
 1102            scenesController.SetScenes(scenes.ToArray());
 1103            Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf);
 1104            Assert.IsTrue(sectionController.view.projectsContainer.activeSelf);
 1105            Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun
 1106            Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co
 107
 108            //switch project to deployed
 1109            scenes = new List<ISceneData>() { new SceneData() { isDeployed = true, id = "Project1" } };
 1110            scenesController.SetScenes(scenes.ToArray());
 1111            Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf);
 1112            Assert.IsFalse(sectionController.view.projectsContainer.activeSelf);
 1113            Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun
 1114            Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co
 115
 116            //remove all scenes
 1117            scenesController.SetScenes(new ISceneData[] { });
 1118            Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf);
 1119            Assert.IsFalse(sectionController.view.projectsContainer.activeSelf);
 1120            Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun
 1121            Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co
 1122        }
 123
 19124        public int GetVisibleChildrenAmount(Transform parent) { return parent.Cast<Transform>().Count(child => child.gam
 125    }
 126}