< Summary

Class:DCL.MyAccount.MyProfileLinkListComponentView
Assembly:MyAccountHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/MyAccountHUD/MyProfileLinkListComponentView.cs
Covered lines:0
Uncovered lines:29
Coverable lines:29
Total lines:82
Line coverage:0% (0 of 29)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MyProfileLinkListComponentView()0%2100%
Awake()0%2100%
Add(...)0%2100%
Clear()0%6200%
ClearInput()0%2100%
EnableOrDisableAddNewLinkOption(...)0%2100%
EnableOrDisableAddButton()0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/MyAccountHUD/MyProfileLinkListComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.Networking;
 6using UnityEngine.UI;
 7
 8namespace DCL.MyAccount
 9{
 10    public class MyProfileLinkListComponentView : MonoBehaviour
 11    {
 12        [SerializeField] private Button addButton;
 13        [SerializeField] private TMP_InputField newLinkTitle;
 14        [SerializeField] private TMP_InputField newLinkUrl;
 15        [SerializeField] private MyProfileLinkComponentView linkPrefab;
 16        [SerializeField] private RectTransform linksContainer;
 17
 018        private readonly List<MyProfileLinkComponentView> links = new ();
 19
 020        private bool isAddEnabled = true;
 21
 22        public event Action<(string title, string url)> OnAddedNew;
 23        public event Action<(string title, string url)> OnRemoved;
 24
 25        private void Awake()
 26        {
 027            addButton.onClick.AddListener(() =>
 28            {
 029                if (!newLinkUrl.text.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
 30                    && !newLinkUrl.text.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
 031                    newLinkUrl.text = $"https://{newLinkUrl.text}";
 32
 033                OnAddedNew?.Invoke((
 34                    title: newLinkTitle.text,
 35                    url: newLinkUrl.text));
 036            });
 37
 038            newLinkTitle.onValueChanged.AddListener(str => EnableOrDisableAddButton());
 039            newLinkUrl.onValueChanged.AddListener(str => EnableOrDisableAddButton());
 40
 041            EnableOrDisableAddButton();
 042        }
 43
 44        public void Add(string title, string url)
 45        {
 046            MyProfileLinkComponentView linkComponent = Instantiate(linkPrefab, linksContainer);
 047            linkComponent.Set(title, UnityWebRequest.UnEscapeURL(url));
 048            linkComponent.OnRemoved += OnRemoved;
 049            links.Add(linkComponent);
 050        }
 51
 52        public void Clear()
 53        {
 054            foreach (MyProfileLinkComponentView linkComponent in links)
 55            {
 056                linkComponent.OnRemoved -= OnRemoved;
 057                Destroy(linkComponent.gameObject);
 58            }
 59
 060            links.Clear();
 061        }
 62
 63        public void ClearInput()
 64        {
 065            newLinkTitle.text = "";
 066            newLinkUrl.text = "";
 067        }
 68
 69        public void EnableOrDisableAddNewLinkOption(bool enabled)
 70        {
 071            isAddEnabled = enabled;
 072            EnableOrDisableAddButton();
 073        }
 74
 75        private void EnableOrDisableAddButton()
 76        {
 077            addButton.interactable = newLinkTitle.text.Length > 0 && newLinkUrl.text.Length > 0
 78                                                                  && LinkValidator.IsValid(newLinkUrl.text)
 79                                                                  && isAddEnabled;
 080        }
 81    }
 82}