< Summary

Class:DCL.ContentModeration.ContentModerationReportingComponentView
Assembly:ContentModerationHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ContentModerationHUD/ContentModerationReportingComponentView.cs
Covered lines:0
Uncovered lines:133
Coverable lines:133
Total lines:305
Line coverage:0% (0 of 133)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:20
Method coverage:0% (0 of 20)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ContentModerationReportingComponentView()0%2100%
Awake()0%2100%
Dispose()0%2100%
RefreshControl()0%2100%
ShowPanel()0%2100%
HidePanel(...)0%20400%
SetScene(...)0%2100%
SetRatingAsMarked(...)0%30500%
SetRating(...)0%3421800%
SetLoadingState(...)0%2100%
SetPanelAsSent(...)0%2100%
ResetPanelState()0%2100%
CreateButtons()0%20400%
InstantiateOptionButton(...)0%2100%
InstantiateCommentsBox()0%2100%
ResetOptions()0%20400%
SetTitle()0%6200%
SetSendButtonInteractable(...)0%2100%
SendReport(...)0%6200%
GoToLearnMore()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ContentModerationHUD/ContentModerationReportingComponentView.cs

#LineLine coverage
 1using DCL.Controllers;
 2using System;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.ContentModeration
 9{
 10    public class ContentModerationReportingComponentView : BaseComponentView, IContentModerationReportingComponentView
 11    {
 12        [Header("REFERENCES")]
 13        [SerializeField] private TMP_Text titleText;
 14        [SerializeField] private Button backgroundButton;
 15        [SerializeField] private ButtonComponentView cancelButton;
 16        [SerializeField] private ButtonComponentView gotItButton1;
 17        [SerializeField] private ButtonComponentView gotItButton2;
 18        [SerializeField] private ButtonComponentView sendButton;
 19        [SerializeField] private Button learnMoreButton;
 20        [SerializeField] private ContentModerationRatingButtonComponentView teenRatingButton;
 21        [SerializeField] private ContentModerationRatingButtonComponentView adultRatingButton;
 22        [SerializeField] private ContentModerationRatingButtonComponentView restrictedRatingButton;
 23        [SerializeField] private GameObject optionsSectionContainer;
 24        [SerializeField] private TMP_Text optionsSectionTitle;
 25        [SerializeField] private TMP_Text optionsSectionSubtitle;
 26        [SerializeField] private GameObject markedRatingInfoContainer;
 27        [SerializeField] private TMP_Text markedRatingInfoTitle;
 28        [SerializeField] private TMP_Text markedRatingInfoDescription;
 29        [SerializeField] private Transform optionsContainer;
 30        [SerializeField] private ScrollRect optionsScroll;
 31        [SerializeField] private GameObject mainModal;
 32        [SerializeField] private GameObject mainFormSection;
 33        [SerializeField] private GameObject loadingStateSection;
 34        [SerializeField] private GameObject reportSentModal;
 35        [SerializeField] private Image modalHeaderImage;
 36
 37        [Header("TEEN CONFIGURATION")]
 38        [SerializeField] private Sprite teenHeaderSprite;
 39        [SerializeField] private string teenOptionTitle;
 40        [SerializeField] private string teenOptionSubtitle;
 41        [SerializeField] private List<string> teenOptions;
 42        [SerializeField] private string teenDescription;
 43
 44        [Header("ADULT CONFIGURATION")]
 45        [SerializeField] private Sprite adultHeaderSprite;
 46        [SerializeField] private string adultOptionTitle;
 47        [SerializeField] private string adultOptionSubtitle;
 48        [SerializeField] private List<string> adultOptions;
 49        [SerializeField] private string adultDescription;
 50
 51        [Header("RESTRICTED CONFIGURATION")]
 52        [SerializeField] private Sprite restrictedHeaderSprite;
 53        [SerializeField] private string restrictedOptionTitle;
 54        [SerializeField] private string restrictedOptionSubtitle;
 55        [SerializeField] private List<string> restrictedOptions;
 56        [SerializeField] private string restrictedDescription;
 57
 58        [Header("PREFABS")]
 59        [SerializeField] private GameObject optionButtonPrefab;
 60        [SerializeField] private GameObject commentsPrefab;
 61
 062        private readonly List<ContentModerationReportingOptionComponentView> teenOptionButtons = new ();
 063        private readonly List<ContentModerationReportingOptionComponentView> adultOptionButtons = new ();
 064        private readonly List<ContentModerationReportingOptionComponentView> restrictedOptionButtons = new ();
 65        private SceneContentCategory currentMarkedRating;
 66        private SceneContentCategory currentRating;
 067        private readonly List<string> selectedOptions = new ();
 68        private TMP_InputField commentsInput;
 69        private bool isLoadingActive;
 70        private string currentSceneName;
 71
 72        public event Action<bool> OnPanelClosed;
 73        public event Action<(SceneContentCategory contentCategory, List<string> issues, string comments)> OnSendClicked;
 74        public event Action OnLearnMoreClicked;
 75
 76        public override void Awake()
 77        {
 078            base.Awake();
 079            backgroundButton.onClick.AddListener(() => HidePanel(!reportSentModal.activeSelf));
 080            cancelButton.onClick.AddListener(() => HidePanel(true));
 081            gotItButton1.onClick.AddListener(() => HidePanel(false));
 082            gotItButton2.onClick.AddListener(() => HidePanel(false));
 083            sendButton.onClick.AddListener(() => SendReport((currentRating, selectedOptions, commentsInput.text)));
 084            learnMoreButton.onClick.AddListener(GoToLearnMore);
 085            teenRatingButton.RatingButton.onClick.AddListener(() => SetRating(SceneContentCategory.TEEN));
 086            adultRatingButton.RatingButton.onClick.AddListener(() => SetRating(SceneContentCategory.ADULT));
 087            restrictedRatingButton.RatingButton.onClick.AddListener(() => SetRating(SceneContentCategory.RESTRICTED));
 88
 089            CreateButtons();
 090        }
 91
 92        public override void Dispose()
 93        {
 094            backgroundButton.onClick.RemoveAllListeners();
 095            cancelButton.onClick.RemoveAllListeners();
 096            gotItButton1.onClick.RemoveAllListeners();
 097            gotItButton2.onClick.RemoveAllListeners();
 098            sendButton.onClick.RemoveAllListeners();
 099            learnMoreButton.onClick.RemoveAllListeners();
 0100            teenRatingButton.RatingButton.onClick.RemoveAllListeners();
 0101            adultRatingButton.RatingButton.onClick.RemoveAllListeners();
 0102            restrictedRatingButton.RatingButton.onClick.RemoveAllListeners();
 0103            base.Dispose();
 0104        }
 105
 0106        public override void RefreshControl() { }
 107
 108        public void ShowPanel()
 109        {
 0110            Show();
 0111            SetLoadingState(false);
 0112            SetPanelAsSent(false);
 0113            ResetOptions();
 0114        }
 115
 116        public void HidePanel(bool isCancelled)
 117        {
 0118            if (isLoadingActive || !isVisible)
 0119                return;
 120
 0121            Hide();
 0122            OnPanelClosed?.Invoke(isCancelled);
 0123        }
 124
 125        public void SetScene(string sceneName) =>
 0126            currentSceneName = sceneName;
 127
 128        public void SetRatingAsMarked(SceneContentCategory contentCategory)
 129        {
 0130            currentMarkedRating = contentCategory;
 131
 0132            modalHeaderImage.sprite = contentCategory switch
 133                                      {
 0134                                          SceneContentCategory.TEEN => teenHeaderSprite,
 0135                                          SceneContentCategory.ADULT => adultHeaderSprite,
 0136                                          SceneContentCategory.RESTRICTED => restrictedHeaderSprite,
 0137                                          _ => teenHeaderSprite,
 138                                      };
 139
 0140            teenRatingButton.SetCurrentMarkActive(contentCategory == SceneContentCategory.TEEN);
 0141            adultRatingButton.SetCurrentMarkActive(contentCategory == SceneContentCategory.ADULT);
 0142            restrictedRatingButton.SetCurrentMarkActive(contentCategory == SceneContentCategory.RESTRICTED);
 0143        }
 144
 145        public void SetRating(SceneContentCategory contentCategory)
 146        {
 0147            currentRating = contentCategory;
 148
 0149            selectedOptions.Clear();
 150
 0151            teenRatingButton.Select(contentCategory == SceneContentCategory.TEEN);
 0152            adultRatingButton.Select(contentCategory == SceneContentCategory.ADULT);
 0153            restrictedRatingButton.Select(contentCategory == SceneContentCategory.RESTRICTED);
 154
 0155            markedRatingInfoContainer.SetActive((contentCategory == SceneContentCategory.TEEN && teenRatingButton.IsMark
 156                                                (contentCategory == SceneContentCategory.ADULT && adultRatingButton.IsMa
 157                                                (contentCategory == SceneContentCategory.RESTRICTED && restrictedRatingB
 0158            optionsSectionContainer.SetActive((contentCategory == SceneContentCategory.TEEN && !teenRatingButton.IsMarke
 159                                              (contentCategory == SceneContentCategory.ADULT && !adultRatingButton.IsMar
 160                                              (contentCategory == SceneContentCategory.RESTRICTED && !restrictedRatingBu
 161
 0162            gotItButton1.gameObject.SetActive(markedRatingInfoContainer.activeSelf);
 0163            sendButton.gameObject.SetActive(!markedRatingInfoContainer.activeSelf);
 164
 165            switch (contentCategory)
 166            {
 167                default:
 168                case SceneContentCategory.TEEN:
 0169                    optionsSectionTitle.text = teenOptionTitle;
 0170                    optionsSectionSubtitle.text = teenOptionSubtitle;
 0171                    markedRatingInfoTitle.text = teenOptionTitle;
 0172                    markedRatingInfoDescription.text = teenDescription;
 0173                    break;
 174                case SceneContentCategory.ADULT:
 0175                    optionsSectionTitle.text = adultOptionTitle;
 0176                    optionsSectionSubtitle.text = adultOptionSubtitle;
 0177                    markedRatingInfoTitle.text = adultOptionTitle;
 0178                    markedRatingInfoDescription.text = adultDescription;
 0179                    break;
 180                case SceneContentCategory.RESTRICTED:
 0181                    optionsSectionTitle.text = restrictedOptionTitle;
 0182                    optionsSectionSubtitle.text = restrictedOptionSubtitle;
 0183                    markedRatingInfoTitle.text = restrictedOptionTitle;
 0184                    markedRatingInfoDescription.text = restrictedDescription;
 185                    break;
 186            }
 187
 0188            foreach (ContentModerationReportingOptionComponentView option in teenOptionButtons)
 0189                option.SetActive((int)contentCategory == 0);
 0190            foreach (ContentModerationReportingOptionComponentView option in adultOptionButtons)
 0191                option.SetActive((int)contentCategory == 1);
 0192            foreach (ContentModerationReportingOptionComponentView option in restrictedOptionButtons)
 0193                option.SetActive((int)contentCategory == 2);
 194
 0195            ResetOptions();
 0196            SetTitle();
 0197        }
 198
 199        public void SetLoadingState(bool isLoading)
 200        {
 0201            mainFormSection.SetActive(!isLoading);
 0202            loadingStateSection.SetActive(isLoading);
 0203            isLoadingActive = isLoading;
 0204        }
 205
 206        public void SetPanelAsSent(bool hasBeenSent)
 207        {
 0208            mainModal.SetActive(!hasBeenSent);
 0209            reportSentModal.SetActive(hasBeenSent);
 0210        }
 211
 212        public void ResetPanelState()
 213        {
 0214            mainFormSection.SetActive(true);
 0215            loadingStateSection.SetActive(false);
 0216            isLoadingActive = false;
 0217        }
 218
 219        private void CreateButtons()
 220        {
 0221            foreach (string option in teenOptions)
 222            {
 0223                ContentModerationReportingOptionComponentView optionComponent = InstantiateOptionButton(option);
 0224                teenOptionButtons.Add(optionComponent);
 225            }
 226
 0227            foreach (string option in adultOptions)
 228            {
 0229                ContentModerationReportingOptionComponentView optionComponent = InstantiateOptionButton(option);
 0230                adultOptionButtons.Add(optionComponent);
 231            }
 232
 0233            foreach (string option in restrictedOptions)
 234            {
 0235                ContentModerationReportingOptionComponentView optionComponent = InstantiateOptionButton(option);
 0236                restrictedOptionButtons.Add(optionComponent);
 237            }
 238
 0239            commentsInput = InstantiateCommentsBox();
 0240        }
 241
 242        private ContentModerationReportingOptionComponentView InstantiateOptionButton(string option)
 243        {
 0244            ContentModerationReportingOptionComponentView optionComponent = Instantiate(optionButtonPrefab, optionsConta
 245               .GetComponent<ContentModerationReportingOptionComponentView>();
 0246            optionComponent.SetOptionText(option);
 0247            optionComponent.UnselectOption();
 248
 0249            optionComponent.OptionButton.onClick.AddListener(() =>
 250            {
 0251                if (!selectedOptions.Contains(option))
 252                {
 0253                    selectedOptions.Add(option);
 0254                    optionComponent.SelectOption();
 255                }
 256                else
 257                {
 0258                    selectedOptions.Remove(option);
 0259                    optionComponent.UnselectOption();
 260                }
 261
 0262                SetSendButtonInteractable(selectedOptions.Count > 0);
 0263            });
 264
 0265            return optionComponent;
 266        }
 267
 268        private TMP_InputField InstantiateCommentsBox()
 269        {
 0270            GameObject commentsObject = Instantiate(commentsPrefab, optionsContainer);
 0271            return commentsObject.GetComponentInChildren<TMP_InputField>();
 272        }
 273
 274        private void ResetOptions()
 275        {
 0276            foreach (ContentModerationReportingOptionComponentView option in teenOptionButtons)
 0277                option.UnselectOption();
 0278            foreach (ContentModerationReportingOptionComponentView option in adultOptionButtons)
 0279                option.UnselectOption();
 0280            foreach (ContentModerationReportingOptionComponentView option in restrictedOptionButtons)
 0281                option.UnselectOption();
 282
 0283            selectedOptions.Clear();
 0284            optionsScroll.verticalNormalizedPosition = 1f;
 0285            commentsInput.text = string.Empty;
 0286            SetSendButtonInteractable(false);
 0287        }
 288
 289        private void SetTitle()
 290        {
 0291            titleText.text = currentMarkedRating == currentRating
 292                ? $"{currentSceneName} has been rated as"
 293                : $"Flag {currentSceneName} for Rating Review";
 0294        }
 295
 296        private void SetSendButtonInteractable(bool isInteractable) =>
 0297            sendButton.SetInteractable(isInteractable);
 298
 299        private void SendReport((SceneContentCategory contentCategory, List<string> issues, string comments) report) =>
 0300            OnSendClicked?.Invoke(report);
 301
 302        private void GoToLearnMore() =>
 0303            OnLearnMoreClicked?.Invoke();
 304    }
 305}