< Summary

Class:ModalComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Modal/ModalComponentView.cs
Covered lines:12
Uncovered lines:12
Coverable lines:24
Total lines:78
Line coverage:50% (12 of 24)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%2100%
RefreshControl()0%3.073080%
Configure(...)0%110100%
CloseButtonClicked()0%220100%
Show(...)0%6200%
Hide(...)0%2.52050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Modal/ModalComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public interface IModalComponentView
 8{
 9    /// <summary>
 10    /// It will be triggered when the modal is closed.
 11    /// </summary>
 12    event Action OnCloseAction;
 13
 14    /// <summary>
 15    /// Fill the model and updates the modal with this data.
 16    /// </summary>
 17    /// <param name="model">Data to configure the image.</param>
 18    void Configure(ModalComponentModel model);
 19}
 20
 21public class ModalComponentView : BaseComponentView, IModalComponentView
 22{
 23    public event Action OnCloseAction;
 24
 25    [Header("Prefab References")]
 26    [SerializeField] internal ButtonComponentView closeButton;
 27    [SerializeField] internal Button alphaBackground;
 28    [SerializeField] internal GameObject container;
 29
 30    [Header("Configuration")]
 31    [SerializeField] internal ModalComponentModel model;
 32
 33    internal GameObject content;
 34
 35    public override void Start()
 36    {
 037        base.Start();
 38
 039        closeButton.onClick.AddListener(CloseButtonClicked);
 040        alphaBackground.onClick.AddListener(CloseButtonClicked);
 041        RefreshControl();
 042    }
 43
 44    public override void RefreshControl()
 45    {
 146        if (content != null)
 047            Destroy(content);
 148        if (model.content != null)
 149            content = Instantiate(model.content, container.transform);
 150    }
 51
 52    public void Configure(ModalComponentModel model)
 53    {
 154        this.model = model;
 155        RefreshControl();
 156    }
 57
 58    internal void CloseButtonClicked()
 59    {
 160        OnCloseAction?.Invoke();
 161        Hide();
 162    }
 63
 64    public override void Show(bool instant = false)
 65    {
 066        if (isVisible)
 067            return;
 68
 069        base.Show(instant);
 070    }
 71    public override void Hide(bool instant = false)
 72    {
 173        if (!isVisible)
 174            return;
 75
 076        base.Hide(instant);
 077    }
 78}