| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.TestTools; |
| | 9 | |
|
| | 10 | | public class BIWCatalogShould |
| | 11 | | { |
| | 12 | | private GameObject gameObjectToUse; |
| | 13 | |
|
| | 14 | | [UnitySetUp] |
| | 15 | | protected IEnumerator SetUp() |
| | 16 | | { |
| 5 | 17 | | BIWCatalogManager.Init(); |
| 5 | 18 | | gameObjectToUse = new GameObject("_TestObject"); |
| 5 | 19 | | gameObjectToUse.AddComponent<AssetCatalogBridge>(); |
| 5 | 20 | | yield return null; |
| 5 | 21 | | } |
| | 22 | |
|
| | 23 | | [Test] |
| | 24 | | public void BuilderInWorldSearch() |
| | 25 | | { |
| 1 | 26 | | string nameToFilter = "Sandy"; |
| 1 | 27 | | BuilderInWorldTestHelper.CreateTestCatalogLocalMultipleFloorObjects(); |
| | 28 | |
|
| 1 | 29 | | CatalogItem catalogItemToFilter = null; |
| 3 | 30 | | foreach (CatalogItem catalogItem in DataStore.i.builderInWorld.catalogItemDict.GetValues()) |
| | 31 | | { |
| 1 | 32 | | if (catalogItem.name.Contains(nameToFilter)) |
| | 33 | | { |
| 1 | 34 | | catalogItemToFilter = catalogItem; |
| 1 | 35 | | return; |
| | 36 | | } |
| | 37 | | } |
| | 38 | |
|
| 0 | 39 | | SceneCatalogController sceneCatalogController = new SceneCatalogController(); |
| 0 | 40 | | List<Dictionary<string, List<CatalogItem>>> result = sceneCatalogController.biwSearchBarController.FilterAssets |
| | 41 | |
|
| 0 | 42 | | CatalogItem filteredItem = result[0].Values.ToList()[0][0]; |
| | 43 | |
|
| 0 | 44 | | Assert.AreEqual(filteredItem, catalogItemToFilter); |
| 1 | 45 | | } |
| | 46 | |
|
| | 47 | | [Test] |
| | 48 | | public void BuilderInWorldQuickBar() |
| | 49 | | { |
| 1 | 50 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| 1 | 51 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 52 | |
|
| 1 | 53 | | CatalogItemAdapter adapter = BuilderInWorldTestHelper.CreateCatalogItemAdapter(gameObjectToUse); |
| 1 | 54 | | adapter.SetContent(item); |
| | 55 | |
|
| 1 | 56 | | CatalogAssetGroupAdapter groupAdapter = new GameObject("_CatalogAssetGroupAdapter").AddComponent<CatalogAssetGro |
| 1 | 57 | | groupAdapter.SubscribeToEvents(adapter); |
| | 58 | |
|
| 1 | 59 | | CatalogGroupListView catalogGroupListView = new GameObject("_CatalogGroupListView").AddComponent<CatalogGroupLis |
| 1 | 60 | | catalogGroupListView.SubscribeToEvents(groupAdapter); |
| 1 | 61 | | catalogGroupListView.generalCanvas = Utils.GetOrCreateComponent<Canvas>(gameObjectToUse); |
| 1 | 62 | | SceneCatalogView sceneCatalogView = SceneCatalogView.Create(); |
| 1 | 63 | | sceneCatalogView.catalogGroupListView = catalogGroupListView; |
| 1 | 64 | | SceneCatalogController sceneCatalogController = new SceneCatalogController(); |
| | 65 | |
|
| 1 | 66 | | QuickBarView quickBarView = QuickBarView.Create(); |
| | 67 | |
|
| 1 | 68 | | QuickBarController quickBarController = new QuickBarController(); |
| 1 | 69 | | sceneCatalogController.Initialize(sceneCatalogView, quickBarController); |
| 1 | 70 | | quickBarController.Initialize(quickBarView, sceneCatalogController); |
| 1 | 71 | | int slots = quickBarController.GetSlotsCount(); |
| 1 | 72 | | quickBarView.shortcutsImgs = new QuickBarSlot[slots]; |
| | 73 | |
|
| 20 | 74 | | for (int i = 0; i < slots; i++) |
| | 75 | | { |
| 9 | 76 | | quickBarController.SetIndexToDrop(i); |
| 9 | 77 | | adapter.AdapterStartDragging(null); |
| 9 | 78 | | quickBarController.SetQuickBarShortcut(item, i, new Texture2D(10, 10)); |
| 9 | 79 | | Assert.AreEqual(item, quickBarController.QuickBarObjectSelected(i)); |
| | 80 | | } |
| 1 | 81 | | } |
| | 82 | |
|
| | 83 | | [Test] |
| | 84 | | public void BuilderInWorldToggleFavorite() |
| | 85 | | { |
| 1 | 86 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 87 | |
|
| 1 | 88 | | CatalogItem item = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 89 | |
|
| 1 | 90 | | FavoritesController favoritesController = new FavoritesController(new GameObject("_FavoritesController").AddComp |
| 1 | 91 | | favoritesController.ToggleFavoriteState(item, null); |
| 1 | 92 | | Assert.IsTrue(item.IsFavorite()); |
| | 93 | |
|
| 1 | 94 | | favoritesController.ToggleFavoriteState(item, null); |
| 1 | 95 | | Assert.IsFalse(item.IsFavorite()); |
| 1 | 96 | | } |
| | 97 | |
|
| | 98 | | [Test] |
| | 99 | | public void CatalogItemsSceneObject() |
| | 100 | | { |
| 1 | 101 | | BuilderInWorldTestHelper.CreateTestCatalogLocalSingleObject(); |
| | 102 | |
|
| 1 | 103 | | Assert.AreEqual(DataStore.i.builderInWorld.catalogItemDict.Count(), 1); |
| 1 | 104 | | Assert.AreEqual(DataStore.i.builderInWorld.catalogItemPackDict.Count(), 1); |
| 1 | 105 | | Assert.AreEqual(BIWCatalogManager.GetCatalogItemPacksFilteredByCategories().Count, 1); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [Test] |
| | 109 | | public void CatalogItemsNfts() |
| | 110 | | { |
| 1 | 111 | | BuilderInWorldTestHelper.CreateNFT(); |
| | 112 | |
|
| 1 | 113 | | Assert.AreEqual(DataStore.i.builderInWorld.catalogItemDict.Count(), 1); |
| 1 | 114 | | Assert.AreEqual(DataStore.i.builderInWorld.catalogItemPackDict.Count(), 1); |
| 1 | 115 | | Assert.AreEqual(BIWCatalogManager.GetCatalogItemPacksFilteredByCategories().Count, 1); |
| 1 | 116 | | } |
| | 117 | |
|
| | 118 | | [UnityTearDown] |
| | 119 | | protected IEnumerator TearDown() |
| | 120 | | { |
| 5 | 121 | | AssetCatalogBridge.i.ClearCatalog(); |
| 5 | 122 | | BIWCatalogManager.ClearCatalog(); |
| 5 | 123 | | BIWCatalogManager.Dispose(); |
| 5 | 124 | | if (gameObjectToUse != null) |
| 5 | 125 | | GameObject.Destroy(gameObjectToUse); |
| 5 | 126 | | yield return null; |
| 5 | 127 | | } |
| | 128 | | } |