< Summary

Class:ReceivedFriendRequestsNotificationBadge
Assembly:NotificationBadge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/ReceivedFriendRequestsNotificationBadge.cs
Covered lines:20
Uncovered lines:4
Coverable lines:24
Total lines:69
Line coverage:83.3% (20 of 24)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:9
Method coverage:77.7% (7 of 9)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ReceivedFriendRequestsNotificationBadge()0%110100%
Start()0%110100%
OnEnable()0%110100%
Initialize(...)0%2.022083.33%
OnDestroy()0%220100%
UpdateReceivedRequests(...)0%2100%
UpdateReceivedRequests()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/ReceivedFriendRequestsNotificationBadge.cs

#LineLine coverage
 1using DCL;
 2using DCl.Social.Friends;
 3using DCL.Social.Friends;
 4using TMPro;
 5using UnityEngine;
 6
 7public class ReceivedFriendRequestsNotificationBadge : MonoBehaviour
 8{
 9    [SerializeField] private TextMeshProUGUI notificationText;
 10    [SerializeField] private GameObject notificationContainer;
 1011    [SerializeField] private int maxNumberToShow = 9;
 12
 13    private IFriendsController friendsController;
 14    private int currentUnreadMessagesValue;
 15
 16    public int CurrentUnreadMessages
 17    {
 018        get => currentUnreadMessagesValue;
 19        set
 20        {
 121            currentUnreadMessagesValue = value;
 22
 123            if (currentUnreadMessagesValue > 0)
 24            {
 025                notificationContainer.SetActive(true);
 026                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 27                    ? currentUnreadMessagesValue.ToString()
 28                    : $"+{maxNumberToShow}";
 29            }
 30            else
 31            {
 132                notificationContainer.SetActive(false);
 33            }
 134        }
 35    }
 36
 37    private void Start()
 38    {
 139        Initialize(Environment.i.serviceLocator.Get<IFriendsController>());
 140    }
 41
 42    private void OnEnable()
 43    {
 544        UpdateReceivedRequests();
 545    }
 46
 47    public void Initialize(IFriendsController friendsController)
 48    {
 149        if (friendsController == null) return;
 150        this.friendsController = friendsController;
 151        friendsController.OnTotalFriendRequestUpdated += UpdateReceivedRequests;
 152        UpdateReceivedRequests();
 153    }
 54
 55    private void OnDestroy()
 56    {
 557        if (friendsController != null)
 158            friendsController.OnTotalFriendRequestUpdated -= UpdateReceivedRequests;
 559    }
 60
 61    private void UpdateReceivedRequests(int totalReceivedFriendRequests, int totalSentFriendRequests) =>
 062        CurrentUnreadMessages = totalReceivedFriendRequests;
 63
 64    private void UpdateReceivedRequests()
 65    {
 1166        if (friendsController == null) return;
 167        CurrentUnreadMessages = friendsController.TotalReceivedFriendRequestCount;
 168    }
 69}