< 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:111
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 System.Globalization;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8public class FriendRequestEntry : FriendEntryBase
 9{
 10    [SerializeField] internal TMP_Text bodyMessage;
 11    [SerializeField] internal TMP_Text requestDate;
 12    [SerializeField] internal GameObject shortcutButtonsContainer;
 13    [SerializeField] internal Button acceptButton;
 14    [SerializeField] internal Button rejectButton;
 15    [SerializeField] internal Button cancelButton;
 16    [SerializeField] internal Button openButton;
 17
 3618    public bool isReceived { get; private set; }
 19
 20    public event Action<FriendRequestEntry> OnAccepted;
 21    public event Action<FriendRequestEntry> OnRejected;
 22    public event Action<FriendRequestEntry> OnCancelled;
 23    public event Action<FriendRequestEntry> OnOpened;
 24
 25    public override void Awake()
 26    {
 1727        base.Awake();
 28
 1729        acceptButton.onClick.RemoveAllListeners();
 1730        rejectButton.onClick.RemoveAllListeners();
 1731        cancelButton.onClick.RemoveAllListeners();
 1832        acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this));
 1833        rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this));
 1834        cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this));
 1735        openButton.onClick.AddListener(() => OnOpened?.Invoke(this));
 1736    }
 37
 38    public void Populate(FriendRequestEntryModel model)
 39    {
 1240        base.Populate(model);
 1241        SetBodyMessage(model.bodyMessage);
 1242        SetRequestDate(model.timestamp);
 1243        SetReceived(model.isReceived);
 1244        SetShortcutButtonsActive(model.isShortcutButtonsActive);
 1245    }
 46
 47    public override void Populate(FriendEntryModel model)
 48    {
 049        base.Populate(model);
 50
 051        if (model is FriendRequestEntryModel requestModel)
 52        {
 053            SetBodyMessage(requestModel.bodyMessage);
 054            SetRequestDate(requestModel.timestamp);
 055            SetReceived(requestModel.isReceived);
 056            SetShortcutButtonsActive(requestModel.isShortcutButtonsActive);
 57        }
 058    }
 59
 60    private void SetBodyMessage(string value)
 61    {
 1262        if (bodyMessage == null)
 063            return;
 64
 1265        bodyMessage.text = value;
 1266        bodyMessage.gameObject.SetActive(!string.IsNullOrEmpty(value));
 1267    }
 68
 69    private void SetRequestDate(long value)
 70    {
 1271        if (requestDate == null)
 072            return;
 73
 1274        requestDate.text = Utils.UnixToDateTimeWithTime((ulong)value).ToString("MMM dd", new CultureInfo("en-US")).ToUpp
 1275    }
 76
 77    private void SetReceived(bool value)
 78    {
 1279        isReceived = value;
 80
 1281        if (isReceived)
 582            PopulateReceived();
 83        else
 784            PopulateSent();
 785    }
 86
 87    private void PopulateReceived()
 88    {
 589        isReceived = true;
 590        cancelButton.gameObject.SetActive(false);
 591        acceptButton.gameObject.SetActive(true);
 592        rejectButton.gameObject.SetActive(true);
 593    }
 94
 95    private void PopulateSent()
 96    {
 797        isReceived = false;
 798        cancelButton.gameObject.SetActive(true);
 799        acceptButton.gameObject.SetActive(false);
 7100        rejectButton.gameObject.SetActive(false);
 7101    }
 102
 103    private void SetShortcutButtonsActive(bool isActive)
 104    {
 12105        if (shortcutButtonsContainer != null)
 12106            shortcutButtonsContainer.SetActive(isActive);
 107
 12108        if (requestDate != null)
 12109            requestDate.gameObject.SetActive(!isActive);
 12110    }
 111}