< Summary

Class:AvatarEditorHUD_Tests.AvatarEditorHUDViewShould
Assembly:AvatarEditorHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Tests/AvatarEditorHUDViewShould.cs
Covered lines:80
Uncovered lines:0
Coverable lines:80
Total lines:283
Line coverage:100% (80 of 80)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%440100%
TearDown()0%330100%
Setup_AvatarEditorHUDController()0%110100%
Activate_CompatibleWithBodyShape_ItemToggle(...)0%110100%
NotCreate_IncompatibleWithBodyShape_ItemToggle(...)0%110100%
NotAdd_BaseWearables_ToCollectibles(...)0%110100%
Add_Exclusives_ToCollectibles(...)0%110100%
CreateNFTsButtonsByRarityCorrectly(...)0%110100%
FillNFTInfoPanelCorrectly()0%330100%
NotShowAmmountIfOnlyOneItemIsPossesed()0%110100%
ShowAndUpdateAmount(...)0%110100%
ShowAndUpdateAmountInCollectibleTab(...)0%110100%
CreateDummyNFT(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Tests/AvatarEditorHUDViewShould.cs

#LineLine coverage
 1using AvatarShape_Tests;
 2using NUnit.Framework;
 3using System.Collections;
 4using System.Collections.Generic;
 5using System.Linq;
 6using UnityEngine;
 7using UnityEngine.TestTools;
 8
 9namespace AvatarEditorHUD_Tests
 10{
 11    public class AvatarEditorHUDViewShould : IntegrationTestSuite_Legacy
 12    {
 13        private UserProfile userProfile;
 14        private AvatarEditorHUDController_Mock controller;
 15        private BaseDictionary<string, WearableItem> catalog;
 16
 2417        protected override bool justSceneSetUp => true;
 18
 19        [UnitySetUp]
 20        protected override IEnumerator SetUp()
 21        {
 2422            yield return base.SetUp();
 23
 2424            yield return base.SetUp_CharacterController();
 25
 2426            Setup_AvatarEditorHUDController();
 27
 2428            controller.UnequipAllWearables();
 2429            controller.SetVisibility(true);
 2430        }
 31
 32        protected override IEnumerator TearDown()
 33        {
 2434            controller.Dispose();
 2435            yield return base.TearDown();
 2436        }
 37
 38        private void Setup_AvatarEditorHUDController()
 39        {
 2440            userProfile = ScriptableObject.CreateInstance<UserProfile>();
 2441            userProfile.UpdateData(new UserProfileModel()
 42            {
 43                name = "name",
 44                email = "mail",
 45                avatar = new AvatarModel()
 46                {
 47                    bodyShape = WearableLiterals.BodyShapes.FEMALE,
 48                    wearables = new List<string>() { },
 49                }
 50            }, false);
 51
 2452            catalog = AvatarAssetsTestHelpers.CreateTestCatalogLocal();
 2453            controller = new AvatarEditorHUDController_Mock();
 2454            controller.Initialize(userProfile, catalog);
 2455        }
 56
 57        [Test]
 58        [TestCase("urn:decentraland:off-chain:base-avatars:f_african_leggins", WearableLiterals.BodyShapes.FEMALE)]
 59        [TestCase("urn:decentraland:off-chain:base-avatars:eyebrows_02", WearableLiterals.BodyShapes.MALE)]
 60        public void Activate_CompatibleWithBodyShape_ItemToggle(string wearableId, string bodyShape)
 61        {
 262            userProfile.UpdateData(new UserProfileModel()
 63            {
 64                name = "name",
 65                email = "mail",
 66                avatar = new AvatarModel()
 67                {
 68                    bodyShape = bodyShape,
 69                    wearables = new List<string>() { },
 70                }
 71            }, false);
 272            var category = catalog.Get(wearableId).data.category;
 73
 274            Assert.IsTrue(controller.myView.selectorsByCategory.ContainsKey(category));
 275            var selector = controller.myView.selectorsByCategory[category];
 76
 277            Assert.IsTrue(selector.itemToggles.ContainsKey(wearableId));
 278            var itemToggle = selector.itemToggles[wearableId];
 279            Assert.NotNull(itemToggle.wearableItem);
 80
 281            Assert.AreEqual(wearableId, itemToggle.wearableItem.id);
 282            Assert.IsTrue(itemToggle.gameObject.activeSelf);
 283        }
 84
 85        [Test]
 86        [TestCase("urn:decentraland:off-chain:base-avatars:f_african_leggins", WearableLiterals.BodyShapes.MALE)]
 87        [TestCase("urn:decentraland:off-chain:base-avatars:eyebrows_02", WearableLiterals.BodyShapes.FEMALE)]
 88        public void NotCreate_IncompatibleWithBodyShape_ItemToggle(string wearableId, string bodyShape)
 89        {
 290            userProfile.UpdateData(new UserProfileModel()
 91            {
 92                name = "name",
 93                email = "mail",
 94                avatar = new AvatarModel()
 95                {
 96                    bodyShape = bodyShape,
 97                    wearables = new List<string>() { },
 98                }
 99            }, false);
 100
 2101            var category = catalog.Get(wearableId).data.category;
 102
 2103            Assert.IsTrue(controller.myView.selectorsByCategory.ContainsKey(category));
 2104            var selector = controller.myView.selectorsByCategory[category];
 105
 2106            Assert.IsTrue(selector.itemToggles.ContainsKey(wearableId));
 2107            var itemToggle = selector.itemToggles[wearableId];
 2108            Assert.NotNull(itemToggle.wearableItem);
 109
 2110            Assert.AreEqual(wearableId, itemToggle.wearableItem.id);
 2111            Assert.IsFalse(itemToggle.gameObject.activeSelf);
 2112        }
 113
 114        [Test]
 115        [TestCase("urn:decentraland:off-chain:base-avatars:f_mouth_00")]
 116        [TestCase("urn:decentraland:off-chain:base-avatars:bee_t_shirt")]
 117        [TestCase("urn:decentraland:off-chain:base-avatars:m_mountainshoes.glb")]
 118        [TestCase("urn:decentraland:off-chain:base-avatars:moptop")]
 8119        public void NotAdd_BaseWearables_ToCollectibles(string wearableId) { Assert.IsFalse(controller.myView.collectibl
 120
 121        [Test]
 122        [TestCase("urn:decentraland:off-chain:halloween_2019:sad_clown_upper_body")]
 123        public void Add_Exclusives_ToCollectibles(string wearableId)
 124        {
 1125            userProfile.SetInventory(new[] { wearableId });
 1126            userProfile.UpdateData(new UserProfileModel()
 127            {
 128                name = "name",
 129                email = "mail",
 130                avatar = new AvatarModel()
 131                {
 132                    bodyShape = WearableLiterals.BodyShapes.FEMALE,
 133                    wearables = new List<string>() { },
 134                }
 135            }, false);
 136
 1137            Assert.IsTrue(controller.myView.collectiblesItemSelector.itemToggles.ContainsKey(wearableId));
 1138        }
 139
 140        [Test]
 141        [TestCase(WearableLiterals.ItemRarity.RARE)]
 142        [TestCase(WearableLiterals.ItemRarity.EPIC)]
 143        [TestCase(WearableLiterals.ItemRarity.LEGENDARY)]
 144        [TestCase(WearableLiterals.ItemRarity.MYTHIC)]
 145        [TestCase(WearableLiterals.ItemRarity.UNIQUE)]
 146        public void CreateNFTsButtonsByRarityCorrectly(string rarity)
 147        {
 5148            WearableItem dummyItem = CreateDummyNFT(rarity);
 149
 5150            var selector = controller.myView.selectorsByCategory[dummyItem.data.category];
 5151            var itemToggleObject = selector.itemToggles[dummyItem.id].gameObject;
 152
 5153            var originalName = selector.itemToggleFactory.nftDictionary[rarity].prefab.name;
 154
 5155            Assert.IsTrue(itemToggleObject.name.Contains(originalName)); //Comparing names because PrefabUtility.GetOute
 5156        }
 157
 158        [Test]
 159        public void FillNFTInfoPanelCorrectly()
 160        {
 1161            WearableItem dummyItem = CreateDummyNFT(WearableLiterals.ItemRarity.EPIC);
 162
 1163            var itemToggle = controller.myView.selectorsByCategory[dummyItem.data.category].itemToggles[dummyItem.id];
 1164            var nftInfo = (itemToggle as NFTItemToggle)?.nftItemInfo;
 165
 1166            Assert.NotNull(nftInfo);
 1167            Assert.AreEqual(dummyItem.GetName(), nftInfo.name.text);
 1168            Assert.AreEqual(dummyItem.description, nftInfo.description.text);
 1169            Assert.AreEqual($"{dummyItem.issuedId} / {dummyItem.GetIssuedCountFromRarity(dummyItem.rarity)}", nftInfo.mi
 1170        }
 171
 172        [Test]
 173        public void NotShowAmmountIfOnlyOneItemIsPossesed()
 174        {
 1175            var wearableId = "urn:decentraland:off-chain:halloween_2019:sad_clown_upper_body";
 1176            userProfile.SetInventory(new[] { wearableId });
 1177            userProfile.UpdateData(new UserProfileModel()
 178            {
 179                name = "name",
 180                email = "mail",
 181                avatar = new AvatarModel()
 182                {
 183                    bodyShape = WearableLiterals.BodyShapes.FEMALE,
 184                    wearables = new List<string>() { },
 185                }
 186            }, false);
 187
 1188            Assert.IsFalse(controller.myView.collectiblesItemSelector.itemToggles[wearableId].amountContainer.gameObject
 1189        }
 190
 191        [Test]
 192        [TestCase(2)]
 193        [TestCase(3)]
 194        [TestCase(5)]
 195        [TestCase(10)]
 196        public void ShowAndUpdateAmount(int amount)
 197        {
 4198            var wearableId = "urn:decentraland:off-chain:halloween_2019:sad_clown_upper_body";
 4199            userProfile.SetInventory(Enumerable.Repeat(wearableId, amount).ToArray());
 4200            userProfile.UpdateData(new UserProfileModel()
 201            {
 202                name = "name",
 203                email = "mail",
 204                avatar = new AvatarModel()
 205                {
 206                    bodyShape = WearableLiterals.BodyShapes.FEMALE,
 207                    wearables = new List<string>() { },
 208                }
 209            }, false);
 210
 4211            var itemToggle = controller.myView.selectorsByCategory[WearableLiterals.Categories.UPPER_BODY].itemToggles[w
 212
 4213            Assert.IsTrue(itemToggle.amountContainer.gameObject.activeSelf);
 4214            Assert.AreEqual($"x{amount}", itemToggle.amountText.text);
 4215        }
 216
 217        [Test]
 218        [TestCase(2)]
 219        [TestCase(3)]
 220        [TestCase(5)]
 221        [TestCase(10)]
 222        public void ShowAndUpdateAmountInCollectibleTab(int amount)
 223        {
 4224            var wearableId = "urn:decentraland:off-chain:halloween_2019:sad_clown_upper_body";
 4225            userProfile.SetInventory(Enumerable.Repeat(wearableId, amount).ToArray());
 4226            userProfile.UpdateData(new UserProfileModel()
 227            {
 228                name = "name",
 229                email = "mail",
 230                avatar = new AvatarModel()
 231                {
 232                    bodyShape = WearableLiterals.BodyShapes.FEMALE,
 233                    wearables = new List<string>() { },
 234                }
 235            }, false);
 236
 4237            var itemToggle = controller.myView.collectiblesItemSelector.itemToggles[wearableId];
 238
 4239            Assert.IsTrue(itemToggle.amountContainer.gameObject.activeSelf);
 4240            Assert.AreEqual($"x{amount}", itemToggle.amountText.text);
 4241        }
 242
 243        private WearableItem CreateDummyNFT(string rarity)
 244        {
 6245            var dummyItem = new WearableItem()
 246            {
 247                id = "dummyItem",
 248                rarity = rarity,
 249                description = "My Description",
 250                issuedId = 1,
 251                data = new WearableItem.Data()
 252                {
 253                    category = WearableLiterals.Categories.EYES,
 254                    tags = new[] { WearableLiterals.Tags.EXCLUSIVE },
 255                    representations = new[]
 256                    {
 257                        new WearableItem.Representation()
 258                        {
 259                            bodyShapes = new[] { WearableLiterals.BodyShapes.FEMALE, WearableLiterals.BodyShapes.MALE },
 260                        }
 261                    }
 262                },
 263                i18n = new[] { new i18n() { code = "en", text = "Dummy Item" } }
 264            };
 265
 6266            userProfile.SetInventory(new[] { dummyItem.id });
 6267            userProfile.UpdateData(new UserProfileModel()
 268            {
 269                name = "name",
 270                email = "mail",
 271                avatar = new AvatarModel()
 272                {
 273                    bodyShape = WearableLiterals.BodyShapes.FEMALE,
 274                    wearables = new List<string>() { },
 275                }
 276            }, false);
 277
 6278            catalog.Remove(dummyItem.id);
 6279            catalog.Add(dummyItem.id, dummyItem);
 6280            return dummyItem;
 281        }
 282    }
 283}