< Summary

Class:Tests.QuestsTrackerHUD.QuestsTrackerHUDViewShould
Assembly:QuestsTrackerHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/Tests/QuestsTrackerHUDViewShould.cs
Covered lines:101
Uncovered lines:0
Coverable lines:101
Total lines:267
Line coverage:100% (101 of 101)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
BeEmptyOnInitialize()0%110100%
TrackQuestProgress()0%110100%
AddPinnedQuestToTracker()0%110100%
AddNotPinnedQuestToTracker()0%110100%
PinUntrackedQuestProperly()0%110100%
PinTrackedQuestProperly()0%110100%
UnpinTrackedQuestProperly()0%110100%
RemoveTrackedEntry()0%330100%
PopulateQuestEntryProperly_SingleTask()0%440100%
PopulateQuestEntryProperly_NumericTask()0%440100%
PopulateQuestEntryProperly_StepBased()0%440100%
TearDown()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/Tests/QuestsTrackerHUDViewShould.cs

#LineLine coverage
 1using System.Collections;
 2using DCL;
 3using DCL.Huds.QuestsTracker;
 4using NUnit.Framework;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7
 8namespace Tests.QuestsTrackerHUD
 9{
 10    public class QuestsTrackerHUDViewShould
 11    {
 12        private const string MOCK_QUEST_ID = "quest0";
 13        private const string MOCK_SECTION_ID = "section0";
 14        private const string MOCK_TASK_ID = "task0";
 15
 16        private QuestsTrackerHUDView hudView;
 17
 18        [SetUp]
 19        public void SetUp()
 20        {
 1121            QuestModel questMock = new QuestModel
 22            {
 23                id = MOCK_QUEST_ID, name = "name", description = "description",
 24            };
 1125            QuestSection sectionMock = new QuestSection
 26            {
 27                id = MOCK_SECTION_ID
 28            };
 1129            QuestTask taskMock = new QuestTask
 30            {
 31                id = MOCK_TASK_ID,
 32                type = "single",
 33                payload = JsonUtility.ToJson(new TaskPayload_Single
 34                {
 35                    isDone = false
 36                })
 37            };
 1138            sectionMock.tasks = new []
 39            {
 40                taskMock
 41            };
 1142            questMock.sections = new []
 43            {
 44                sectionMock
 45            };
 1146            DataStore.i.Quests.quests.Set(new []
 47            {
 48                (questMock.id, questMock)
 49            });
 50
 1151            QuestsTrackerHUDView.ENTRIES_PER_FRAME = int.MaxValue;
 52
 1153            hudView = Object.Instantiate(Resources.Load<GameObject>("QuestsTrackerHUD")).GetComponent<QuestsTrackerHUDVi
 1154        }
 55
 56        [Test]
 257        public void BeEmptyOnInitialize() { Assert.AreEqual(0, hudView.currentEntries.Count); }
 58
 59        [Test]
 60        public void TrackQuestProgress()
 61        {
 162            hudView.UpdateQuest(MOCK_QUEST_ID, true);
 63
 164            Assert.AreEqual(1, hudView.currentEntries.Count);
 165            Assert.IsTrue(hudView.currentEntries.ContainsKey(MOCK_QUEST_ID));
 166        }
 67
 68        [Test]
 69        public void AddPinnedQuestToTracker()
 70        {
 171            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, true);
 72
 173            Assert.AreEqual(1, hudView.questsContainer.childCount);
 174            Assert.IsTrue(hudView.currentEntries.ContainsKey(MOCK_QUEST_ID));
 175            Assert.IsTrue(hudView.currentEntries[MOCK_QUEST_ID].isPinned);
 176        }
 77
 78        [Test]
 79        public void AddNotPinnedQuestToTracker()
 80        {
 181            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, false);
 82
 183            Assert.AreEqual(1, hudView.questsContainer.childCount);
 184            Assert.IsTrue(hudView.currentEntries.ContainsKey(MOCK_QUEST_ID));
 185            Assert.IsFalse(hudView.currentEntries[MOCK_QUEST_ID].isPinned);
 186        }
 87
 88        [Test]
 89        public void PinUntrackedQuestProperly()
 90        {
 191            hudView.PinQuest(MOCK_QUEST_ID);
 192            Assert.IsTrue(hudView.currentEntries.ContainsKey(MOCK_QUEST_ID));
 193        }
 94
 95        [Test]
 96        public void PinTrackedQuestProperly()
 97        {
 198            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, false);
 99
 1100            hudView.PinQuest(MOCK_QUEST_ID);
 101
 1102            Assert.IsTrue(hudView.currentEntries[MOCK_QUEST_ID].isPinned);
 1103        }
 104
 105        [Test]
 106        public void UnpinTrackedQuestProperly()
 107        {
 1108            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, true);
 109
 1110            hudView.UnpinQuest(MOCK_QUEST_ID);
 111
 1112            Assert.IsFalse(hudView.currentEntries[MOCK_QUEST_ID].isPinned);
 1113        }
 114
 115        [UnityTest]
 116        public IEnumerator RemoveTrackedEntry()
 117        {
 1118            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, false);
 119
 1120            hudView.RemoveEntry(MOCK_QUEST_ID);
 121
 1122            yield return null; //Let Unity destroy the entry properly
 123
 1124            Assert.AreEqual(0, hudView.currentEntries.Count);
 1125        }
 126
 127        [UnityTest]
 128        public IEnumerator PopulateQuestEntryProperly_SingleTask()
 129        {
 1130            DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "questName";
 1131            DataStore.i.Quests.quests[MOCK_QUEST_ID].sections = new QuestSection[2];
 6132            for (int i = 0; i < 2; i++)
 133            {
 2134                DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[i] = new QuestSection()
 135                {
 136                    id = $"section{i}",
 137                    name = $"sectionName{i}",
 138                    progress = 1 - i, //So the first section is completed and the second one not
 139                    tasks = new []
 140                    {
 141                        new QuestTask
 142                        {
 143                            id = $"task{i}",
 144                            name = $"task{i}",
 145                            type = "single",
 146                            payload = JsonUtility.ToJson(new TaskPayload_Single { isDone = false })
 147                        }
 148                    }
 149                };
 150            }
 151
 1152            DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "questName";
 1153            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, false);
 154
 1155            yield return null; //wait for all the instantiation/destruction of items to be done by unity
 156
 1157            Assert.AreEqual( "questName", hudView.currentEntries[MOCK_QUEST_ID].questTitle.text);
 1158            Assert.AreEqual( 0, hudView.currentEntries[MOCK_QUEST_ID].progress.fillAmount);
 1159            Assert.AreEqual( 2, hudView.currentEntries[MOCK_QUEST_ID].sectionContainer.childCount);
 1160            Assert.AreEqual( 1, hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section0"].taskEntries.Count);
 161
 1162            var taskEntry = hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section0"].taskContainer.GetComponentI
 1163            Assert.NotNull(taskEntry);
 1164            Assert.AreEqual("task0" , taskEntry.taskTitle.text);
 1165            Assert.AreEqual("0/1" , taskEntry.progressText.text);
 166
 1167            var taskEntry1 = hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section1"].taskContainer.GetComponent
 1168            Assert.NotNull(taskEntry1);
 1169            Assert.AreEqual("task1" , taskEntry1.taskTitle.text);
 1170            Assert.AreEqual("0/1" , taskEntry1.progressText.text);
 1171        }
 172
 173        [UnityTest]
 174        public IEnumerator PopulateQuestEntryProperly_NumericTask()
 175        {
 1176            DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "questName";
 1177            DataStore.i.Quests.quests[MOCK_QUEST_ID].sections = new QuestSection[2];
 6178            for (int i = 0; i < 2; i++)
 179            {
 2180                DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[i] = new QuestSection()
 181                {
 182                    id = $"section{i}",
 183                    name = $"sectionName{i}",
 184                    progress = 1 - i, //So the first section is completed and the second one not
 185                    tasks = new []
 186                    {
 187                        new QuestTask
 188                        {
 189                            id = $"task{i}",
 190                            name = $"task{i}",
 191                            type = "numeric",
 192                            payload = JsonUtility.ToJson(new TaskPayload_Numeric { start = 10, current = 15, end = 20 })
 193                        }
 194                    }
 195                };
 196            }
 197
 1198            DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "questName";
 1199            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, false);
 200
 1201            yield return null; //wait for all the instantiation/destruction of items to be done by unity
 202
 1203            Assert.AreEqual( "questName", hudView.currentEntries[MOCK_QUEST_ID].questTitle.text);
 1204            Assert.AreEqual( 0, hudView.currentEntries[MOCK_QUEST_ID].progress.fillAmount);
 1205            Assert.AreEqual( 2, hudView.currentEntries[MOCK_QUEST_ID].sectionContainer.childCount);
 1206            Assert.AreEqual( 1, hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section0"].taskEntries.Count);
 207
 1208            var taskEntry = hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section0"].taskContainer.GetComponentI
 1209            Assert.NotNull(taskEntry);
 1210            Assert.AreEqual("task0" , taskEntry.taskTitle.text);
 1211            Assert.AreEqual("15/20" , taskEntry.progressText.text);
 212
 1213            var taskEntry1 = hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section1"].taskContainer.GetComponent
 1214            Assert.NotNull(taskEntry1);
 1215            Assert.AreEqual("task1" , taskEntry1.taskTitle.text);
 1216            Assert.AreEqual("15/20" , taskEntry1.progressText.text);
 1217        }
 218
 219        [UnityTest]
 220        public IEnumerator PopulateQuestEntryProperly_StepBased()
 221        {
 1222            DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "questName";
 1223            DataStore.i.Quests.quests[MOCK_QUEST_ID].sections = new QuestSection[2];
 6224            for (int i = 0; i < 2; i++)
 225            {
 2226                DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[i] = new QuestSection()
 227                {
 228                    id = $"section{i}",
 229                    name = $"sectionName{i}",
 230                    progress = 1 - i, //So the first section is completed and the second one not,
 231                    tasks = new []
 232                    {
 233                        new QuestTask
 234                        {
 235                            id = $"task{i}",
 236                            name = $"task{i}",
 237                            type = "step-based",
 238                            payload = JsonUtility.ToJson(new TaskPayload_Numeric { start = 10, current = 15, end = 20 })
 239                        }
 240                    }
 241                };
 242            }
 243
 1244            DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "questName";
 1245            hudView.AddOrUpdateQuest(MOCK_QUEST_ID, false);
 246
 1247            yield return null; //wait for all the instantiation/destruction of items to be done by unity
 248
 1249            Assert.AreEqual( "questName", hudView.currentEntries[MOCK_QUEST_ID].questTitle.text);
 1250            Assert.AreEqual( 0, hudView.currentEntries[MOCK_QUEST_ID].progress.fillAmount);
 1251            Assert.AreEqual( 2, hudView.currentEntries[MOCK_QUEST_ID].sectionContainer.childCount);
 1252            Assert.AreEqual( 1, hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section0"].taskEntries.Count);
 253
 1254            var taskEntry = hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section0"].taskContainer.GetComponentI
 1255            Assert.NotNull(taskEntry);
 1256            Assert.AreEqual("task0" , taskEntry.taskTitle.text);
 1257            Assert.AreEqual("15/20" , taskEntry.progressText.text);
 258
 1259            var taskEntry1 = hudView.currentEntries[MOCK_QUEST_ID].sectionEntries["section1"].taskContainer.GetComponent
 1260            Assert.NotNull(taskEntry1);
 1261            Assert.AreEqual("task1" , taskEntry1.taskTitle.text);
 1262            Assert.AreEqual("15/20" , taskEntry1.progressText.text);
 1263        }
 264        [TearDown]
 22265        public void TearDown() { Object.Destroy(hudView.gameObject); }
 266    }
 267}