< Summary

Class:DCL.Backpack.NftBreadcrumbComponentView
Assembly:BackpackEditorHUDV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/NftBreadcrumbComponentView.cs
Covered lines:43
Uncovered lines:5
Coverable lines:48
Total lines:132
Line coverage:89.5% (43 of 48)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:10
Method coverage:80% (8 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NftBreadcrumbComponentView()0%110100%
Awake()0%110100%
RefreshControl()0%330100%
Update()0%2.862040%
CreateSeparator()0%110100%
CreateSubCategory(...)0%220100%
ClearInstances()0%330100%
RemoveFilter(...)0%6200%
ApplyFilter(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/NftBreadcrumbComponentView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System;
 3using System.Collections.Generic;
 4using UIComponents.Scripts.Components;
 5using UnityEngine;
 6
 7namespace DCL.Backpack
 8{
 9    public class NftBreadcrumbComponentView : BaseComponentView<NftBreadcrumbModel>
 10    {
 11        [SerializeField] internal NftSubCategoryFilterComponentView prefab;
 12        [SerializeField] internal GameObject separatorPrefab;
 13        [SerializeField] internal RectTransform container;
 14        [SerializeField] internal RectTransform layoutContainer;
 15        [SerializeField] internal NFTTypeIconsAndColors iconsByCategory;
 16
 4017        private readonly Dictionary<NftSubCategoryFilterComponentView, PoolableObject> pooledObjects = new ();
 4018        private readonly Dictionary<GameObject, PoolableObject> pooledSeparators = new ();
 19        private Pool pool;
 20        private Pool separatorsPool;
 21        private bool isLayoutDirty;
 22
 123        internal NftBreadcrumbModel Model => model;
 24
 25        public event Action<string> OnFilterSelected;
 26        public event Action<string> OnFilterRemoved;
 27
 28        public override void Awake()
 29        {
 3730            base.Awake();
 31
 3732            pool = PoolManager.i.AddPool(
 33                $"NftBreadcrumbComponentView_{GetInstanceID()}",
 34                Instantiate(prefab).gameObject,
 35                maxPrewarmCount: 5,
 36                isPersistent: true);
 37
 3738            separatorsPool = PoolManager.i.AddPool(
 39                $"NftBreadcrumbSeparator_{GetInstanceID()}",
 40                Instantiate(separatorPrefab),
 41                maxPrewarmCount: 5,
 42                isPersistent: true);
 3743        }
 44
 45        public override void RefreshControl()
 46        {
 447            ClearInstances();
 48
 2049            for (var i = 0; i < model.Path.Length; i++)
 50            {
 651                (string Filter, string Name, string Type, bool Removable) subCategory = model.Path[i];
 652                bool isLastItem = i == model.Path.Length - 1;
 653                bool isSelected = model.Current == i;
 54
 655                CreateSubCategory(subCategory, false, isSelected);
 56
 657                if (!isLastItem)
 258                    CreateSeparator();
 59            }
 60
 461            isLayoutDirty = true;
 462        }
 63
 64        private void Update()
 65        {
 666            if (!isLayoutDirty) return;
 067            isLayoutDirty = false;
 068            layoutContainer.ForceUpdateLayout(false);
 069        }
 70
 71        private void CreateSeparator()
 72        {
 273            PoolableObject poolObj = separatorsPool.Get();
 274            GameObject separator = poolObj.gameObject;
 275            separator.transform.SetParent(container, false);
 276            pooledSeparators[separator] = poolObj;
 277        }
 78
 79        private NftSubCategoryFilterComponentView CreateSubCategory((string Filter, string Name, string Type, bool Remov
 80            bool showResultCount, bool isSelected)
 81        {
 682            PoolableObject poolObj = pool.Get();
 683            NftSubCategoryFilterComponentView view = poolObj.gameObject.GetComponent<NftSubCategoryFilterComponentView>(
 684            Sprite icon = iconsByCategory.GetTypeImage(subCategory.Type);
 85
 686            string categoryName = subCategory.Name;
 687            categoryName = WearableItem.CATEGORIES_READABLE_MAPPING.TryGetValue(categoryName, out string readableCategor
 88
 689            view.SetModel(new NftSubCategoryFilterModel
 90            {
 91                Name = categoryName,
 92                Filter = subCategory.Filter,
 93                ResultCount = model.ResultCount,
 94                ShowResultCount = showResultCount,
 95                Icon = icon,
 96                IsSelected = isSelected,
 97                ShowRemoveButton = subCategory.Removable,
 98            });
 99
 6100            view.OnNavigate += ApplyFilter;
 6101            view.OnExit += RemoveFilter;
 6102            view.transform.SetParent(container, false);
 103
 6104            pooledObjects[view] = poolObj;
 105
 6106            return view;
 107        }
 108
 109        private void ClearInstances()
 110        {
 12111            foreach ((NftSubCategoryFilterComponentView view, PoolableObject poolObj) in pooledObjects)
 112            {
 2113                poolObj.Release();
 2114                view.OnNavigate -= ApplyFilter;
 2115                view.OnExit -= RemoveFilter;
 116            }
 117
 4118            pooledObjects.Clear();
 119
 10120            foreach ((GameObject go, PoolableObject poolObj) in pooledSeparators)
 1121                poolObj.Release();
 122
 4123            pooledSeparators.Clear();
 4124        }
 125
 126        private void RemoveFilter(NftSubCategoryFilterModel model) =>
 0127            OnFilterRemoved?.Invoke(model.Filter);
 128
 129        private void ApplyFilter(NftSubCategoryFilterModel model) =>
 0130            OnFilterSelected?.Invoke(model.Filter);
 131    }
 132}