< Summary

Class:FriendsHUDView
Assembly:FriendsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDView.cs
Covered lines:39
Uncovered lines:30
Coverable lines:69
Total lines:204
Line coverage:56.5% (39 of 69)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FriendsHUDView()0%110100%
FriendsHUDView()0%110100%
Create(...)0%110100%
GetAllEntries()0%2100%
ShowSpinner()0%110100%
HideSpinner()0%110100%
Initialize(...)0%220100%
OnCloseButtonPressed()0%6200%
AddFakeRequestReceived()0%2100%
AddFakeRequestSent()0%2100%
AddFakeRequestSentAccepted()0%2100%
AddFakeOnlineFriend()0%2100%
AddFakeOfflineFriend()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class FriendsHUDView : MonoBehaviour
 7{
 8    public const string NOTIFICATIONS_ID = "Friends";
 19    static readonly int ANIM_PROPERTY_SELECTED = Animator.StringToHash("Selected");
 10    const string VIEW_PATH = "FriendsHUD";
 11    const int PREINSTANTIATED_FRIENDS_ENTRIES = 25;
 12    const int PREINSTANTIATED_FRIENDS_REQUEST_ENTRIES = 5;
 13
 14    public Button closeButton;
 15    public Button friendsButton;
 16    public Button friendRequestsButton;
 17    public FriendsTabView friendsList;
 18    public FriendRequestsTabView friendRequestsList;
 19    public GameObject spinner;
 20
 2321    public float notificationsDuration = 3f;
 22
 23    FriendsHUDController controller;
 24
 25    public event System.Action OnClose;
 26
 27    public static FriendsHUDView Create(FriendsHUDController controller)
 28    {
 2229        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<FriendsHUDView>();
 2230        view.Initialize(controller);
 2231        return view;
 32    }
 33
 34    internal List<FriendEntryBase> GetAllEntries()
 35    {
 036        var result = new List<FriendEntryBase>();
 037        result.AddRange(friendsList.GetAllEntries());
 038        result.AddRange(friendRequestsList.GetAllEntries());
 039        return result;
 40    }
 41
 42    public void ShowSpinner()
 43    {
 144        spinner.gameObject.SetActive(true);
 45
 146        friendsList.gameObject.SetActive(false);
 147        friendRequestsList.gameObject.SetActive(false);
 48
 149        friendsButton.interactable = false;
 150        friendRequestsButton.interactable = false;
 151    }
 52
 53    public void HideSpinner()
 54    {
 1155        spinner.gameObject.SetActive(false);
 56
 1157        friendsList.gameObject.SetActive(true);
 1158        friendRequestsList.gameObject.SetActive(false);
 59
 1160        friendsButton.interactable = true;
 1161        friendsButton.onClick.Invoke();
 62
 1163        friendRequestsButton.interactable = true;
 1164    }
 65
 66    private void Initialize(FriendsHUDController controller)
 67    {
 2268        this.controller = controller;
 2269        friendsList.Initialize(this, PREINSTANTIATED_FRIENDS_ENTRIES);
 2270        friendRequestsList.Initialize(this, PREINSTANTIATED_FRIENDS_REQUEST_ENTRIES);
 71
 2272        closeButton.onClick.AddListener(OnCloseButtonPressed);
 73
 2274        friendsButton.onClick.AddListener(() =>
 75        {
 3776            friendsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, true);
 3777            friendRequestsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, false);
 3778            friendsList.gameObject.SetActive(true);
 3779            friendRequestsList.gameObject.SetActive(false);
 3780            Utils.ForceUpdateLayout(friendsList.transform as RectTransform);
 3781        });
 82
 2283        friendRequestsButton.onClick.AddListener(() =>
 84        {
 185            friendsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, false);
 186            friendRequestsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, true);
 187            friendsList.gameObject.SetActive(false);
 188            friendRequestsList.gameObject.SetActive(true);
 189            Utils.ForceUpdateLayout(friendRequestsList.transform as RectTransform);
 190        });
 91
 2292        if (friendsButton.interactable)
 2293            friendsButton.onClick.Invoke();
 2294    }
 95
 96    public void OnCloseButtonPressed()
 97    {
 098        controller.SetVisibility(false);
 099        OnClose?.Invoke();
 0100    }
 101
 102#if UNITY_EDITOR
 103    [ContextMenu("AddFakeRequestReceived")]
 104    public void AddFakeRequestReceived()
 105    {
 0106        string id1 = Random.Range(0, 1000000).ToString();
 0107        UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel()
 108        {
 109            userId = id1,
 110            name = "Pravus-" + id1
 111        });
 112
 0113        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 114        {
 115            userId = id1,
 116            action = FriendshipAction.REQUESTED_FROM
 117        });
 0118    }
 119
 120    [ContextMenu("AddFakeRequestSent")]
 121    public void AddFakeRequestSent()
 122    {
 0123        string id1 = Random.Range(0, 1000000).ToString();
 124
 0125        UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel()
 126        {
 127            userId = id1,
 128            name = "Brian-" + id1
 129        });
 130
 0131        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 132        {
 133            userId = id1,
 134            action = FriendshipAction.REQUESTED_TO
 135        });
 0136    }
 137
 138    [ContextMenu("AddFakeRequestSentAccepted")]
 139    public void AddFakeRequestSentAccepted()
 140    {
 0141        string id1 = Random.Range(0, 1000000).ToString();
 142
 0143        UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel()
 144        {
 145            userId = id1,
 146            name = "Brian-" + id1
 147        });
 148
 0149        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 150        {
 151            userId = id1,
 152            action = FriendshipAction.REQUESTED_TO
 153        });
 154
 0155        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 156        {
 157            userId = id1,
 158            action = FriendshipAction.APPROVED
 159        });
 0160    }
 161
 162    [ContextMenu("AddFakeOnlineFriend")]
 163    public void AddFakeOnlineFriend()
 164    {
 0165        string id1 = Random.Range(0, 1000000).ToString();
 166
 0167        UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel()
 168        {
 169            userId = id1,
 170            name = "Brian-" + id1
 171        });
 172
 0173        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 174        {
 175            userId = id1,
 176            action = FriendshipAction.APPROVED
 177        });
 178
 0179        FriendsController.i.UpdateUserStatus(new FriendsController.UserStatus()
 180            { userId = id1, presence = PresenceStatus.ONLINE });
 0181    }
 182
 183    [ContextMenu("AddFakeOfflineFriend")]
 184    public void AddFakeOfflineFriend()
 185    {
 0186        string id1 = Random.Range(0, 1000000).ToString();
 187
 0188        UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel()
 189        {
 190            userId = id1,
 191            name = "Pravus-" + id1
 192        });
 193
 0194        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 195        {
 196            userId = id1,
 197            action = FriendshipAction.APPROVED
 198        });
 199
 0200        FriendsController.i.UpdateUserStatus(new FriendsController.UserStatus()
 201            { userId = id1, presence = PresenceStatus.OFFLINE });
 0202    }
 203#endif
 204}