< Summary

Class:ReceivedFriendRequestsNotificationBadge
Assembly:NotificationBadge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/ReceivedFriendRequestsNotificationBadge.cs
Covered lines:19
Uncovered lines:5
Coverable lines:24
Total lines:65
Line coverage:79.1% (19 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%110100%
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        this.friendsController = friendsController;
 3247        friendsController.OnTotalFriendRequestUpdated += UpdateReceivedRequests;
 3248        UpdateReceivedRequests();
 3249    }
 50
 51    private void OnDestroy()
 52    {
 3453        if (friendsController != null)
 3254            friendsController.OnTotalFriendRequestUpdated -= UpdateReceivedRequests;
 3455    }
 56
 57    private void UpdateReceivedRequests(int totalReceivedFriendRequests, int totalSentFriendRequests) =>
 058        CurrentUnreadMessages = totalReceivedFriendRequests;
 59
 60    private void UpdateReceivedRequests()
 61    {
 10762        if (friendsController == null) return;
 3363        CurrentUnreadMessages = friendsController.TotalReceivedFriendRequestCount;
 3364    }
 65}