< 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:68
Line coverage:83.3% (20 of 24)
Covered branches:0
Total branches:0

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.Social.Friends;
 2using DCL.Social.Friends;
 3using TMPro;
 4using UnityEngine;
 5
 6public class ReceivedFriendRequestsNotificationBadge : MonoBehaviour
 7{
 8    [SerializeField] private TextMeshProUGUI notificationText;
 9    [SerializeField] private GameObject notificationContainer;
 5610    [SerializeField] private int maxNumberToShow = 9;
 11
 12    private IFriendsController friendsController;
 13    private int currentUnreadMessagesValue;
 14
 15    public int CurrentUnreadMessages
 16    {
 017        get => currentUnreadMessagesValue;
 18        set
 19        {
 3020            currentUnreadMessagesValue = value;
 21
 3022            if (currentUnreadMessagesValue > 0)
 23            {
 024                notificationContainer.SetActive(true);
 025                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 26                    ? currentUnreadMessagesValue.ToString()
 27                    : $"+{maxNumberToShow}";
 28            }
 29            else
 30            {
 3031                notificationContainer.SetActive(false);
 32            }
 3033        }
 34    }
 35
 36    private void Start()
 37    {
 2938        Initialize(FriendsController.i);
 2939    }
 40
 41    private void OnEnable()
 42    {
 3543        UpdateReceivedRequests();
 3544    }
 45
 46    public void Initialize(IFriendsController friendsController)
 47    {
 2948        if (friendsController == null) return;
 2949        this.friendsController = friendsController;
 2950        friendsController.OnTotalFriendRequestUpdated += UpdateReceivedRequests;
 2951        UpdateReceivedRequests();
 2952    }
 53
 54    private void OnDestroy()
 55    {
 3456        if (friendsController != null)
 2957            friendsController.OnTotalFriendRequestUpdated -= UpdateReceivedRequests;
 3458    }
 59
 60    private void UpdateReceivedRequests(int totalReceivedFriendRequests, int totalSentFriendRequests) =>
 061        CurrentUnreadMessages = totalReceivedFriendRequests;
 62
 63    private void UpdateReceivedRequests()
 64    {
 9865        if (friendsController == null) return;
 3066        CurrentUnreadMessages = friendsController.TotalReceivedFriendRequestCount;
 3067    }
 68}