< Summary

Class:ModalComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Modal/ModalComponentView.cs
Covered lines:14
Uncovered lines:15
Coverable lines:29
Total lines:91
Line coverage:48.2% (14 of 29)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:8
Method coverage:62.5% (5 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ModalComponentView()0%110100%
Start()0%2100%
RefreshControl()0%3.073080%
Configure(...)0%110100%
CanBeCancelled(...)0%2100%
CloseButtonClicked()0%3.073080%
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    /// <summary>
 21    /// This will hide the close button of the pop up, forcing the user to take an action
 22    /// </summary>
 23    /// <param name="canBe"></param>
 24    void CanBeCancelled(bool canBe);
 25}
 26
 27public class ModalComponentView : BaseComponentView, IModalComponentView
 28{
 29    public event Action OnCloseAction;
 30
 31    [Header("Prefab References")]
 32    [SerializeField] internal ButtonComponentView closeButton;
 33    [SerializeField] internal Button alphaBackground;
 34    [SerializeField] internal GameObject container;
 35
 36    [Header("Configuration")]
 37    [SerializeField] internal ModalComponentModel model;
 38
 39    internal GameObject content;
 340    internal bool canBeCanceled = true;
 41
 42    public void Start()
 43    {
 044        closeButton.onClick.AddListener(CloseButtonClicked);
 045        alphaBackground.onClick.AddListener(CloseButtonClicked);
 046        RefreshControl();
 047    }
 48
 49    public override void RefreshControl()
 50    {
 151        if (content != null)
 052            Destroy(content);
 153        if (model.content != null)
 154            content = Instantiate(model.content, container.transform);
 155    }
 56
 57    public void Configure(ModalComponentModel model)
 58    {
 159        this.model = model;
 160        RefreshControl();
 161    }
 62
 63    public void CanBeCancelled(bool canBe)
 64    {
 065        closeButton.gameObject.SetActive(canBe);
 066        canBeCanceled = canBe;
 067    }
 68
 69    internal void CloseButtonClicked()
 70    {
 171        if (!canBeCanceled)
 072            return;
 173        OnCloseAction?.Invoke();
 174        Hide();
 175    }
 76
 77    public override void Show(bool instant = false)
 78    {
 079        if (isVisible)
 080            return;
 81
 082        base.Show(instant);
 083    }
 84    public override void Hide(bool instant = false)
 85    {
 186        if (!isVisible)
 187            return;
 88
 089        base.Hide(instant);
 090    }
 91}