< Summary

Class:DCL.Quests.QuestOfferComponentView
Assembly:Quests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestOfferHUD/QuestOfferComponentView.cs
Covered lines:32
Uncovered lines:7
Coverable lines:39
Total lines:101
Line coverage:82% (32 of 39)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:9
Method coverage:77.7% (7 of 9)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
QuestOfferComponentView()0%110100%
Awake()0%110100%
Dispose()0%220100%
RefreshControl()0%2100%
SetIsGuest(...)0%110100%
SetQuestId(...)0%2100%
SetQuestTitle(...)0%110100%
SetQuestDescription(...)0%110100%
SetRewards(...)0%6.046090%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestOfferHUD/QuestOfferComponentView.cs

#LineLine coverage
 1using MainScripts.DCL.Helpers.Utils;
 2using System;
 3using System.Collections.Generic;
 4using TMPro;
 5using UIComponents.Scripts.Components;
 6using UnityEngine;
 7using UnityEngine.UI;
 8using Object = UnityEngine.Object;
 9
 10namespace DCL.Quests
 11{
 12    public class QuestOfferComponentView : BaseComponentView<QuestOfferComponentModel>, IQuestOfferComponentView
 13    {
 14        private const int MAX_REWARDS_COUNT = 3;
 15
 16        [SerializeField] internal GameObject rewardsSection;
 17        [SerializeField] internal GameObject guestSection;
 18        [SerializeField] internal TMP_Text questTitle;
 19        [SerializeField] internal TMP_Text questDescription;
 20        [SerializeField] internal Button acceptButton;
 21        [SerializeField] internal Button cancelButton;
 22        [SerializeField] internal Transform rewardsContainer;
 23
 24        [SerializeField] internal QuestRewardComponentView rewardPrefab;
 25        public event Action<string> OnQuestAccepted;
 26
 27        private UnityObjectPool<QuestRewardComponentView> rewardsPool;
 728        private List<QuestRewardComponentView> usedRewards = new ();
 29
 30        public override void Awake()
 31        {
 632            acceptButton.onClick.RemoveAllListeners();
 633            acceptButton.onClick.AddListener(()=>OnQuestAccepted?.Invoke(model.questId));
 634            rewardsPool = new UnityObjectPool<QuestRewardComponentView>(rewardPrefab, rewardsContainer);
 635            rewardsPool.Prewarm(MAX_REWARDS_COUNT);
 636        }
 37
 38        public override void Dispose()
 39        {
 1240            base.Dispose();
 41
 3242            foreach (var pooledReward in usedRewards)
 443                rewardsPool.Release(pooledReward);
 1244            rewardsPool.Clear();
 1245        }
 46
 47        public override void RefreshControl()
 48        {
 049            SetQuestId(model.questId);
 050            SetQuestTitle(model.title);
 051            SetQuestDescription(model.description);
 052            SetRewards(model.rewardsList);
 053        }
 54
 55        public void SetIsGuest(bool isGuest)
 56        {
 257            guestSection.SetActive(isGuest);
 258        }
 59
 60        public void SetQuestId(string questId) =>
 061            model.questId = questId;
 62
 63        public void SetQuestTitle(string title)
 64        {
 165            model.title = title;
 166            questTitle.text = title;
 167        }
 68
 69        public void SetQuestDescription(string description)
 70        {
 171            model.description = description;
 172            questDescription.text = description;
 173        }
 74
 75        public void SetRewards(List<QuestRewardComponentModel> rewardsList)
 76        {
 277            model.rewardsList = rewardsList;
 78
 1679            for (var i = 0; i < rewardsContainer.childCount; i++)
 680                Destroy(rewardsContainer.GetChild(i));
 81
 282            if (rewardsList == null || rewardsList.Count == 0)
 83            {
 184                rewardsSection.SetActive(false);
 185                return;
 86            }
 87
 188            rewardsSection.SetActive(true);
 89
 290            foreach (var pooledReward in usedRewards)
 091                rewardsPool.Release(pooledReward);
 92
 693            foreach (var rewardModel in rewardsList)
 94            {
 295                QuestRewardComponentView pooledReward = rewardsPool.Get();
 296                pooledReward.SetModel(rewardModel);
 297                usedRewards.Add(pooledReward);
 98            }
 199        }
 100    }
 101}