< Summary

Class:DCL.Chat.HUD.CreateChannelWindowComponentView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/CreateChannelWindowComponentView.cs
Covered lines:54
Uncovered lines:23
Coverable lines:77
Total lines:147
Line coverage:70.1% (54 of 77)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%110100%
Awake()0%220100%
RefreshControl()0%2100%
Show()0%110100%
Hide()0%110100%
ShowChannelExistsError(...)0%110100%
ClearError()0%110100%
DisableCreateButton()0%110100%
EnableCreateButton()0%110100%
ClearInputText()0%110100%
FocusInputField()0%110100%
ShowWrongFormatError()0%110100%
ShowTooShortError()0%2100%
ShowChannelsExceededError()0%110100%
ShowUnknownError()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/CreateChannelWindowComponentView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6namespace DCL.Chat.HUD
 7{
 8    public class CreateChannelWindowComponentView : BaseComponentView, ICreateChannelWindowView
 9    {
 10        [SerializeField] internal Button createButton;
 11        [SerializeField] internal Button[] closeButtons;
 12        [SerializeField] internal Button joinButton;
 13        [SerializeField] internal TMP_InputField channelNameInput;
 14        [SerializeField] internal GameObject channelExistsContainer;
 15        [SerializeField] internal GameObject channelExistsWithJoinOptionContainer;
 16        [SerializeField] internal GameObject specialCharactersErrorContainer;
 17        [SerializeField] internal GameObject tooShortErrorContainer;
 18        [SerializeField] internal GameObject exceededLimitErrorContainer;
 19        [SerializeField] internal GameObject unknownErrorContainer;
 20        [SerializeField] internal TMP_Text channelNameLengthLabel;
 21        [SerializeField] internal GameObject inputFieldErrorBevel;
 22        [SerializeField] internal Color errorColor;
 23
 24        private Color lengthLabelOriginalColor;
 25
 26        public event Action<string> OnChannelNameUpdated;
 27        public event Action OnCreateSubmit;
 28        public event Action OnClose;
 29        public event Action OnJoinChannel;
 30
 31        public static CreateChannelWindowComponentView Create()
 32        {
 1633            return Instantiate(Resources.Load<CreateChannelWindowComponentView>("SocialBarV1/ChannelCreationHUD"));
 34        }
 35
 36        public override void Awake()
 37        {
 1638            base.Awake();
 39
 1740            createButton.onClick.AddListener(() => OnCreateSubmit?.Invoke());
 1641            channelNameInput.onValueChanged.AddListener(text =>
 42            {
 343                channelNameLengthLabel.text = $"{Mathf.Min(20, text.Length)}/20";
 344                OnChannelNameUpdated?.Invoke(text);
 045            });
 1646            channelNameInput.onSubmit.AddListener(text =>
 47            {
 048                OnCreateSubmit?.Invoke();
 049            });
 9650            foreach (var button in closeButtons)
 3351                button.onClick.AddListener(() => OnClose?.Invoke());
 1752            joinButton.onClick.AddListener(() => OnJoinChannel?.Invoke());
 1653            lengthLabelOriginalColor = channelNameLengthLabel.color;
 1654        }
 55
 56        public override void RefreshControl()
 57        {
 058            throw new NotImplementedException();
 59        }
 60
 061        public RectTransform Transform => (RectTransform) transform;
 62
 263        public void Show() => gameObject.SetActive(true);
 64
 265        public void Hide() => gameObject.SetActive(false);
 66
 67        public void ShowChannelExistsError(bool showJoinChannelOption)
 68        {
 269            channelExistsContainer.SetActive(!showJoinChannelOption);
 270            channelExistsWithJoinOptionContainer.SetActive(showJoinChannelOption);
 271            inputFieldErrorBevel.SetActive(true);
 272            specialCharactersErrorContainer.SetActive(false);
 273            tooShortErrorContainer.SetActive(false);
 274            exceededLimitErrorContainer.SetActive(false);
 275            unknownErrorContainer.SetActive(false);
 276            channelNameLengthLabel.color = errorColor;
 277        }
 78
 79        public void ClearError()
 80        {
 281            channelExistsContainer.SetActive(false);
 282            channelExistsWithJoinOptionContainer.SetActive(false);
 283            inputFieldErrorBevel.SetActive(false);
 284            specialCharactersErrorContainer.SetActive(false);
 285            tooShortErrorContainer.SetActive(false);
 286            exceededLimitErrorContainer.SetActive(false);
 287            unknownErrorContainer.SetActive(false);
 288            channelNameLengthLabel.color = lengthLabelOriginalColor;
 289        }
 90
 291        public void DisableCreateButton() => createButton.interactable = false;
 92
 293        public void EnableCreateButton() => createButton.interactable = true;
 94
 195        public void ClearInputText() => channelNameInput.text = "";
 96
 197        public void FocusInputField() => channelNameInput.Select();
 98
 99        public void ShowWrongFormatError()
 100        {
 1101            channelExistsContainer.SetActive(false);
 1102            channelExistsWithJoinOptionContainer.SetActive(false);
 1103            inputFieldErrorBevel.SetActive(true);
 1104            specialCharactersErrorContainer.SetActive(true);
 1105            tooShortErrorContainer.SetActive(false);
 1106            exceededLimitErrorContainer.SetActive(false);
 1107            unknownErrorContainer.SetActive(false);
 1108            channelNameLengthLabel.color = errorColor;
 1109        }
 110
 111        public void ShowTooShortError()
 112        {
 0113            channelExistsContainer.SetActive(false);
 0114            channelExistsWithJoinOptionContainer.SetActive(false);
 0115            inputFieldErrorBevel.SetActive(true);
 0116            specialCharactersErrorContainer.SetActive(false);
 0117            tooShortErrorContainer.SetActive(true);
 0118            exceededLimitErrorContainer.SetActive(false);
 0119            unknownErrorContainer.SetActive(false);
 0120            channelNameLengthLabel.color = errorColor;
 0121        }
 122
 123        public void ShowChannelsExceededError()
 124        {
 1125            channelExistsContainer.SetActive(false);
 1126            channelExistsWithJoinOptionContainer.SetActive(false);
 1127            inputFieldErrorBevel.SetActive(true);
 1128            specialCharactersErrorContainer.SetActive(false);
 1129            tooShortErrorContainer.SetActive(false);
 1130            exceededLimitErrorContainer.SetActive(true);
 1131            unknownErrorContainer.SetActive(false);
 1132            channelNameLengthLabel.color = errorColor;
 1133        }
 134
 135        public void ShowUnknownError()
 136        {
 0137            channelExistsContainer.SetActive(false);
 0138            channelExistsWithJoinOptionContainer.SetActive(false);
 0139            inputFieldErrorBevel.SetActive(true);
 0140            specialCharactersErrorContainer.SetActive(false);
 0141            tooShortErrorContainer.SetActive(false);
 0142            exceededLimitErrorContainer.SetActive(false);
 0143            unknownErrorContainer.SetActive(true);
 0144            channelNameLengthLabel.color = errorColor;
 0145        }
 146    }
 147}