< Summary

Class:BIWFloorHandlerShould
Assembly:BuilderInWorldTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Tests/BIWFloorHandlerShould.cs
Covered lines:55
Uncovered lines:1
Coverable lines:56
Total lines:120
Line coverage:98.2% (55 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
CreateFloor()0%77096.15%
ChangeFloor()0%330100%
TearDown()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Tests/BIWFloorHandlerShould.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL;
 5using DCL.Components;
 6using DCL.Helpers;
 7using DCL.Models;
 8using NUnit.Framework;
 9using UnityEngine;
 10using UnityEngine.TestTools;
 11
 12public 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    {
 221        yield return base.SetUp();
 222        controller = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0];
 23
 224        biwCreatorController = controller.biwCreatorController;
 225        biwCreatorController.Init();
 226        biwFloorHandler = controller.biwFloorHandler;
 227        biwFloorHandler.Init();
 228        entityHandler = controller.builderInWorldEntityHandler;
 229        entityHandler.Init();
 230        entityHandler.EnterEditMode(scene);
 31
 232        biwFloorHandler.dclBuilderMeshLoadIndicatorController.Init();
 233    }
 34
 35    [Test]
 36    public void CreateFloor()
 37    {
 38        //Arrange
 139        BIWCatalogManager.Init();
 140        BuilderInWorldTestHelper.CreateTestCatalogLocalMultipleFloorObjects();
 141        CatalogItem floorItem = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 42
 143        controller.InitGameObjects();
 144        controller.FindSceneToEdit();
 145        controller.InitControllers();
 46
 147        biwCreatorController.EnterEditMode(scene);
 148        biwFloorHandler.EnterEditMode(scene);
 49
 50        //Act
 151        biwFloorHandler.CreateFloor(floorItem);
 52
 53        //Assert
 354        foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
 55        {
 156            if (entity.isFloor)
 57            {
 158                Assert.IsTrue(biwFloorHandler.ExistsFloorPlaceHolderForEntity(entity.rootEntity.entityId));
 159                Assert.AreEqual(entity.GetCatalogItemAssociated().id, floorItem.id);
 160                break;
 61            }
 62        }
 63
 364        foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
 65        {
 166            if (entity.isFloor)
 67            {
 168                if (!entity.rootEntity.TryGetSharedComponent(CLASS_ID.GLTF_SHAPE, out ISharedComponent component))
 069                    Assert.Fail("Floor doesn't contains a GLTFShape!");
 70
 171                entity.rootEntity.OnShapeUpdated?.Invoke(entity.rootEntity);
 172                Assert.IsFalse(biwFloorHandler.ExistsFloorPlaceHolderForEntity(entity.rootEntity.entityId));
 173                break;
 74            }
 75        }
 176    }
 77
 78    [Test]
 79    public void ChangeFloor()
 80    {
 81        //Arrange
 182        BIWCatalogManager.Init();
 83
 184        BuilderInWorldTestHelper.CreateTestCatalogLocalMultipleFloorObjects();
 85
 186        CatalogItem oldFloor = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];
 187        CatalogItem newFloor = DataStore.i.builderInWorld.catalogItemDict.GetValues()[1];
 88
 189        controller.InitGameObjects();
 190        controller.FindSceneToEdit();
 191        controller.InitControllers();
 92
 193        biwCreatorController.EnterEditMode(scene);
 194        biwFloorHandler.EnterEditMode(scene);
 95
 96        //Act
 197        biwFloorHandler.CreateFloor(oldFloor);
 198        biwFloorHandler.ChangeFloor(newFloor);
 99
 100        //Assert
 3101        foreach (DCLBuilderInWorldEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
 102        {
 1103            if (entity.isFloor)
 104            {
 1105                Assert.AreEqual(entity.GetCatalogItemAssociated().id, newFloor.id);
 1106                Assert.AreEqual(biwFloorHandler.FindCurrentFloorCatalogItem().id, newFloor.id);
 1107                break;
 108            }
 109        }
 1110    }
 111
 112    protected override IEnumerator TearDown()
 113    {
 2114        BIWCatalogManager.ClearCatalog();
 2115        BuilderInWorldNFTController.i.ClearNFTs();
 2116        controller.CleanItems();
 2117        controller.gameObject.SetActive(false);
 2118        yield return base.TearDown();
 2119    }
 120}