< Summary

Class:FriendRequestEntry
Assembly:FriendsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/Entries/FriendRequestEntry.cs
Covered lines:43
Uncovered lines:9
Coverable lines:52
Total lines:110
Line coverage:82.6% (43 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Populate(...)0%110100%
Populate(...)0%6200%
SetBodyMessage(...)0%2.032080%
SetRequestDate(...)0%2.062075%
SetReceived(...)0%220100%
PopulateReceived()0%110100%
PopulateSent()0%110100%
SetShortcutButtonsActive(...)0%330100%

File(s)

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

#LineLine coverage
 1using DCL.Helpers;
 2using System;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public class FriendRequestEntry : FriendEntryBase
 8{
 9    [SerializeField] internal TMP_Text bodyMessage;
 10    [SerializeField] internal TMP_Text requestDate;
 11    [SerializeField] internal GameObject shortcutButtonsContainer;
 12    [SerializeField] internal Button acceptButton;
 13    [SerializeField] internal Button rejectButton;
 14    [SerializeField] internal Button cancelButton;
 15    [SerializeField] internal Button openButton;
 16
 3617    public bool isReceived { get; private set; }
 18
 19    public event Action<FriendRequestEntry> OnAccepted;
 20    public event Action<FriendRequestEntry> OnRejected;
 21    public event Action<FriendRequestEntry> OnCancelled;
 22    public event Action<FriendRequestEntry> OnOpened;
 23
 24    public override void Awake()
 25    {
 1726        base.Awake();
 27
 1728        acceptButton.onClick.RemoveAllListeners();
 1729        rejectButton.onClick.RemoveAllListeners();
 1730        cancelButton.onClick.RemoveAllListeners();
 1831        acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this));
 1832        rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this));
 1833        cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this));
 1734        openButton.onClick.AddListener(() => OnOpened?.Invoke(this));
 1735    }
 36
 37    public void Populate(FriendRequestEntryModel model)
 38    {
 1239        base.Populate(model);
 1240        SetBodyMessage(model.bodyMessage);
 1241        SetRequestDate(model.timestamp);
 1242        SetReceived(model.isReceived);
 1243        SetShortcutButtonsActive(model.isShortcutButtonsActive);
 1244    }
 45
 46    public override void Populate(FriendEntryModel model)
 47    {
 048        base.Populate(model);
 49
 050        if (model is FriendRequestEntryModel requestModel)
 51        {
 052            SetBodyMessage(requestModel.bodyMessage);
 053            SetRequestDate(requestModel.timestamp);
 054            SetReceived(requestModel.isReceived);
 055            SetShortcutButtonsActive(requestModel.isShortcutButtonsActive);
 56        }
 057    }
 58
 59    private void SetBodyMessage(string value)
 60    {
 1261        if (bodyMessage == null)
 062            return;
 63
 1264        bodyMessage.text = value;
 1265        bodyMessage.gameObject.SetActive(!string.IsNullOrEmpty(value));
 1266    }
 67
 68    private void SetRequestDate(long value)
 69    {
 1270        if (requestDate == null)
 071            return;
 72
 1273        requestDate.text = Utils.UnixToDateTimeWithTime((ulong)value).ToString("MMM dd").ToUpper();
 1274    }
 75
 76    private void SetReceived(bool value)
 77    {
 1278        isReceived = value;
 79
 1280        if (isReceived)
 581            PopulateReceived();
 82        else
 783            PopulateSent();
 784    }
 85
 86    private void PopulateReceived()
 87    {
 588        isReceived = true;
 589        cancelButton.gameObject.SetActive(false);
 590        acceptButton.gameObject.SetActive(true);
 591        rejectButton.gameObject.SetActive(true);
 592    }
 93
 94    private void PopulateSent()
 95    {
 796        isReceived = false;
 797        cancelButton.gameObject.SetActive(true);
 798        acceptButton.gameObject.SetActive(false);
 799        rejectButton.gameObject.SetActive(false);
 7100    }
 101
 102    private void SetShortcutButtonsActive(bool isActive)
 103    {
 12104        if (shortcutButtonsContainer != null)
 12105            shortcutButtonsContainer.SetActive(isActive);
 106
 12107        if (requestDate != null)
 12108            requestDate.gameObject.SetActive(!isActive);
 12109    }
 110}