< Summary

Class:ProfileCardComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ProfileCard/ProfileCardComponentView.cs
Covered lines:42
Uncovered lines:14
Coverable lines:56
Total lines:162
Line coverage:75% (42 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%220100%
Configure(...)0%110100%
RefreshControl()0%8.125050%
Dispose()0%220100%
SetProfilePicture(...)0%2.032080%
SetProfilePicture(...)0%3.213071.43%
SetProfilePicture(...)0%3.213071.43%
SetProfileName(...)0%4.134080%
SetProfileAddress(...)0%4.054085.71%
SetLoadingIndicatorVisible(...)0%110100%
OnProfileImageLoaded(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ProfileCard/ProfileCardComponentView.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public interface IProfileCardComponentView
 6{
 7    /// <summary>
 8    /// Event that will be triggered when the profile card is clicked.
 9    /// </summary>
 10    Button.ButtonClickedEvent onClick { get; }
 11
 12    /// <summary>
 13    /// Set the profile picture directly from a sprite.
 14    /// </summary>
 15    /// <param name="sprite">Profile picture (sprite).</param>
 16    void SetProfilePicture(Sprite sprite);
 17
 18    /// <summary>
 19    /// Set the profile picture from a 2D texture.
 20    /// </summary>
 21    /// <param name="newPicture">Profile picture (2D texture).</param>
 22    void SetProfilePicture(Texture2D newPicture);
 23
 24    /// <summary>
 25    /// Set the profile picture from an uri.
 26    /// </summary>
 27    /// <param name="uri">Profile picture (url).</param>
 28    void SetProfilePicture(string uri);
 29
 30    /// <summary>
 31    /// Set the profile name.
 32    /// </summary>
 33    /// <param name="newName">Profile name.</param>
 34    void SetProfileName(string newName);
 35
 36    /// <summary>
 37    /// Set the profile address. It will only show the last 4 caracteres.
 38    /// </summary>
 39    /// <param name="newAddress">Profile address.</param>
 40    void SetProfileAddress(string newAddress);
 41
 42    /// <summary>
 43    /// Active or deactive the loading indicator.
 44    /// </summary>
 45    /// <param name="isVisible">True for showing the loading indicator.</param>
 46    void SetLoadingIndicatorVisible(bool isVisible);
 47}
 48
 49public class ProfileCardComponentView : BaseComponentView, IProfileCardComponentView, IComponentModelConfig
 50{
 51    [Header("Prefab References")]
 52    [SerializeField] internal Button button;
 53    [SerializeField] internal ImageComponentView profileImage;
 54    [SerializeField] internal TMP_Text profileName;
 55    [SerializeField] internal TMP_Text profileAddress;
 56
 57    [Header("Configuration")]
 58    [SerializeField] internal ProfileCardComponentModel model;
 59
 060    public Button.ButtonClickedEvent onClick => button?.onClick;
 61
 62    public override void Start()
 63    {
 1864        if (profileImage != null)
 1865            profileImage.OnLoaded += OnProfileImageLoaded;
 1866    }
 67
 68    public void Configure(BaseComponentModel newModel)
 69    {
 170        model = (ProfileCardComponentModel)newModel;
 171        RefreshControl();
 172    }
 73
 74    public override void RefreshControl()
 75    {
 176        if (model == null)
 077            return;
 78
 179        if (model.profilePictureSprite != null)
 180            SetProfilePicture(model.profilePictureSprite);
 081        else if (model.profilePictureTexture != null)
 082            SetProfilePicture(model.profilePictureTexture);
 083        else if (!string.IsNullOrEmpty(model.profilePictureUri))
 084            SetProfilePicture(model.profilePictureUri);
 85        else
 086            SetProfilePicture(sprite: null);
 87
 188        SetProfileName(model.profileName);
 189        SetProfileAddress(model.profileAddress);
 190    }
 91
 92    public override void Dispose()
 93    {
 4494        base.Dispose();
 95
 4496        if (profileImage != null)
 4497            profileImage.OnLoaded += OnProfileImageLoaded;
 4498    }
 99
 100    public void SetProfilePicture(Sprite sprite)
 101    {
 3102        model.profilePictureSprite = sprite;
 103
 3104        if (profileImage == null)
 0105            return;
 106
 3107        profileImage.SetImage(sprite);
 3108    }
 109
 110    public void SetProfilePicture(Texture2D texture)
 111    {
 1112        model.profilePictureTexture = texture;
 113
 1114        if (!Application.isPlaying)
 0115            return;
 116
 1117        if (profileImage == null)
 0118            return;
 119
 1120        profileImage.SetImage(texture);
 1121    }
 122
 123    public void SetProfilePicture(string uri)
 124    {
 1125        model.profilePictureUri = uri;
 126
 1127        if (!Application.isPlaying)
 0128            return;
 129
 1130        if (profileImage == null)
 0131            return;
 132
 1133        profileImage.SetImage(uri);
 1134    }
 135
 136    public void SetProfileName(string newName)
 137    {
 3138        model.profileName = newName;
 139
 3140        if (profileName == null)
 0141            return;
 142
 3143        profileName.text = !string.IsNullOrEmpty(newName) ? newName : string.Empty;
 3144    }
 145
 146    public void SetProfileAddress(string newAddress)
 147    {
 4148        model.profileAddress = newAddress;
 149
 4150        if (profileAddress == null)
 0151            return;
 152
 4153        if (!string.IsNullOrEmpty(newAddress))
 3154            profileAddress.text = newAddress.Length >= 4 ? $"#{newAddress.Substring(newAddress.Length - 4, 4)}" : $"#{ne
 155        else
 1156            profileAddress.text = string.Empty;
 1157    }
 158
 4159    public void SetLoadingIndicatorVisible(bool isVisible) { profileImage.SetLoadingIndicatorVisible(isVisible); }
 160
 2161    internal void OnProfileImageLoaded(Sprite sprite) { SetProfilePicture(sprite); }
 162}