< Summary

Class:NotificationHUDController
Assembly:NotificationHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationHUDController.cs
Covered lines:20
Uncovered lines:14
Coverable lines:34
Total lines:83
Line coverage:58.8% (20 of 34)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:13
Method coverage:76.9% (10 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
NotificationHUDController(...)0%110100%
NotificationHUDController(...)0%110100%
Dispose()0%220100%
ShowNotification(...)0%2100%
ShowNotification(...)0%2.032080%
DismissAllNotifications(...)0%30500%
OnNotificationDismissed(...)0%110100%
SetActive(...)0%110100%
SetVisibility(...)0%110100%
ShowWelcomeNotification()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationHUD/NotificationHUDController.cs

#LineLine coverage
 1using System.Collections.Generic;
 2
 3public class NotificationHUDController : IHUD, INotificationHUDController
 4{
 5    [System.Serializable]
 6    public class Model
 7    {
 68        public List<INotification> notifications = new();
 9    }
 10
 2411    public NotificationHUDView view { get; }
 1012    public Model model { get; }
 13
 1214    public NotificationHUDController(NotificationHUDView view) : this(new Model(), view) { }
 15
 616    public NotificationHUDController(Model model, NotificationHUDView view)
 17    {
 618        this.model = model;
 619        this.view = view;
 20
 621        view.OnNotificationDismissedEvent += OnNotificationDismissed;
 622    }
 23
 24    public void Dispose()
 25    {
 626        if (view != null)
 27        {
 628            UnityEngine.Object.Destroy(view.gameObject);
 629            view.OnNotificationDismissedEvent -= OnNotificationDismissed;
 30        }
 631    }
 32
 33    public void ShowNotification(INotification notification)
 34    {
 035        model.notifications.Add(notification);
 036        view.ShowNotification(notification, notification.model);
 037    }
 38
 39    public void ShowNotification(DCL.NotificationModel.Model model)
 40    {
 441        if (!string.IsNullOrEmpty(model.groupID))
 42        {
 43            //NOTE(Brian): If more notifications of the same group are visible, hide them.
 44            //             This works when having notifications in different contexts (i.e. FriendsHUD vs global notific
 045            DismissAllNotifications(model.groupID);
 46        }
 47
 448        var notification = view.ShowNotification(model);
 449        this.model.notifications.Add(notification);
 450    }
 51
 52    public void DismissAllNotifications(string groupID)
 53    {
 054        if (this.model.notifications.Count > 0)
 55        {
 56            //NOTE(Brian): Copy list to avoid modify while iterating error
 057            var notiList = new List<INotification>(this.model.notifications);
 058            int notiCount = notiList.Count;
 59
 060            for (int i = 0; i < notiCount; i++)
 61            {
 062                if (!string.IsNullOrEmpty(groupID) && groupID != notiList[i].model.groupID)
 63                    continue;
 64
 065                notiList[i].Dismiss(instant: true);
 66            }
 67        }
 068    }
 69
 270    private void OnNotificationDismissed(INotification notification) { model.notifications.Remove(notification); }
 71
 272    public void SetActive(bool active) { view.SetActive(active); }
 73
 74
 75
 276    public void SetVisibility(bool visible) { SetActive(visible); }
 77
 78    public void ShowWelcomeNotification()
 79    {
 080        var model = WelcomeNotification.Get();
 081        ShowNotification(model);
 082    }
 83}