| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using UnityEditor; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace 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"; |
| 3 | 19 | | var sceneCardPrefab = AssetDatabase.LoadAssetAtPath<SceneCardView>(sceneCardPrefabPath); |
| | 20 | |
|
| 3 | 21 | | sectionController = new SectionScenesController(); |
| 3 | 22 | | scenesController = new ScenesViewController(sceneCardPrefab); |
| | 23 | |
|
| 3 | 24 | | scenesController.AddListener((IDeployedSceneListener)sectionController); |
| 3 | 25 | | scenesController.AddListener((IProjectSceneListener)sectionController); |
| 3 | 26 | | } |
| | 27 | |
|
| | 28 | | [TearDown] |
| | 29 | | public void TearDown() |
| | 30 | | { |
| 3 | 31 | | scenesController.Dispose(); |
| 3 | 32 | | sectionController.Dispose(); |
| 3 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void HavePrefabSetupCorrectly() |
| | 37 | | { |
| 1 | 38 | | Assert.AreEqual(0, sectionController.view.deployedSceneContainer.transform.childCount, "InWorldCardsContaine |
| 1 | 39 | | Assert.AreEqual(0, sectionController.view.projectSceneContainer.transform.childCount, "ProjectsCardsContaine |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | [Test] |
| | 43 | | public void ShowEmptyScreenWhenNoScenes() |
| | 44 | | { |
| 1 | 45 | | Assert.IsTrue(sectionController.view.emptyScreen.activeSelf); |
| 1 | 46 | | Assert.IsFalse(sectionController.view.contentScreen.activeSelf); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | [Test] |
| | 50 | | public void ShowAndHideCardsCorrectly() |
| | 51 | | { |
| 1 | 52 | | List<ISceneData> scenes = new List<ISceneData>(); |
| 1 | 53 | | Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 54 | | Assert.IsFalse(sectionController.view.projectsContainer.activeSelf); |
| | 55 | |
|
| | 56 | | //add project scene |
| 1 | 57 | | scenes.Add(new SceneData() { isDeployed = false, id = "Project1" }); |
| 1 | 58 | | scenesController.SetScenes(scenes.ToArray()); |
| 1 | 59 | | Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 60 | | Assert.IsTrue(sectionController.view.projectsContainer.activeSelf); |
| | 61 | |
|
| | 62 | | //add deployed scenes |
| 1 | 63 | | scenes.Add(new SceneData() { isDeployed = true, id = "Deployed1" }); |
| 1 | 64 | | scenes.Add(new SceneData() { isDeployed = true, id = "Deployed2" }); |
| 1 | 65 | | scenes.Add(new SceneData() { isDeployed = true, id = "Deployed3" }); |
| 1 | 66 | | scenesController.SetScenes(scenes.ToArray()); |
| 1 | 67 | | Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 68 | | Assert.IsTrue(sectionController.view.projectsContainer.activeSelf); |
| 1 | 69 | | Assert.AreEqual(1, sectionController.view.projectSceneContainer.childCount); |
| 1 | 70 | | Assert.AreEqual(3, sectionController.view.deployedSceneContainer.childCount); |
| 1 | 71 | | Assert.AreEqual(1, GetVisibleChildrenAmount(sectionController.view.projectSceneContainer)); |
| 1 | 72 | | Assert.AreEqual(3, GetVisibleChildrenAmount(sectionController.view.deployedSceneContainer)); |
| 1 | 73 | | Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun |
| 1 | 74 | | Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co |
| | 75 | |
|
| | 76 | | //add deployed scene |
| 1 | 77 | | scenes.Add(new SceneData() { isDeployed = true, id = "Deployed4" }); |
| 1 | 78 | | scenesController.SetScenes(scenes.ToArray()); |
| 1 | 79 | | Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 80 | | Assert.IsTrue(sectionController.view.projectsContainer.activeSelf); |
| 1 | 81 | | Assert.AreEqual(1, sectionController.view.projectSceneContainer.childCount); |
| 1 | 82 | | Assert.AreEqual(4, sectionController.view.deployedSceneContainer.childCount); |
| 1 | 83 | | Assert.AreEqual(1, GetVisibleChildrenAmount(sectionController.view.projectSceneContainer)); |
| 1 | 84 | | Assert.AreEqual(3, GetVisibleChildrenAmount(sectionController.view.deployedSceneContainer)); |
| 1 | 85 | | Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun |
| 1 | 86 | | Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co |
| | 87 | |
|
| | 88 | | //remove deployed scene |
| 6 | 89 | | scenes = scenes.FindAll((data) => data.id != "Deployed3"); |
| 1 | 90 | | scenesController.SetScenes(scenes.ToArray()); |
| 1 | 91 | | Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 92 | | Assert.IsTrue(sectionController.view.projectsContainer.activeSelf); |
| 1 | 93 | | Assert.AreEqual(1, sectionController.view.projectSceneContainer.childCount); |
| 1 | 94 | | Assert.AreEqual(3, sectionController.view.deployedSceneContainer.childCount); |
| 1 | 95 | | Assert.AreEqual(1, GetVisibleChildrenAmount(sectionController.view.projectSceneContainer)); |
| 1 | 96 | | Assert.AreEqual(3, GetVisibleChildrenAmount(sectionController.view.deployedSceneContainer)); |
| 1 | 97 | | Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun |
| 1 | 98 | | Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co |
| | 99 | |
|
| | 100 | | //remove all deployed |
| 1 | 101 | | scenes = new List<ISceneData>() { new SceneData() { isDeployed = false, id = "Project1" } }; |
| 1 | 102 | | scenesController.SetScenes(scenes.ToArray()); |
| 1 | 103 | | Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 104 | | Assert.IsTrue(sectionController.view.projectsContainer.activeSelf); |
| 1 | 105 | | Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun |
| 1 | 106 | | Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co |
| | 107 | |
|
| | 108 | | //switch project to deployed |
| 1 | 109 | | scenes = new List<ISceneData>() { new SceneData() { isDeployed = true, id = "Project1" } }; |
| 1 | 110 | | scenesController.SetScenes(scenes.ToArray()); |
| 1 | 111 | | Assert.IsTrue(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 112 | | Assert.IsFalse(sectionController.view.projectsContainer.activeSelf); |
| 1 | 113 | | Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun |
| 1 | 114 | | Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co |
| | 115 | |
|
| | 116 | | //remove all scenes |
| 1 | 117 | | scenesController.SetScenes(new ISceneData[] { }); |
| 1 | 118 | | Assert.IsFalse(sectionController.view.inWorldContainer.activeSelf); |
| 1 | 119 | | Assert.IsFalse(sectionController.view.projectsContainer.activeSelf); |
| 1 | 120 | | Assert.AreEqual(sectionController.view.projectSceneContainer.childCount, sectionController.projectViews.Coun |
| 1 | 121 | | Assert.AreEqual(sectionController.view.deployedSceneContainer.childCount, sectionController.deployedViews.Co |
| 1 | 122 | | } |
| | 123 | |
|
| 19 | 124 | | public int GetVisibleChildrenAmount(Transform parent) { return parent.Cast<Transform>().Count(child => child.gam |
| | 125 | | } |
| | 126 | | } |