< 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:5
Coverable lines:25
Total lines:66
Line coverage:80% (20 of 25)
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 TMPro;
 2using UnityEngine;
 3
 4public class ReceivedFriendRequestsNotificationBadge : MonoBehaviour
 5{
 6    [SerializeField] private TextMeshProUGUI notificationText;
 7    [SerializeField] private GameObject notificationContainer;
 548    [SerializeField] private int maxNumberToShow = 9;
 9
 10    private IFriendsController friendsController;
 11    private int currentUnreadMessagesValue;
 12
 13    public int CurrentUnreadMessages
 14    {
 015        get => currentUnreadMessagesValue;
 16        set
 17        {
 3318            currentUnreadMessagesValue = value;
 19
 3320            if (currentUnreadMessagesValue > 0)
 21            {
 022                notificationContainer.SetActive(true);
 023                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 24                    ? currentUnreadMessagesValue.ToString()
 25                    : $"+{maxNumberToShow}";
 026            }
 27            else
 28            {
 3329                notificationContainer.SetActive(false);
 30            }
 3331        }
 32    }
 33
 34    private void Start()
 35    {
 3236        Initialize(FriendsController.i);
 3237    }
 38
 39    private void OnEnable()
 40    {
 3841        UpdateReceivedRequests();
 3842    }
 43
 44    public void Initialize(IFriendsController friendsController)
 45    {
 3246        if (friendsController == null) return;
 3247        this.friendsController = friendsController;
 3248        friendsController.OnTotalFriendRequestUpdated += UpdateReceivedRequests;
 3249        UpdateReceivedRequests();
 3250    }
 51
 52    private void OnDestroy()
 53    {
 3454        if (friendsController != null)
 3255            friendsController.OnTotalFriendRequestUpdated -= UpdateReceivedRequests;
 3456    }
 57
 58    private void UpdateReceivedRequests(int totalReceivedFriendRequests, int totalSentFriendRequests) =>
 059        CurrentUnreadMessages = totalReceivedFriendRequests;
 60
 61    private void UpdateReceivedRequests()
 62    {
 10763        if (friendsController == null) return;
 3364        CurrentUnreadMessages = friendsController.TotalReceivedFriendRequestCount;
 3365    }
 66}