| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using NSubstitute; |
| | 6 | | using NUnit.Framework; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace Tests.BuildModeHUDControllers |
| | 10 | | { |
| | 11 | | public class EntityInformationControllerShould |
| | 12 | | { |
| | 13 | | private EntityInformationController entityInformationController; |
| | 14 | |
|
| | 15 | | [SetUp] |
| | 16 | | public void SetUp() |
| | 17 | | { |
| 21 | 18 | | entityInformationController = new EntityInformationController(); |
| 21 | 19 | | entityInformationController.Initialize(Substitute.For<IEntityInformationView>()); |
| 21 | 20 | | Environment.i.platform.webRequest.Initialize( |
| | 21 | | genericWebRequest: new WebRequest(), |
| | 22 | | assetBundleWebRequest: new WebRequestAssetBundle(), |
| | 23 | | textureWebRequest: new WebRequestTexture(), |
| | 24 | | audioWebRequest: new WebRequestAudio()); |
| 21 | 25 | | } |
| | 26 | |
|
| | 27 | | [TearDown] |
| | 28 | | public void TearDown() |
| | 29 | | { |
| 21 | 30 | | entityInformationController.Dispose(); |
| 21 | 31 | | Environment.i.platform.webRequest.Dispose(); |
| 21 | 32 | | } |
| | 33 | |
|
| | 34 | | [Test] |
| | 35 | | public void PositionChangedCorrectly() |
| | 36 | | { |
| | 37 | | // Arrange |
| 1 | 38 | | Vector3 testPos = new Vector3(5, 7, 0); |
| 1 | 39 | | Vector3 returnedPos = Vector3.zero; |
| 3 | 40 | | entityInformationController.OnPositionChange += (pos) => { returnedPos = pos; }; |
| | 41 | |
|
| | 42 | | // Act |
| 1 | 43 | | entityInformationController.PositionChanged(testPos); |
| | 44 | |
|
| | 45 | | // Assert |
| 1 | 46 | | Assert.AreEqual(testPos, returnedPos, "The position does not match!"); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | [Test] |
| | 50 | | public void RotationChangedCorrectly() |
| | 51 | | { |
| | 52 | | // Arrange |
| 1 | 53 | | Vector3 testRot = new Vector3(5, 7, 0); |
| 1 | 54 | | Vector3 returnedRot = Vector3.zero; |
| 3 | 55 | | entityInformationController.OnRotationChange += (rot) => { returnedRot = rot; }; |
| | 56 | |
|
| | 57 | | // Act |
| 1 | 58 | | entityInformationController.RotationChanged(testRot); |
| | 59 | |
|
| | 60 | | // Assert |
| 1 | 61 | | Assert.AreEqual(testRot, returnedRot, "The rotation does not match!"); |
| 1 | 62 | | } |
| | 63 | |
|
| | 64 | | [Test] |
| | 65 | | public void ScaleChangedCorrectly() |
| | 66 | | { |
| | 67 | | // Arrange |
| 1 | 68 | | Vector3 testScale = new Vector3(5, 7, 0); |
| 1 | 69 | | Vector3 returnedScale = Vector3.zero; |
| 3 | 70 | | entityInformationController.OnScaleChange += (scale) => { returnedScale = scale; }; |
| | 71 | |
|
| | 72 | | // Act |
| 1 | 73 | | entityInformationController.ScaleChanged(testScale); |
| | 74 | |
|
| | 75 | | // Assert |
| 1 | 76 | | Assert.AreEqual(testScale, returnedScale, "The scale does not match!"); |
| 1 | 77 | | } |
| | 78 | |
|
| | 79 | | [Test] |
| | 80 | | public void NameChangedCorrectly() |
| | 81 | | { |
| | 82 | | // Arrange |
| 1 | 83 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 84 | | string testText = "Test text"; |
| 1 | 85 | | DCLBuilderInWorldEntity returnedEntity = null; |
| 1 | 86 | | string returnedText = ""; |
| 1 | 87 | | entityInformationController.OnNameChange += (entity, name) => |
| | 88 | | { |
| 1 | 89 | | returnedEntity = entity; |
| 1 | 90 | | returnedText = name; |
| 1 | 91 | | }; |
| | 92 | |
|
| | 93 | | // Act |
| 1 | 94 | | entityInformationController.NameChanged(testEntity, testText); |
| | 95 | |
|
| | 96 | | // Assert |
| 1 | 97 | | Assert.AreEqual(testEntity, returnedEntity, "The entity does not match!"); |
| 1 | 98 | | Assert.AreEqual(testText, returnedText, "The text does not match!"); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | [Test] |
| | 102 | | public void ToggleDetailsInfoCorrectly() |
| | 103 | | { |
| | 104 | | // Act |
| 1 | 105 | | entityInformationController.ToggleDetailsInfo(); |
| | 106 | |
|
| | 107 | | // Assert |
| 1 | 108 | | entityInformationController.entityInformationView.Received(1).ToggleDetailsInfo(); |
| 1 | 109 | | } |
| | 110 | |
|
| | 111 | | [Test] |
| | 112 | | public void ToggleBasicInfoCorrectly() |
| | 113 | | { |
| | 114 | | // Act |
| 1 | 115 | | entityInformationController.ToggleBasicInfo(); |
| | 116 | |
|
| | 117 | | // Assert |
| 1 | 118 | | entityInformationController.entityInformationView.Received(1).ToggleBasicInfo(); |
| 1 | 119 | | } |
| | 120 | |
|
| | 121 | | [Test] |
| | 122 | | public void StartChangingNameCorrectly() |
| | 123 | | { |
| | 124 | | // Arrange |
| 1 | 125 | | entityInformationController.isChangingName = false; |
| | 126 | |
|
| | 127 | | // Act |
| 1 | 128 | | entityInformationController.StartChangingName(); |
| | 129 | |
|
| | 130 | | // Assert |
| 1 | 131 | | Assert.IsTrue(entityInformationController.isChangingName, "isChangingName is false!"); |
| 1 | 132 | | } |
| | 133 | |
|
| | 134 | | [Test] |
| | 135 | | public void EndChangingNameCorrectly() |
| | 136 | | { |
| | 137 | | // Arrange |
| 1 | 138 | | entityInformationController.isChangingName = true; |
| | 139 | |
|
| | 140 | | // Act |
| 1 | 141 | | entityInformationController.EndChangingName(); |
| | 142 | |
|
| | 143 | | // Assert |
| 1 | 144 | | Assert.IsFalse(entityInformationController.isChangingName, "isChangingName is true!"); |
| 1 | 145 | | } |
| | 146 | |
|
| | 147 | | [Test] |
| | 148 | | public void SetEntityCorrectly() |
| | 149 | | { |
| | 150 | | // Arrange |
| 1 | 151 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 152 | | ParcelScene testScene = new GameObject("_ParcelScene").AddComponent<ParcelScene>(); |
| | 153 | |
|
| | 154 | | // Act |
| 1 | 155 | | entityInformationController.SetEntity(testEntity, testScene); |
| | 156 | |
|
| | 157 | | // Assert |
| 1 | 158 | | entityInformationController.entityInformationView.Received(1).SetCurrentEntity(testEntity); |
| 1 | 159 | | Assert.AreEqual(testScene, entityInformationController.parcelScene, "The parcel scene does not match!"); |
| 1 | 160 | | entityInformationController.entityInformationView.Received(1).SetEntityThumbnailEnable(false); |
| 1 | 161 | | } |
| | 162 | |
|
| | 163 | | [Test] |
| | 164 | | public void GetThumbnailCorrectly() |
| | 165 | | { |
| | 166 | | // Arrange |
| 1 | 167 | | CatalogItem testCatalogItem = new CatalogItem(); |
| 1 | 168 | | testCatalogItem.thumbnailURL = "test url"; |
| 1 | 169 | | entityInformationController.loadedThumbnailPromise = null; |
| | 170 | |
|
| | 171 | | // Act |
| 1 | 172 | | entityInformationController.GetThumbnail(testCatalogItem); |
| | 173 | |
|
| | 174 | | // Assert |
| 1 | 175 | | Assert.IsNotNull(entityInformationController.loadedThumbnailPromise, "loadedThumbnailPromise is null!"); |
| 1 | 176 | | } |
| | 177 | |
|
| | 178 | | [Test] |
| | 179 | | public void SetThumbnailCorrectly() |
| | 180 | | { |
| | 181 | | // Arrange |
| 1 | 182 | | Asset_Texture testTexture = new Asset_Texture(); |
| 1 | 183 | | testTexture.texture = new Texture2D(20, 20); |
| | 184 | |
|
| | 185 | | // Act |
| 1 | 186 | | entityInformationController.SetThumbnail(testTexture); |
| | 187 | |
|
| | 188 | | // Assert |
| 1 | 189 | | entityInformationController.entityInformationView.Received(1).SetEntityThumbnailEnable(true); |
| 1 | 190 | | entityInformationController.entityInformationView.Received(1).SetEntityThumbnailTexture(testTexture.texture) |
| 1 | 191 | | } |
| | 192 | |
|
| | 193 | | [Test] |
| | 194 | | public void UpdateEntityNameCorrectly() |
| | 195 | | { |
| | 196 | | // Arrange |
| 1 | 197 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| 1 | 198 | | entityInformationController.isChangingName = false; |
| | 199 | |
|
| | 200 | | // Act |
| 1 | 201 | | entityInformationController.UpdateEntityName(testEntity); |
| | 202 | |
|
| | 203 | | // Assert |
| 1 | 204 | | entityInformationController.entityInformationView.Received(1).SetNameIFText(Arg.Any<string>()); |
| 1 | 205 | | } |
| | 206 | |
|
| | 207 | | [Test] |
| | 208 | | [TestCase(true)] |
| | 209 | | [TestCase(false)] |
| | 210 | | public void UpdateLimitsInformationCorrectly(bool isCatalogNull) |
| | 211 | | { |
| | 212 | | // Arrange |
| 2 | 213 | | CatalogItem testCatalogItem = null; |
| 2 | 214 | | if (!isCatalogNull) |
| | 215 | | { |
| 1 | 216 | | testCatalogItem = new CatalogItem(); |
| 1 | 217 | | testCatalogItem.metrics = new SceneObject.ObjectMetrics |
| | 218 | | { |
| | 219 | | entities = 5, |
| | 220 | | bodies = 3, |
| | 221 | | triangles = 10, |
| | 222 | | textures = 2, |
| | 223 | | materials = 2, |
| | 224 | | meshes = 6 |
| | 225 | | }; |
| | 226 | | } |
| | 227 | |
|
| | 228 | | // Act |
| 2 | 229 | | entityInformationController.UpdateLimitsInformation(testCatalogItem); |
| | 230 | |
|
| | 231 | | // Assert |
| 2 | 232 | | entityInformationController.entityInformationView.Received(1).SeEntityLimitsText(isCatalogNull ? "" : Arg.An |
| 2 | 233 | | } |
| | 234 | |
|
| | 235 | | [Test] |
| | 236 | | public void SetEnableCorrectly() |
| | 237 | | { |
| | 238 | | // Arrange |
| 1 | 239 | | entityInformationController.entityInformationView.SetActive(false); |
| | 240 | |
|
| | 241 | | // Act |
| 1 | 242 | | entityInformationController.Enable(); |
| | 243 | |
|
| | 244 | | // Assert |
| 1 | 245 | | entityInformationController.entityInformationView.Received(1).SetActive(true); |
| 1 | 246 | | } |
| | 247 | |
|
| | 248 | | [Test] |
| | 249 | | public void SetDisableCorrectly() |
| | 250 | | { |
| | 251 | | // Arrange |
| 1 | 252 | | bool hidden = false; |
| 1 | 253 | | entityInformationController.entityInformationView.SetActive(true); |
| | 254 | |
|
| 1 | 255 | | entityInformationController.OnDisable += () => |
| | 256 | | { |
| 1 | 257 | | hidden = true; |
| 1 | 258 | | }; |
| | 259 | |
|
| | 260 | | // Act |
| 1 | 261 | | entityInformationController.Disable(); |
| | 262 | |
|
| | 263 | | // Assert |
| 1 | 264 | | entityInformationController.entityInformationView.Received(1).SetActive(false); |
| 1 | 265 | | entityInformationController.entityInformationView.Received(1).SetCurrentEntity(null); |
| 1 | 266 | | Assert.IsTrue(hidden); |
| 1 | 267 | | } |
| | 268 | |
|
| | 269 | | [Test] |
| | 270 | | public void UpdateInfoCorrectly() |
| | 271 | | { |
| | 272 | | // Arrange |
| 1 | 273 | | DCLBuilderInWorldEntity testEntity = new GameObject("_DCLBuilderInWorldEntity").AddComponent<DCLBuilderInWor |
| | 274 | |
|
| | 275 | | // Act |
| 1 | 276 | | entityInformationController.UpdateInfo(testEntity); |
| | 277 | |
|
| | 278 | | // Assert |
| 1 | 279 | | entityInformationController.entityInformationView.Received(1).SetPositionAttribute(Arg.Any<Vector3>()); |
| 1 | 280 | | entityInformationController.entityInformationView.Received(1).SetRotationAttribute(Arg.Any<Vector3>()); |
| 1 | 281 | | entityInformationController.entityInformationView.Received(1).SetScaleAttribute(Arg.Any<Vector3>()); |
| 1 | 282 | | } |
| | 283 | |
|
| | 284 | | [Test] |
| | 285 | | [TestCase(1)] |
| | 286 | | [TestCase(5)] |
| | 287 | | public void UpdateEntitiesSelectionCorrectly(int numberOfSelectedEntities) |
| | 288 | | { |
| | 289 | | // Act |
| 2 | 290 | | entityInformationController.UpdateEntitiesSelection(numberOfSelectedEntities); |
| | 291 | |
|
| | 292 | | // Assert |
| 2 | 293 | | entityInformationController.entityInformationView.Received(1).UpdateEntitiesSelection(numberOfSelectedEntiti |
| 2 | 294 | | } |
| | 295 | |
|
| | 296 | | [Test] |
| | 297 | | [TestCase(true)] |
| | 298 | | [TestCase(false)] |
| | 299 | | public void SetTransparencyModeCorrectly(bool isOn) |
| | 300 | | { |
| | 301 | | // Act |
| 2 | 302 | | entityInformationController.SetTransparencyMode(isOn); |
| | 303 | |
|
| | 304 | | // Assert |
| 2 | 305 | | entityInformationController.entityInformationView.Received(1).SetTransparencyMode(Arg.Any<float>(), !isOn); |
| 2 | 306 | | } |
| | 307 | | } |
| | 308 | | } |