< Summary

Class:SectionSelectorComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/SectionSelector/SectionSelectorComponentView.cs
Covered lines:45
Uncovered lines:11
Coverable lines:56
Total lines:152
Line coverage:80.3% (45 of 56)
Covered branches:0
Total branches:0
Covered methods:11
Total methods:13
Method coverage:84.6% (11 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSelectorComponentView()0%110100%
Awake()0%110100%
Configure(...)0%110100%
RefreshControl()0%2.062075%
SetSections(...)0%330100%
GetSection(...)0%220100%
DisableSection(...)0%220100%
EnableSection(...)0%6200%
GetAllSections()0%110100%
CreateSection(...)0%2.012088.89%
RemoveAllInstantiatedSections()0%6.296080%
DestroyGameObjectOnEditor()0%12300%
RegisterCurrentInstantiatedSections()0%6.046090%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/SectionSelector/SectionSelectorComponentView.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5public interface ISectionSelectorComponentView
 6{
 7    /// <summary>
 8    /// Set the sections of the selector.
 9    /// </summary>
 10    /// <param name="sections">List of UI components.</param>
 11    void SetSections(List<SectionToggleModel> sections);
 12
 13    /// <summary>
 14    /// Get a section of the section selector.
 15    /// </summary>
 16    /// <param name="index">Index of the list of sections.</param>
 17    /// <returns>A specific section toggle.</returns>
 18    ISectionToggle GetSection(int index);
 19
 20    /// <summary>
 21    /// Get all the sections of the section selector.
 22    /// </summary>
 23    /// <returns>The list of sections.</returns>
 24    List<ISectionToggle> GetAllSections();
 25}
 26
 27public class SectionSelectorComponentView : BaseComponentView, ISectionSelectorComponentView, IComponentModelConfig<Sect
 28{
 29    [Header("Prefab References")]
 30    [SerializeField] internal SectionToggle sectionToggleTemplate;
 31
 32    [Header("Configuration")]
 33    [SerializeField] internal SectionSelectorComponentModel model;
 34
 10135    internal List<ISectionToggle> instantiatedSections = new List<ISectionToggle>();
 36
 37    public override void Awake()
 38    {
 9439        base.Awake();
 40
 9441        RegisterCurrentInstantiatedSections();
 9442    }
 43
 44    public void Configure(SectionSelectorComponentModel newModel)
 45    {
 146        model = newModel;
 147        RefreshControl();
 148    }
 49
 50    public override void RefreshControl()
 51    {
 1352        if (model == null)
 053            return;
 54
 1355        SetSections(model.sections);
 1356    }
 57
 58    public void SetSections(List<SectionToggleModel> sections)
 59    {
 1760        model.sections = sections;
 61
 1762        RemoveAllInstantiatedSections();
 63
 19864        for (int i = 0; i < sections.Count; i++)
 65        {
 8266            CreateSection(sections[i], $"Section_{i}");
 67        }
 68
 1769        if (instantiatedSections.Count > 0)
 1770            instantiatedSections[0].SelectToggle();
 1771    }
 72
 73    public ISectionToggle GetSection(int index)
 74    {
 97875        if (index >= instantiatedSections.Count)
 8876            return null;
 77
 89078        return instantiatedSections[index];
 79    }
 80
 81    public void DisableSection(int index)
 82    {
 7683        if (index < instantiatedSections.Count)
 7684            instantiatedSections[index].GameObject.SetActive(false);
 7685    }
 86
 87    public void EnableSection(int index)
 88    {
 089        if (index < instantiatedSections.Count)
 090            instantiatedSections[index].GameObject.SetActive(true);
 091    }
 92
 193    public List<ISectionToggle> GetAllSections() { return instantiatedSections; }
 94
 95    internal void CreateSection(SectionToggleModel newSectionModel, string name)
 96    {
 8397        if (sectionToggleTemplate == null)
 098            return;
 99
 83100        SectionToggle newGO = Instantiate(sectionToggleTemplate, transform);
 83101        newGO.name = name;
 83102        newGO.gameObject.SetActive(true);
 83103        newGO.SetInfo(newSectionModel);
 83104        newGO.SelectToggle();
 83105        instantiatedSections.Add(newGO);
 83106    }
 107
 108    internal void RemoveAllInstantiatedSections()
 109    {
 216110        foreach (Transform child in transform)
 111        {
 90112            if (child.gameObject == sectionToggleTemplate.gameObject)
 113                continue;
 114
 72115            if (Application.isPlaying)
 116            {
 72117                Destroy(child.gameObject);
 118            }
 119            else
 120            {
 0121                if (isActiveAndEnabled)
 0122                    StartCoroutine(DestroyGameObjectOnEditor(child.gameObject));
 123            }
 124        }
 125
 18126        instantiatedSections.Clear();
 18127    }
 128
 129    internal IEnumerator DestroyGameObjectOnEditor(GameObject go)
 130    {
 0131        yield return null;
 0132        DestroyImmediate(go);
 0133    }
 134
 135    internal void RegisterCurrentInstantiatedSections()
 136    {
 94137        instantiatedSections.Clear();
 138
 1182139        foreach (Transform child in transform)
 140        {
 497141            if (child.gameObject == sectionToggleTemplate.gameObject ||
 142                child.name.Contains("TooltipRef"))
 143                continue;
 144
 403145            SectionToggle existingSection = child.GetComponent<SectionToggle>();
 403146            if (existingSection != null)
 403147                instantiatedSections.Add(existingSection);
 148            else
 0149                Destroy(child.gameObject);
 150        }
 94151    }
 152}