< 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:0
Uncovered lines:53
Coverable lines:53
Total lines:111
Line coverage:0% (0 of 53)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:11
Method coverage:0% (0 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
Populate(...)0%2100%
Populate(...)0%6200%
SetBodyMessage(...)0%6200%
SetRequestDate(...)0%6200%
SetReceived(...)0%6200%
PopulateReceived()0%2100%
PopulateSent()0%2100%
SetShortcutButtonsActive(...)0%12300%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Globalization;
 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
 017    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    {
 026        base.Awake();
 27
 028        acceptButton.onClick.RemoveAllListeners();
 029        rejectButton.onClick.RemoveAllListeners();
 030        cancelButton.onClick.RemoveAllListeners();
 031        acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this));
 032        rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this));
 033        cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this));
 034        openButton.onClick.AddListener(() => OnOpened?.Invoke(this));
 035    }
 36
 37    public void Populate(FriendRequestEntryModel model)
 38    {
 039        base.Populate(model);
 040        SetBodyMessage(model.bodyMessage);
 041        SetRequestDate(model.timestamp);
 042        SetReceived(model.isReceived);
 043        SetShortcutButtonsActive(model.isShortcutButtonsActive);
 044    }
 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    {
 061        if (bodyMessage == null)
 062            return;
 63
 064        bodyMessage.text = value;
 065        bodyMessage.gameObject.SetActive(!string.IsNullOrEmpty(value));
 066    }
 67
 68    private void SetRequestDate(DateTime value)
 69    {
 070        if (requestDate == null)
 071            return;
 72
 073        DateTime localTime = value.ToLocalTime();
 074        requestDate.text = localTime.ToString("MMM dd", new CultureInfo("en-US")).ToUpper();
 075    }
 76
 77    private void SetReceived(bool value)
 78    {
 079        isReceived = value;
 80
 081        if (isReceived)
 082            PopulateReceived();
 83        else
 084            PopulateSent();
 085    }
 86
 87    private void PopulateReceived()
 88    {
 089        isReceived = true;
 090        cancelButton.gameObject.SetActive(false);
 091        acceptButton.gameObject.SetActive(true);
 092        rejectButton.gameObject.SetActive(true);
 093    }
 94
 95    private void PopulateSent()
 96    {
 097        isReceived = false;
 098        cancelButton.gameObject.SetActive(true);
 099        acceptButton.gameObject.SetActive(false);
 0100        rejectButton.gameObject.SetActive(false);
 0101    }
 102
 103    private void SetShortcutButtonsActive(bool isActive)
 104    {
 0105        if (shortcutButtonsContainer != null)
 0106            shortcutButtonsContainer.SetActive(isActive);
 107
 0108        if (requestDate != null)
 0109            requestDate.gameObject.SetActive(!isActive);
 0110    }
 111}