| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL; |
| | 5 | | using DCL.Components; |
| | 6 | | using DCL.Helpers; |
| | 7 | | using DCL.Models; |
| | 8 | | using NUnit.Framework; |
| | 9 | | using UnityEngine; |
| | 10 | | using UnityEngine.TestTools; |
| | 11 | |
|
| | 12 | | public class BIWFloorHandlerShould : IntegrationTestSuite_Legacy |
| | 13 | | { |
| | 14 | | private BuilderInWorldEntityHandler entityHandler; |
| | 15 | | private BuilderInWorldController controller; |
| | 16 | | private BIWFloorHandler biwFloorHandler; |
| | 17 | | private BIWCreatorController biwCreatorController; |
| | 18 | |
|
| | 19 | | protected override IEnumerator SetUp() |
| | 20 | | { |
| 2 | 21 | | yield return base.SetUp(); |
| 2 | 22 | | controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0]; |
| | 23 | |
|
| 2 | 24 | | biwCreatorController = controller.biwCreatorController; |
| 2 | 25 | | biwCreatorController.Init(); |
| 2 | 26 | | biwFloorHandler = controller.biwFloorHandler; |
| 2 | 27 | | biwFloorHandler.Init(); |
| 2 | 28 | | entityHandler = controller.builderInWorldEntityHandler; |
| 2 | 29 | | entityHandler.Init(); |
| 2 | 30 | | entityHandler.EnterEditMode(scene); |
| | 31 | |
|
| 2 | 32 | | biwFloorHandler.dclBuilderMeshLoadIndicatorController.Init(); |
| 2 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void CreateFloor() |
| | 37 | | { |
| | 38 | | //Arrange |
| 1 | 39 | | BIWCatalogManager.Init(); |
| 1 | 40 | | BuilderInWorldTestHelper.CreateTestCatalogLocalMultipleFloorObjects(); |
| 1 | 41 | | CatalogItem floorItem = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 42 | |
|
| 1 | 43 | | controller.InitGameObjects(); |
| 1 | 44 | | controller.FindSceneToEdit(); |
| 1 | 45 | | controller.InitControllers(); |
| | 46 | |
|
| 1 | 47 | | biwCreatorController.EnterEditMode(scene); |
| 1 | 48 | | biwFloorHandler.EnterEditMode(scene); |
| | 49 | |
|
| | 50 | | //Act |
| 1 | 51 | | biwFloorHandler.CreateFloor(floorItem); |
| | 52 | |
|
| | 53 | | //Assert |
| 3 | 54 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 55 | | { |
| 1 | 56 | | if (entity.isFloor) |
| | 57 | | { |
| 1 | 58 | | Assert.IsTrue(biwFloorHandler.ExistsFloorPlaceHolderForEntity(entity.rootEntity.entityId)); |
| 1 | 59 | | Assert.AreEqual(entity.GetCatalogItemAssociated().id, floorItem.id); |
| 1 | 60 | | break; |
| | 61 | | } |
| | 62 | | } |
| | 63 | |
|
| 3 | 64 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 65 | | { |
| 1 | 66 | | if (entity.isFloor) |
| | 67 | | { |
| 1 | 68 | | if (!entity.rootEntity.TryGetSharedComponent(CLASS_ID.GLTF_SHAPE, out ISharedComponent component)) |
| 0 | 69 | | Assert.Fail("Floor doesn't contains a GLTFShape!"); |
| | 70 | |
|
| 1 | 71 | | entity.rootEntity.OnShapeUpdated?.Invoke(entity.rootEntity); |
| 1 | 72 | | Assert.IsFalse(biwFloorHandler.ExistsFloorPlaceHolderForEntity(entity.rootEntity.entityId)); |
| 1 | 73 | | break; |
| | 74 | | } |
| | 75 | | } |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | [Test] |
| | 79 | | public void ChangeFloor() |
| | 80 | | { |
| | 81 | | //Arrange |
| 1 | 82 | | BIWCatalogManager.Init(); |
| | 83 | |
|
| 1 | 84 | | BuilderInWorldTestHelper.CreateTestCatalogLocalMultipleFloorObjects(); |
| | 85 | |
|
| 1 | 86 | | CatalogItem oldFloor = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| 1 | 87 | | CatalogItem newFloor = DataStore.i.builderInWorld.catalogItemDict.GetValues()[1]; |
| | 88 | |
|
| 1 | 89 | | controller.InitGameObjects(); |
| 1 | 90 | | controller.FindSceneToEdit(); |
| 1 | 91 | | controller.InitControllers(); |
| | 92 | |
|
| 1 | 93 | | biwCreatorController.EnterEditMode(scene); |
| 1 | 94 | | biwFloorHandler.EnterEditMode(scene); |
| | 95 | |
|
| | 96 | | //Act |
| 1 | 97 | | biwFloorHandler.CreateFloor(oldFloor); |
| 1 | 98 | | biwFloorHandler.ChangeFloor(newFloor); |
| | 99 | |
|
| | 100 | | //Assert |
| 3 | 101 | | foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene()) |
| | 102 | | { |
| 1 | 103 | | if (entity.isFloor) |
| | 104 | | { |
| 1 | 105 | | Assert.AreEqual(entity.GetCatalogItemAssociated().id, newFloor.id); |
| 1 | 106 | | Assert.AreEqual(biwFloorHandler.FindCurrentFloorCatalogItem().id, newFloor.id); |
| 1 | 107 | | break; |
| | 108 | | } |
| | 109 | | } |
| 1 | 110 | | } |
| | 111 | |
|
| | 112 | | protected override IEnumerator TearDown() |
| | 113 | | { |
| 2 | 114 | | BIWCatalogManager.ClearCatalog(); |
| 2 | 115 | | BuilderInWorldNFTController.i.ClearNFTs(); |
| 2 | 116 | | controller.CleanItems(); |
| 2 | 117 | | controller.gameObject.SetActive(false); |
| 2 | 118 | | yield return base.TearDown(); |
| 2 | 119 | | } |
| | 120 | | } |