< Summary

Class:DCL.Builder.Toast
Assembly:BIWCommonHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/CommonHUD/Scripts/Toast.cs
Covered lines:2
Uncovered lines:14
Coverable lines:16
Total lines:58
Line coverage:12.5% (2 of 16)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Toast()0%110100%
RefreshControl()0%2100%
SetText(...)0%2100%
Show(...)0%6200%
WaitAndDeactivate()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/CommonHUD/Scripts/Toast.cs

#LineLine coverage
 1using System.Collections;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6namespace DCL.Builder
 7{
 8    public interface IToast
 9    {
 10        /// <summary>
 11        /// Show the text
 12        /// </summary>
 13        /// <param name="instant"></param>
 14        void Show(bool instant);
 15
 16        /// <summary>
 17        /// Set the text and changes the size of the toast based on the text
 18        /// </summary>
 19        /// <param name="text"></param>
 20        void SetText(string text);
 21    }
 22
 23    public class Toast : BaseComponentView, IToast
 24    {
 25        [Tooltip("Represented in milliseconds")]
 1726        [SerializeField] internal int msToBeActive = 2000;
 1727        [SerializeField] internal float sizePerCharacter = 8.8f;
 28        [SerializeField] internal Image toastImage;
 29        [SerializeField] internal TextMeshProUGUI toastText;
 30
 31        private Coroutine hideCoroutine;
 32
 033        public override void RefreshControl() {  }
 34
 35        public void SetText(string text)
 36        {
 037            toastText.text = text;
 38
 039            Vector2 size = toastImage.rectTransform.sizeDelta;
 040            size.x = text.Length * sizePerCharacter;
 041            toastImage.rectTransform.sizeDelta = size;
 042        }
 43
 44        public override void Show(bool instant)
 45        {
 046            base.Show(instant);
 047            if(hideCoroutine != null)
 048                StopCoroutine(hideCoroutine);
 049            hideCoroutine = StartCoroutine(WaitAndDeactivate());
 050        }
 51
 52        IEnumerator WaitAndDeactivate()
 53        {
 054            yield return new WaitForSeconds(msToBeActive / 1000f);
 055            Hide(false);
 056        }
 57    }
 58}