| | 1 | | using NSubstitute; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace Tests.BuildModeHUDViews |
| | 7 | | { |
| | 8 | | public class InspectorViewShould |
| | 9 | | { |
| | 10 | | private InspectorView inspectorView; |
| | 11 | |
|
| | 12 | | [SetUp] |
| 16 | 13 | | public void SetUp() { inspectorView = InspectorView.Create(); } |
| | 14 | |
|
| | 15 | | [TearDown] |
| 16 | 16 | | public void TearDown() { Object.Destroy(inspectorView.gameObject); } |
| | 17 | |
|
| | 18 | | [Test] |
| | 19 | | public void InvokeEntityActionCorrectly() |
| | 20 | | { |
| | 21 | | // Arrange |
| 1 | 22 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 23 | | testEntity.entityUniqueId = "testId"; |
| 1 | 24 | | EntityListAdapter testEntityListAdapter = new GameObject("_EntityListAdapter").AddComponent<EntityListAdapte |
| 1 | 25 | | testEntity.entityUniqueId = "testId"; |
| 1 | 26 | | EntityAction testEntityAction = EntityAction.SHOW; |
| 1 | 27 | | DCLBuilderInWorldEntity returnedEntity = null; |
| 1 | 28 | | EntityListAdapter returnedEntityListAdapter = null; |
| 1 | 29 | | EntityAction retournedEntityAction = EntityAction.DELETE; |
| 1 | 30 | | inspectorView.OnEntityActionInvoked += (action, entityToApply, adapter) => |
| | 31 | | { |
| 1 | 32 | | retournedEntityAction = action; |
| 1 | 33 | | returnedEntity = entityToApply; |
| 1 | 34 | | returnedEntityListAdapter = adapter; |
| 1 | 35 | | }; |
| | 36 | |
|
| | 37 | | // Act |
| 1 | 38 | | inspectorView.EntityActionInvoked(testEntityAction, testEntity, testEntityListAdapter); |
| | 39 | |
|
| | 40 | | // Assert |
| 1 | 41 | | Assert.AreEqual(testEntity.entityUniqueId, returnedEntity.entityUniqueId, "The entity does not match!!"); |
| 1 | 42 | | Assert.AreEqual(testEntityListAdapter, returnedEntityListAdapter, "The entity list adapter does not match!!" |
| 1 | 43 | | Assert.AreEqual(testEntityAction, retournedEntityAction, "The entity action does not match!!"); |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | [Test] |
| | 47 | | public void RenameEntityCorrectly() |
| | 48 | | { |
| | 49 | | // Arrange |
| 1 | 50 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 51 | | testEntity.entityUniqueId = "testId"; |
| 1 | 52 | | string testText = "Test text"; |
| 1 | 53 | | DCLBuilderInWorldEntity retournedEntity = null; |
| 1 | 54 | | string retournedText = ""; |
| 1 | 55 | | inspectorView.OnEntityRename += (entity, newName) => |
| | 56 | | { |
| 1 | 57 | | retournedEntity = entity; |
| 1 | 58 | | retournedText = newName; |
| 1 | 59 | | }; |
| | 60 | |
|
| | 61 | | // Act |
| 1 | 62 | | inspectorView.EntityRename(testEntity, testText); |
| | 63 | |
|
| | 64 | | // Assert |
| 1 | 65 | | Assert.AreEqual(testEntity.entityUniqueId, retournedEntity.entityUniqueId, "The entity does not match!!"); |
| 1 | 66 | | Assert.AreEqual(testText, retournedText, "The text does not match!!"); |
| 1 | 67 | | } |
| | 68 | |
|
| | 69 | | [Test] |
| | 70 | | [TestCase(true)] |
| | 71 | | [TestCase(false)] |
| | 72 | | public void SetActiveCorrectly(bool isActive) |
| | 73 | | { |
| | 74 | | // Arrange |
| 2 | 75 | | inspectorView.gameObject.SetActive(!isActive); |
| | 76 | |
|
| | 77 | | // Act |
| 2 | 78 | | inspectorView.SetActive(isActive); |
| | 79 | |
|
| | 80 | | // Assert |
| 2 | 81 | | Assert.AreEqual(isActive, inspectorView.gameObject.activeSelf, "The game object activation property does not |
| 2 | 82 | | } |
| | 83 | |
|
| | 84 | | [Test] |
| | 85 | | public void SetEntitiesListCorrectly() |
| | 86 | | { |
| | 87 | | // Arrange |
| 1 | 88 | | List<DCLBuilderInWorldEntity> testList = new List<DCLBuilderInWorldEntity>(); |
| 1 | 89 | | DCLBuilderInWorldEntity testEntity1 = new GameObject("_DCLBuilderInWorldEntity1").AddComponent<DCLBuilderInW |
| 1 | 90 | | testEntity1.entityUniqueId = "testId1"; |
| 1 | 91 | | DCLBuilderInWorldEntity testEntity2 = new GameObject("_DCLBuilderInWorldEntity2").AddComponent<DCLBuilderInW |
| 1 | 92 | | testEntity1.entityUniqueId = "testId2"; |
| 1 | 93 | | DCLBuilderInWorldEntity testEntity3 = new GameObject("_DCLBuilderInWorldEntity3").AddComponent<DCLBuilderInW |
| 1 | 94 | | testEntity1.entityUniqueId = "testId3"; |
| 1 | 95 | | testList.Add(testEntity1); |
| 1 | 96 | | testList.Add(testEntity2); |
| 1 | 97 | | testList.Add(testEntity3); |
| 1 | 98 | | inspectorView.entitiesList = new List<DCLBuilderInWorldEntity>(); |
| | 99 | |
|
| | 100 | | // Act |
| 1 | 101 | | inspectorView.SetEntitiesList(testList); |
| | 102 | |
|
| | 103 | | // Assert |
| 1 | 104 | | Assert.AreEqual(3, inspectorView.entitiesList.Count, "The number of set entities does not match!"); |
| 8 | 105 | | for (int i = 0; i < 3; i++) |
| | 106 | | { |
| 3 | 107 | | Assert.AreEqual(testList[i].entityUniqueId, inspectorView.entitiesList[i].entityUniqueId, "The added ent |
| | 108 | | } |
| 1 | 109 | | } |
| | 110 | |
|
| | 111 | | [Test] |
| | 112 | | public void ClearEntitiesListCorrectly() |
| | 113 | | { |
| | 114 | | // Arrange |
| 1 | 115 | | List<DCLBuilderInWorldEntity> testList = new List<DCLBuilderInWorldEntity>(); |
| 1 | 116 | | DCLBuilderInWorldEntity testEntity1 = new GameObject("_DCLBuilderInWorldEntity1").AddComponent<DCLBuilderInW |
| 1 | 117 | | testEntity1.entityUniqueId = "testId1"; |
| 1 | 118 | | DCLBuilderInWorldEntity testEntity2 = new GameObject("_DCLBuilderInWorldEntity2").AddComponent<DCLBuilderInW |
| 1 | 119 | | testEntity1.entityUniqueId = "testId2"; |
| 1 | 120 | | DCLBuilderInWorldEntity testEntity3 = new GameObject("_DCLBuilderInWorldEntity3").AddComponent<DCLBuilderInW |
| 1 | 121 | | testEntity1.entityUniqueId = "testId3"; |
| 1 | 122 | | testList.Add(testEntity1); |
| 1 | 123 | | testList.Add(testEntity2); |
| 1 | 124 | | testList.Add(testEntity3); |
| 1 | 125 | | inspectorView.entitiesList = testList; |
| | 126 | |
|
| | 127 | | // Act |
| 1 | 128 | | inspectorView.ClearEntitiesList(); |
| | 129 | |
|
| | 130 | | // Assert |
| 1 | 131 | | Assert.AreEqual(0, inspectorView.entitiesList.Count, "The number of set entities does not match!"); |
| 1 | 132 | | } |
| | 133 | |
|
| | 134 | | [Test] |
| | 135 | | public void SetCloseButtonsActionCorrectly() |
| | 136 | | { |
| | 137 | | // Arrange |
| 1 | 138 | | bool actionsCalled = false; |
| | 139 | |
|
| | 140 | | // Act |
| 3 | 141 | | inspectorView.SetCloseButtonsAction(() => { actionsCalled = true; }); |
| 1 | 142 | | inspectorView.closeEntityListBtn.onClick.Invoke(); |
| | 143 | |
|
| | 144 | | // Assert |
| 1 | 145 | | Assert.IsTrue(actionsCalled, ""); |
| 1 | 146 | | } |
| | 147 | |
|
| | 148 | | [Test] |
| | 149 | | public void ConfigureSceneLimitsCorrectly() |
| | 150 | | { |
| | 151 | | // Arrange |
| 1 | 152 | | ISceneLimitsController mockedSceneLimitsController = Substitute.For<ISceneLimitsController>(); |
| 1 | 153 | | inspectorView.sceneLimitsController = null; |
| | 154 | |
|
| | 155 | |
|
| | 156 | | // Act |
| 1 | 157 | | inspectorView.ConfigureSceneLimits(mockedSceneLimitsController); |
| | 158 | |
|
| | 159 | | // Assert |
| 1 | 160 | | Assert.AreEqual(mockedSceneLimitsController, inspectorView.sceneLimitsController, "The scene limits controll |
| 1 | 161 | | mockedSceneLimitsController.Received(1).Initialize(inspectorView.sceneLimitsView); |
| 1 | 162 | | } |
| | 163 | | } |
| | 164 | | } |