| | 1 | | using NUnit.Framework; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace Tests.BuildModeHUDViews |
| | 5 | | { |
| | 6 | | public class EntityInformationViewShould |
| | 7 | | { |
| | 8 | | private EntityInformationView entityInformationView; |
| | 9 | |
|
| | 10 | | [SetUp] |
| 44 | 11 | | public void SetUp() { entityInformationView = EntityInformationView.Create(); } |
| | 12 | |
|
| | 13 | | [TearDown] |
| 44 | 14 | | public void TearDown() { Object.Destroy(entityInformationView.gameObject); } |
| | 15 | |
|
| | 16 | | [Test] |
| | 17 | | public void SetCurrentEntityCorrectly() |
| | 18 | | { |
| | 19 | | // Arrange |
| 1 | 20 | | DCLBuilderInWorldEntity newEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWorl |
| 1 | 21 | | newEntity.entityUniqueId = "testId"; |
| 1 | 22 | | entityInformationView.currentEntity = null; |
| | 23 | |
|
| | 24 | | // Act |
| 1 | 25 | | entityInformationView.SetCurrentEntity(newEntity); |
| | 26 | |
|
| | 27 | | // Assert |
| 1 | 28 | | Assert.AreEqual(newEntity.entityUniqueId, entityInformationView.currentEntity.entityUniqueId, "The entity id |
| 1 | 29 | | } |
| | 30 | |
|
| | 31 | | [Test] |
| | 32 | | [TestCase(true)] |
| | 33 | | [TestCase(false)] |
| | 34 | | public void ToggleDetailsInfoCorrectly(bool isActive) |
| | 35 | | { |
| | 36 | | // Arrange |
| 2 | 37 | | entityInformationView.detailsGO.SetActive(!isActive); |
| 2 | 38 | | entityInformationView.detailsToggleBtn.sprite = null; |
| | 39 | |
|
| | 40 | | // Act |
| 2 | 41 | | entityInformationView.ToggleDetailsInfo(); |
| | 42 | |
|
| | 43 | | // Assert |
| 2 | 44 | | Assert.AreEqual(isActive, entityInformationView.detailsGO.activeSelf, "The details game object activation pr |
| 2 | 45 | | Assert.AreEqual(isActive ? entityInformationView.openMenuSprite : entityInformationView.closeMenuSprite, ent |
| 2 | 46 | | } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | [TestCase(true)] |
| | 50 | | [TestCase(false)] |
| | 51 | | public void ToggleBasicInfoCorrectly(bool isActive) |
| | 52 | | { |
| | 53 | | // Arrange |
| 2 | 54 | | entityInformationView.basicsGO.SetActive(!isActive); |
| 2 | 55 | | entityInformationView.basicToggleBtn.sprite = null; |
| | 56 | |
|
| | 57 | | // Act |
| 2 | 58 | | entityInformationView.ToggleBasicInfo(); |
| | 59 | |
|
| | 60 | | // Assert |
| 2 | 61 | | Assert.AreEqual(isActive, entityInformationView.basicsGO.activeSelf, "The basics game object activation prop |
| 2 | 62 | | Assert.AreEqual(isActive ? entityInformationView.openMenuSprite : entityInformationView.closeMenuSprite, ent |
| 2 | 63 | | } |
| | 64 | |
|
| | 65 | | [Test] |
| | 66 | | public void StartChangingNameCorrectly() |
| | 67 | | { |
| | 68 | | // Arrange |
| 1 | 69 | | bool changingNameStarted = false; |
| 2 | 70 | | entityInformationView.OnStartChangingName += () => changingNameStarted = true; |
| | 71 | |
|
| | 72 | | // Act |
| 1 | 73 | | entityInformationView.StartChangingName(); |
| | 74 | |
|
| | 75 | | // Assert |
| 1 | 76 | | Assert.IsTrue(changingNameStarted, "changingNameStarted is false!"); |
| 1 | 77 | | } |
| | 78 | |
|
| | 79 | | [Test] |
| | 80 | | public void EndChangingNameCorrectly() |
| | 81 | | { |
| | 82 | | // Arrange |
| 1 | 83 | | bool changingNameEndeed = false; |
| 2 | 84 | | entityInformationView.OnEndChangingName += () => changingNameEndeed = true; |
| | 85 | |
|
| | 86 | | // Act |
| 1 | 87 | | entityInformationView.EndChangingName(); |
| | 88 | |
|
| | 89 | | // Assert |
| 1 | 90 | | Assert.IsTrue(changingNameEndeed, "changingNameEndeed is false!"); |
| 1 | 91 | | } |
| | 92 | |
|
| | 93 | | [Test] |
| | 94 | | public void ChangeEntityNameCorrectly() |
| | 95 | | { |
| | 96 | | // Arrange |
| 1 | 97 | | string newEntityName = "Test name"; |
| 1 | 98 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 99 | | testEntity.entityUniqueId = "testId"; |
| 1 | 100 | | entityInformationView.currentEntity = testEntity; |
| | 101 | |
|
| 1 | 102 | | DCLBuilderInWorldEntity entity = null; |
| 1 | 103 | | string entityName = ""; |
| 1 | 104 | | entityInformationView.OnNameChange += (changedEntity, name) => |
| | 105 | | { |
| 1 | 106 | | entity = changedEntity; |
| 1 | 107 | | entityName = name; |
| 1 | 108 | | }; |
| | 109 | |
|
| | 110 | | // Act |
| 1 | 111 | | entityInformationView.ChangeEntityName(newEntityName); |
| | 112 | |
|
| | 113 | | // Assert |
| 1 | 114 | | Assert.AreEqual(entityInformationView.currentEntity, entity, "The current entity does not mach!"); |
| 1 | 115 | | Assert.AreEqual(newEntityName, entityName, "The entity name does not match!"); |
| 1 | 116 | | } |
| | 117 | |
|
| | 118 | | [Test] |
| | 119 | | public void DisableCorrectly() |
| | 120 | | { |
| | 121 | | // Arrange |
| 1 | 122 | | bool isDisabled = false; |
| 2 | 123 | | entityInformationView.OnDisable += () => isDisabled = true; |
| | 124 | |
|
| | 125 | | // Act |
| 1 | 126 | | entityInformationView.Disable(); |
| | 127 | |
|
| | 128 | | // Assert |
| 1 | 129 | | Assert.IsTrue(isDisabled, "isDisabled is false!"); |
| 1 | 130 | | } |
| | 131 | |
|
| | 132 | | [Test] |
| | 133 | | [TestCase(true)] |
| | 134 | | [TestCase(false)] |
| | 135 | | public void SetEntityThumbnailEnableCorrectly(bool isEnable) |
| | 136 | | { |
| 2 | 137 | | if (entityInformationView.entitytTumbailImg == null) |
| 0 | 138 | | return; |
| | 139 | |
|
| | 140 | | // Arrange |
| 2 | 141 | | entityInformationView.entitytTumbailImg.enabled = !isEnable; |
| | 142 | |
|
| | 143 | | // Act |
| 2 | 144 | | entityInformationView.SetEntityThumbnailEnable(isEnable); |
| | 145 | |
|
| | 146 | | // Assert |
| 2 | 147 | | Assert.AreEqual(isEnable, entityInformationView.entitytTumbailImg.enabled, "Entity Thumbnail enable property |
| 2 | 148 | | } |
| | 149 | |
|
| | 150 | | [Test] |
| | 151 | | public void SetEntityThumbnailTextureCorrectly() |
| | 152 | | { |
| 1 | 153 | | if (entityInformationView.entitytTumbailImg == null) |
| 0 | 154 | | return; |
| | 155 | |
|
| | 156 | | // Arrange |
| 1 | 157 | | Texture2D newTexture = new Texture2D(2, 2, TextureFormat.ARGB32, false); |
| 1 | 158 | | entityInformationView.entitytTumbailImg.texture = null; |
| | 159 | |
|
| | 160 | | // Act |
| 1 | 161 | | entityInformationView.SetEntityThumbnailTexture(newTexture); |
| | 162 | |
|
| | 163 | | // Assert |
| 1 | 164 | | Assert.AreEqual(newTexture, entityInformationView.entitytTumbailImg.texture, "Entity Thumbnail texture does |
| 1 | 165 | | } |
| | 166 | |
|
| | 167 | | [Test] |
| | 168 | | public void SeEntityLimitsLeftTextCorrectly() |
| | 169 | | { |
| | 170 | | // Arrange |
| 1 | 171 | | string newText = "Test text"; |
| 1 | 172 | | string newText2 = "Test text2"; |
| 1 | 173 | | string newText3 = "Test text3"; |
| 1 | 174 | | entityInformationView.entityLimitsTrisTxt.text = ""; |
| 1 | 175 | | entityInformationView.entityLimitsMaterialsTxt.text = ""; |
| 1 | 176 | | entityInformationView.entityLimitsTextureTxt.text = ""; |
| | 177 | |
|
| | 178 | | // Act |
| 1 | 179 | | entityInformationView.SeEntityLimitsText(newText, newText2 , newText3); |
| | 180 | |
|
| | 181 | | // Assert |
| 1 | 182 | | Assert.AreEqual(newText, entityInformationView.entityLimitsTrisTxt.text, "The left limits text does not matc |
| 1 | 183 | | Assert.AreEqual(newText2, entityInformationView.entityLimitsMaterialsTxt.text, "The left limits text does no |
| 1 | 184 | | Assert.AreEqual(newText3, entityInformationView.entityLimitsTextureTxt.text, "The left limits text does not |
| 1 | 185 | | } |
| | 186 | |
|
| | 187 | | [Test] |
| | 188 | | [TestCase(true)] |
| | 189 | | [TestCase(false)] |
| | 190 | | public void SetSmartItemListViewActiveCorrectly(bool isActive) |
| | 191 | | { |
| | 192 | | // Arrange |
| 2 | 193 | | entityInformationView.smartItemListView.gameObject.SetActive(!isActive); |
| | 194 | |
|
| | 195 | | // Act |
| 2 | 196 | | entityInformationView.SetSmartItemListViewActive(isActive); |
| | 197 | |
|
| | 198 | | // Assert |
| 2 | 199 | | Assert.AreEqual(isActive, entityInformationView.smartItemListView.gameObject.activeSelf, "The smartItemList |
| 2 | 200 | | } |
| | 201 | |
|
| | 202 | | [Test] |
| | 203 | | public void SetNameIFTextCorrectly() |
| | 204 | | { |
| | 205 | | // Arrange |
| 1 | 206 | | string newText = "Test text"; |
| 1 | 207 | | entityInformationView.nameIF.text = ""; |
| | 208 | |
|
| | 209 | | // Act |
| 1 | 210 | | entityInformationView.SetNameIFText(newText); |
| | 211 | |
|
| | 212 | | // Assert |
| 1 | 213 | | Assert.AreEqual(newText, entityInformationView.nameIF.text, "The nameIF text does not match!"); |
| 1 | 214 | | } |
| | 215 | |
|
| | 216 | | [Test] |
| | 217 | | [TestCase(true)] |
| | 218 | | [TestCase(false)] |
| | 219 | | public void SetActiveCorrectly(bool isActive) |
| | 220 | | { |
| | 221 | | // Arrange |
| 2 | 222 | | entityInformationView.gameObject.SetActive(!isActive); |
| | 223 | |
|
| | 224 | | // Act |
| 2 | 225 | | entityInformationView.SetActive(isActive); |
| | 226 | |
|
| | 227 | | // Assert |
| 2 | 228 | | Assert.AreEqual(isActive, entityInformationView.gameObject.activeSelf, "The active property does not match!" |
| 2 | 229 | | } |
| | 230 | |
|
| | 231 | | [Test] |
| | 232 | | [TestCase(1)] |
| | 233 | | [TestCase(5)] |
| | 234 | | public void UpdateEntitiesSelectionCorrectly(int numberOfSelectedEntities) |
| | 235 | | { |
| | 236 | | // Arrange |
| 2 | 237 | | if (numberOfSelectedEntities > 1) |
| | 238 | | { |
| 1 | 239 | | entityInformationView.individualEntityPanel.SetActive(true); |
| 1 | 240 | | entityInformationView.multipleEntitiesPanel.SetActive(false); |
| 1 | 241 | | entityInformationView.multipleEntitiesText.text = ""; |
| 1 | 242 | | } |
| | 243 | | else |
| | 244 | | { |
| 1 | 245 | | entityInformationView.individualEntityPanel.SetActive(false); |
| 1 | 246 | | entityInformationView.multipleEntitiesPanel.SetActive(true); |
| | 247 | | } |
| | 248 | |
|
| | 249 | | // Act |
| 2 | 250 | | entityInformationView.UpdateEntitiesSelection(numberOfSelectedEntities); |
| | 251 | |
|
| | 252 | | // Assert |
| 2 | 253 | | if (numberOfSelectedEntities > 1) |
| | 254 | | { |
| 1 | 255 | | Assert.IsFalse(entityInformationView.individualEntityPanel.activeInHierarchy, "The active property does |
| 1 | 256 | | Assert.IsTrue(entityInformationView.multipleEntitiesPanel.activeInHierarchy, "The active property does n |
| 1 | 257 | | Assert.IsNotEmpty(entityInformationView.multipleEntitiesText.text, "The multipleEntitiesText text is emp |
| 1 | 258 | | } |
| | 259 | | else |
| | 260 | | { |
| 1 | 261 | | Assert.IsTrue(entityInformationView.individualEntityPanel.activeInHierarchy, "The active property does n |
| 1 | 262 | | Assert.IsFalse(entityInformationView.multipleEntitiesPanel.activeInHierarchy, "The active property does |
| | 263 | | } |
| 1 | 264 | | } |
| | 265 | |
|
| | 266 | | [Test] |
| | 267 | | [TestCase(0.5f, true)] |
| | 268 | | [TestCase(0.5f, false)] |
| | 269 | | public void SetTransparencyModeCorrectly(float alphaValue, bool interactable = true) |
| | 270 | | { |
| | 271 | | // Arrange |
| 2 | 272 | | entityInformationView.canvasGroup.alpha = 1f; |
| 2 | 273 | | entityInformationView.canvasGroup.blocksRaycasts = !interactable; |
| 2 | 274 | | entityInformationView.canvasGroup.interactable = !interactable; |
| | 275 | |
|
| | 276 | | // Act |
| 2 | 277 | | entityInformationView.SetTransparencyMode(alphaValue, interactable); |
| | 278 | |
|
| | 279 | | // Assert |
| 2 | 280 | | Assert.AreEqual(alphaValue, entityInformationView.canvasGroup.alpha); |
| 2 | 281 | | Assert.AreEqual(interactable, entityInformationView.canvasGroup.blocksRaycasts); |
| 2 | 282 | | Assert.AreEqual(interactable, entityInformationView.canvasGroup.interactable); |
| 2 | 283 | | } |
| | 284 | | } |
| | 285 | | } |