< Summary

Class:PlaceCategoryButton
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/PlacesSubSectionMenu/PlaceCategoryButton.cs
Covered lines:2
Uncovered lines:21
Coverable lines:23
Total lines:71
Line coverage:8.6% (2 of 23)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:6
Method coverage:16.6% (1 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2.52050%
SetCategory(...)0%12300%
SetStatus(...)0%30500%
RemoveNonASCIICharacters(...)0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/PlacesSubSectionMenu/PlaceCategoryButton.cs

#LineLine coverage
 1using System;
 2using System.Text;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public class PlaceCategoryButton : MonoBehaviour
 8{
 9    [SerializeField] internal Button button;
 10    [SerializeField] internal Image buttonBackgroundImage;
 11    [SerializeField] internal Image iconImage;
 12    [SerializeField] internal TMP_Text text;
 13    [SerializeField] internal Color selectedBackgroundColor;
 14    [SerializeField] internal Color selectedTextColor;
 15    [SerializeField] internal Color deselectedBackgroundColor;
 16    [SerializeField] internal Color deselectedTextColor;
 17
 18    [SerializeField] internal PlaceCategoryIcons cagtegoryIconsSO;
 19
 20    public event Action<string, bool> OnClick;
 21
 022    public string currenCategory { get; private set; }
 23
 24    private bool isCurrentlySelected;
 25
 26    private void Awake()
 27    {
 128        if (button == null)
 129            return;
 30
 031        button.onClick.AddListener(() => OnClick?.Invoke(currenCategory, !isCurrentlySelected));
 032    }
 33
 34    public void SetCategory(string categoryId, string nameToShow)
 35    {
 036        currenCategory = categoryId;
 037        text.text = RemoveNonASCIICharacters(nameToShow)
 38                             .ToUpper()
 39                             .Trim();
 40
 041        var iconFound = false;
 042        foreach (PlaceCategoryIcon categoryIcon in cagtegoryIconsSO.categoryIcons)
 43        {
 044            if (categoryIcon.category != categoryId)
 45                continue;
 46
 047            iconImage.sprite = categoryIcon.icon;
 048            iconFound = true;
 049            break;
 50        }
 51
 052        iconImage.gameObject.SetActive(iconFound);
 053    }
 54
 55    public void SetStatus(bool isSelected)
 56    {
 057        isCurrentlySelected = isSelected;
 058        buttonBackgroundImage.color = isSelected ? selectedBackgroundColor : deselectedBackgroundColor;
 059        text.color = isSelected ? selectedTextColor : deselectedTextColor;
 060    }
 61
 62    private static string RemoveNonASCIICharacters(string text)
 63    {
 064        StringBuilder sb = new StringBuilder();
 65
 066        foreach (char c in text)
 067            if (c <= 127) sb.Append(c);
 68
 069        return sb.ToString();
 70    }
 71}