< Summary

Class:DCL.Social.Friends.FriendsHUDComponentView
Assembly:FriendsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDComponentView.cs
Covered lines:44
Uncovered lines:63
Coverable lines:107
Total lines:267
Line coverage:41.1% (44 of 107)
Covered branches:0
Total branches:0
Covered methods:30
Total methods:53
Method coverage:56.6% (30 of 53)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnFriendRequestApproved(...)0%110100%
remove_OnFriendRequestApproved(...)0%110100%
add_OnCancelConfirmation(...)0%110100%
remove_OnCancelConfirmation(...)0%110100%
add_OnRejectConfirmation(...)0%110100%
remove_OnRejectConfirmation(...)0%110100%
add_OnFriendRequestSent(...)0%110100%
remove_OnFriendRequestSent(...)0%110100%
add_OnFriendRequestOpened(...)0%110100%
remove_OnFriendRequestOpened(...)0%110100%
add_OnWhisper(...)0%110100%
remove_OnWhisper(...)0%110100%
add_OnRequireMoreFriends(...)0%110100%
remove_OnRequireMoreFriends(...)0%110100%
add_OnRequireMoreFriendRequests(...)0%110100%
remove_OnRequireMoreFriendRequests(...)0%110100%
add_OnSearchFriendsRequested(...)0%110100%
remove_OnSearchFriendsRequested(...)0%110100%
Initialize(...)0%110100%
RefreshFriendsTab()0%110100%
Awake()0%110100%
HideLoadingSpinner()0%2100%
ShowLoadingSpinner()0%110100%
GetEntry(...)0%6200%
DisplayFriendUserNotFound()0%2100%
Show()0%110100%
Hide()0%2100%
Set(...)0%2100%
Remove(...)0%2100%
Set(...)0%2100%
IsActive()0%110100%
ShowRequestSendError(...)0%12300%
ShowRequestSendSuccess()0%2100%
ShowMoreFriendsToLoadHint(...)0%2100%
HideMoreFriendsToLoadHint()0%110100%
ShowMoreRequestsToLoadHint(...)0%2100%
HideMoreRequestsToLoadHint()0%110100%
ContainsFriend(...)0%2100%
ContainsFriendRequest(...)0%2100%
EnableSearchMode()0%2100%
DisableSearchMode()0%2100%
UpdateBlockStatus(...)0%2100%
ClearAll()0%110100%
RefreshControl()0%12300%
FocusTab(...)0%30500%
UpdateBlockStatus(...)0%6200%

File(s)

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

#LineLine coverage
 1using SocialFeaturesAnalytics;
 2using System;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6namespace DCL.Social.Friends
 7{
 8    public class FriendsHUDComponentView : BaseComponentView, IFriendsHUDComponentView
 9    {
 10        private const int FRIENDS_LIST_TAB_INDEX = 0;
 11        private const int FRIENDS_REQUEST_TAB_INDEX = 1;
 12
 13        [SerializeField] internal GameObject loadingSpinner;
 14        [SerializeField] internal Button closeButton;
 15        [SerializeField] internal Button friendsTabFocusButton;
 16        [SerializeField] internal Button friendRequestsTabFocusButton;
 17        [SerializeField] internal FriendsTabComponentView friendsTab;
 18        [SerializeField] internal FriendRequestsTabComponentView friendRequestsTab;
 19        [SerializeField] private Model model;
 20
 21        public event Action<FriendRequestEntryModel> OnFriendRequestApproved
 22        {
 123            add => friendRequestsTab.OnFriendRequestApproved += value;
 124            remove => friendRequestsTab.OnFriendRequestApproved -= value;
 25        }
 26
 27        public event Action<FriendRequestEntryModel> OnCancelConfirmation
 28        {
 129            add => friendRequestsTab.OnCancelConfirmation += value;
 130            remove => friendRequestsTab.OnCancelConfirmation -= value;
 31        }
 32
 33        public event Action<FriendRequestEntryModel> OnRejectConfirmation
 34        {
 135            add => friendRequestsTab.OnRejectConfirmation += value;
 136            remove => friendRequestsTab.OnRejectConfirmation -= value;
 37        }
 38
 39        public event Action<string> OnFriendRequestSent
 40        {
 141            add => friendRequestsTab.OnFriendRequestSent += value;
 142            remove => friendRequestsTab.OnFriendRequestSent -= value;
 43        }
 44
 45        public event Action<string> OnFriendRequestOpened
 46        {
 147            add => friendRequestsTab.OnFriendRequestOpened += value;
 148            remove => friendRequestsTab.OnFriendRequestOpened -= value;
 49        }
 50
 51        public event Action<FriendEntryModel> OnWhisper
 52        {
 153            add => friendsTab.OnWhisper += value;
 154            remove => friendsTab.OnWhisper -= value;
 55        }
 56
 57        public event Action OnRequireMoreFriends
 58        {
 159            add => friendsTab.OnRequireMoreEntries += value;
 160            remove => friendsTab.OnRequireMoreEntries -= value;
 61        }
 62
 63        public event Action OnRequireMoreFriendRequests
 64        {
 165            add => friendRequestsTab.OnRequireMoreEntries += value;
 166            remove => friendRequestsTab.OnRequireMoreEntries -= value;
 67        }
 68
 69        public event Action<string> OnSearchFriendsRequested
 70        {
 171            add => friendsTab.OnSearchRequested += value;
 172            remove => friendsTab.OnSearchRequested -= value;
 73        }
 74
 75        public event Action OnFriendListDisplayed;
 76        public event Action OnRequestListDisplayed;
 77
 78        public event Action OnClose;
 79
 280        public RectTransform Transform => transform as RectTransform;
 81
 182        public int FriendCount => friendsTab.Count;
 083        public int FriendRequestCount => friendRequestsTab.Count;
 084        public int FriendRequestSentCount => friendRequestsTab.SentCount;
 085        public int FriendRequestReceivedCount => friendRequestsTab.ReceivedCount;
 186        public bool IsFriendListActive => friendsTab.gameObject.activeInHierarchy;
 087        public bool IsRequestListActive => friendRequestsTab.gameObject.activeInHierarchy;
 88
 89        public void Initialize(IChatController chatController,
 90            IFriendsController friendsController,
 91            ISocialAnalytics socialAnalytics)
 92        {
 193            friendsTab.Initialize(chatController, friendsController, socialAnalytics);
 194        }
 95
 96        public void RefreshFriendsTab()
 97        {
 198            friendsTab.RefreshControl();
 199        }
 100
 101        public override void Awake()
 102        {
 1103            base.Awake();
 104
 1105            friendsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_LIST_TAB_INDEX));
 1106            friendRequestsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_REQUEST_TAB_INDEX));
 1107            closeButton.onClick.AddListener(() =>
 108            {
 0109                OnClose?.Invoke();
 0110                Hide();
 0111            });
 112
 1113            friendRequestsTab.Expand();
 1114        }
 115
 116        public void HideLoadingSpinner()
 117        {
 0118            loadingSpinner.SetActive(false);
 0119            model.isLoadingSpinnerActive = false;
 0120        }
 121
 122        public void ShowLoadingSpinner()
 123        {
 1124            loadingSpinner.SetActive(true);
 1125            model.isLoadingSpinnerActive = true;
 1126        }
 127
 128        public FriendEntryBase GetEntry(string userId)
 129        {
 0130            return (FriendEntryBase) friendsTab.Get(userId) ?? friendRequestsTab.Get(userId);
 131        }
 132
 0133        public void DisplayFriendUserNotFound() => friendRequestsTab.ShowUserNotFoundNotification();
 134
 135        public void Show()
 136        {
 1137            model.visible = true;
 1138            gameObject.SetActive(true);
 1139            AudioScriptableObjects.dialogOpen.Play(true);
 1140        }
 141
 142        public void Hide()
 143        {
 0144            model.visible = false;
 0145            gameObject.SetActive(false);
 0146            AudioScriptableObjects.dialogClose.Play(true);
 0147        }
 148
 149        public void Set(string userId, FriendEntryModel model)
 150        {
 0151            friendRequestsTab.Remove(userId);
 0152            friendsTab.Enqueue(userId, model);
 0153        }
 154
 155        public void Remove(string userId)
 156        {
 0157            friendRequestsTab.Remove(userId);
 0158            friendsTab.Remove(userId);
 0159        }
 160
 161        public void Set(string userId, FriendRequestEntryModel model)
 162        {
 0163            friendRequestsTab.Enqueue(userId, model);
 0164            friendsTab.Remove(userId);
 0165        }
 166
 1167        public bool IsActive() => gameObject.activeInHierarchy;
 168
 169        public void ShowRequestSendError(FriendRequestError error)
 170        {
 171            switch (error)
 172            {
 173                case FriendRequestError.AlreadyFriends:
 0174                    friendRequestsTab.ShowAlreadyFriendsNotification();
 0175                    break;
 176                case FriendRequestError.UserNotFound:
 0177                    friendRequestsTab.ShowUserNotFoundNotification();
 178                    break;
 179            }
 0180        }
 181
 182        public void ShowRequestSendSuccess()
 183        {
 0184            friendRequestsTab.ShowRequestSuccessfullySentNotification();
 0185        }
 186
 0187        public void ShowMoreFriendsToLoadHint(int hiddenCount) => friendsTab.ShowMoreFriendsToLoadHint(hiddenCount);
 188
 1189        public void HideMoreFriendsToLoadHint() => friendsTab.HideMoreFriendsToLoadHint();
 190
 191        public void ShowMoreRequestsToLoadHint(int hiddenCount) =>
 0192            friendRequestsTab.ShowMoreEntriesToLoadHint(hiddenCount);
 193
 1194        public void HideMoreRequestsToLoadHint() => friendRequestsTab.HideMoreFriendsToLoadHint();
 195
 0196        public bool ContainsFriend(string userId) => friendsTab.Get(userId) != null;
 197
 0198        public bool ContainsFriendRequest(string userId) => friendRequestsTab.Get(userId) != null;
 199
 0200        public void EnableSearchMode() => friendsTab.EnableSearchMode();
 201
 0202        public void DisableSearchMode() => friendsTab.DisableSearchMode();
 203
 204        public void UpdateBlockStatus(string userId, bool blocked)
 205        {
 0206            UpdateBlockStatus(blocked, friendsTab.Get(userId));
 0207            UpdateBlockStatus(blocked, friendRequestsTab.Get(userId));
 0208        }
 209
 210        public void ClearAll()
 211        {
 1212            friendsTab.Clear();
 1213            friendRequestsTab.Clear();
 1214        }
 215
 216        public override void RefreshControl()
 217        {
 0218            if (model.isLoadingSpinnerActive)
 0219                ShowLoadingSpinner();
 220            else
 0221                HideLoadingSpinner();
 222
 0223            if (model.visible)
 0224                Show();
 225            else
 0226                Hide();
 227
 0228            FocusTab(model.focusedTabIndex);
 0229        }
 230
 231        internal void FocusTab(int index)
 232        {
 0233            model.focusedTabIndex = index;
 234
 0235            if (index == FRIENDS_LIST_TAB_INDEX)
 236            {
 0237                friendsTab.Show();
 0238                friendRequestsTab.Hide();
 0239                OnFriendListDisplayed?.Invoke();
 240            }
 0241            else if (index == FRIENDS_REQUEST_TAB_INDEX)
 242            {
 0243                friendsTab.Hide();
 0244                friendRequestsTab.Show();
 0245                OnRequestListDisplayed?.Invoke();
 246            }
 247            else
 0248                throw new IndexOutOfRangeException();
 249        }
 250
 251        private void UpdateBlockStatus(bool blocked, FriendEntryBase friendEntry)
 252        {
 0253            if (friendEntry == null) return;
 0254            var friendModel = friendEntry.Model;
 0255            friendModel.blocked = blocked;
 0256            friendEntry.RefreshControl();
 0257        }
 258
 259        [Serializable]
 260        private struct Model
 261        {
 262            public int focusedTabIndex;
 263            public bool isLoadingSpinnerActive;
 264            public bool visible;
 265        }
 266    }
 267}

Methods/Properties

add_OnFriendRequestApproved(System.Action[FriendRequestEntryModel])
remove_OnFriendRequestApproved(System.Action[FriendRequestEntryModel])
add_OnCancelConfirmation(System.Action[FriendRequestEntryModel])
remove_OnCancelConfirmation(System.Action[FriendRequestEntryModel])
add_OnRejectConfirmation(System.Action[FriendRequestEntryModel])
remove_OnRejectConfirmation(System.Action[FriendRequestEntryModel])
add_OnFriendRequestSent(System.Action[String])
remove_OnFriendRequestSent(System.Action[String])
add_OnFriendRequestOpened(System.Action[String])
remove_OnFriendRequestOpened(System.Action[String])
add_OnWhisper(System.Action[FriendEntryModel])
remove_OnWhisper(System.Action[FriendEntryModel])
add_OnRequireMoreFriends(System.Action)
remove_OnRequireMoreFriends(System.Action)
add_OnRequireMoreFriendRequests(System.Action)
remove_OnRequireMoreFriendRequests(System.Action)
add_OnSearchFriendsRequested(System.Action[String])
remove_OnSearchFriendsRequested(System.Action[String])
Transform()
FriendCount()
FriendRequestCount()
FriendRequestSentCount()
FriendRequestReceivedCount()
IsFriendListActive()
IsRequestListActive()
Initialize(IChatController, DCL.Social.Friends.IFriendsController, SocialFeaturesAnalytics.ISocialAnalytics)
RefreshFriendsTab()
Awake()
HideLoadingSpinner()
ShowLoadingSpinner()
GetEntry(System.String)
DisplayFriendUserNotFound()
Show()
Hide()
Set(System.String, FriendEntryModel)
Remove(System.String)
Set(System.String, FriendRequestEntryModel)
IsActive()
ShowRequestSendError(FriendRequestError)
ShowRequestSendSuccess()
ShowMoreFriendsToLoadHint(System.Int32)
HideMoreFriendsToLoadHint()
ShowMoreRequestsToLoadHint(System.Int32)
HideMoreRequestsToLoadHint()
ContainsFriend(System.String)
ContainsFriendRequest(System.String)
EnableSearchMode()
DisableSearchMode()
UpdateBlockStatus(System.String, System.Boolean)
ClearAll()
RefreshControl()
FocusTab(System.Int32)
UpdateBlockStatus(System.Boolean, FriendEntryBase)