< Summary

Class:NotificationsController
Assembly:NotificationsController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/NotificationsController/NotificationsController.cs
Covered lines:1
Uncovered lines:30
Coverable lines:31
Total lines:81
Line coverage:3.2% (1 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
Initialize(...)0%2100%
Dispose()0%2100%
ShowNotificationFromJson(...)0%6200%
ShowNotification(...)0%12300%
ShowNotification(...)0%12300%
DismissAllNotifications(...)0%6200%
ShowWelcomeNotification()0%20400%
ShowDefaultErrorNotification(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/NotificationsController/NotificationsController.cs

#LineLine coverage
 1using DCL;
 2using DCL.NotificationModel;
 3using UnityEngine;
 4
 5public class NotificationsController : MonoBehaviour
 6{
 317    public static NotificationsController i { get; private set; }
 8    public static bool disableWelcomeNotification = false;
 9
 010    public bool allowNotifications { get; set; }
 11
 012    void Awake() { i = this; }
 13
 14    private INotificationHUDController controller;
 15    private DataStore_Notifications notificationsDataStore;
 16
 17    // TODO: refactor into a bridge->service architecture so this dependencies are properly injected
 18    public void Initialize(
 19        INotificationHUDController controller,
 20        DataStore_Notifications notificationsDataStore)
 21    {
 022        this.controller = controller;
 023        this.notificationsDataStore = notificationsDataStore;
 024        allowNotifications = true;
 25
 026        this.notificationsDataStore.DefaultErrorNotification.OnChange += ShowDefaultErrorNotification;
 027    }
 28
 29    public void Dispose()
 30    {
 031        notificationsDataStore.DefaultErrorNotification.OnChange -= ShowDefaultErrorNotification;
 032        controller.Dispose();
 033    }
 34
 35    public void ShowNotificationFromJson(string notificationJson)
 36    {
 037        if (!allowNotifications)
 038            return;
 39
 040        Model model = JsonUtility.FromJson<Model>(notificationJson);
 041        ShowNotification(model);
 042    }
 43
 44    public void ShowNotification(Model notification)
 45    {
 046        if (!allowNotifications)
 047            return;
 48
 049        controller?.ShowNotification(notification);
 050    }
 51
 52    public void ShowNotification(INotification notification)
 53    {
 054        if (!allowNotifications)
 055            return;
 56
 057        controller?.ShowNotification(notification);
 058    }
 59
 060    public void DismissAllNotifications(string groupID) { controller?.DismissAllNotifications(groupID); }
 61
 62    public void ShowWelcomeNotification()
 63    {
 064        if (!allowNotifications || disableWelcomeNotification)
 065            return;
 66
 67        //TODO(Brian): This should be triggered entirely by kernel
 068        controller?.ShowWelcomeNotification();
 069    }
 70
 71    private void ShowDefaultErrorNotification(string errorText, string _)
 72    {
 073        ShowNotification(new Model
 74        {
 75            message = errorText,
 76            type = Type.ERROR,
 77            timer = 5f,
 78            destroyOnFinish = true
 79        });
 080    }
 81}