< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
QuestsTrackerEntryShould()0%110100%
SetUp()0%110100%
PopulateProperly()0%110100%
PopulateAndPrepareSectionsWith_NoProgressedTask()0%110100%
PopulateAndPrepareSectionsWith_JustProgressedTask()0%110100%
PopulateAndPrepareSectionsWith_JustUnlockedTask()0%110100%
PopulateAndPrepareSectionsWith_JustCompletedTask()0%110100%
PopulateAndPrepareSectionsWith_CompletedTask()0%110100%
SetPinStatus(...)0%110100%
TearDown()0%110100%

File(s)

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

#LineLine coverage
 1using DCL.Huds.QuestsTracker;
 2using NUnit.Framework;
 3using UnityEngine;
 4
 5namespace Tests.QuestsTrackerHUD
 6{
 7    public class QuestsTrackerEntryShould
 8    {
 9        private QuestsTrackerEntry questEntry;
 10
 111        private readonly QuestTask task_noProgressed = new QuestTask
 12        {
 13            id = "task_no_progressed",
 14            progress = 0.5f,
 15            justProgressed = false,
 16            justUnlocked = false,
 17            status = QuestsLiterals.Status.ON_GOING,
 18            type = "single",
 19            payload = JsonUtility.ToJson(new TaskPayload_Single { isDone = false }),
 20            oldProgress = 0.5f,
 21        };
 22
 123        private readonly QuestTask task_justProgressed = new QuestTask
 24        {
 25            id = "task_just_progressed",
 26            progress = 0.75f,
 27            justProgressed = true,
 28            justUnlocked = false,
 29            status = QuestsLiterals.Status.ON_GOING,
 30            type = "numeric",
 31            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 32            oldProgress = 0.5f,
 33        };
 34
 135        private readonly QuestTask task_justUnlocked = new QuestTask
 36        {
 37            id = "task_just_unlocked",
 38            progress = 0.75f,
 39            justProgressed = false,
 40            justUnlocked = true,
 41            status = QuestsLiterals.Status.ON_GOING,
 42            type = "numeric",
 43            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 44            oldProgress = 0.5f,
 45        };
 46
 147        private readonly QuestTask task_justCompleted = new QuestTask
 48        {
 49            id = "task_just_completed",
 50            progress = 1f,
 51            justProgressed = true,
 52            justUnlocked = false,
 53            status = QuestsLiterals.Status.ON_GOING,
 54            type = "numeric",
 55            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 56            oldProgress = 0.5f,
 57        };
 58
 159        private readonly QuestTask task_completed = new QuestTask
 60        {
 61            id = "task_completed",
 62            progress = 1f,
 63            justProgressed = false,
 64            justUnlocked = false,
 65            status = QuestsLiterals.Status.ON_GOING,
 66            type = "numeric",
 67            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 68            oldProgress = 1f,
 69        };
 70
 71        [SetUp]
 1672        public void SetUp() { questEntry = Object.Instantiate(Resources.Load<GameObject>("QuestsTrackerEntry")).GetCompo
 73
 74        [Test]
 75        public void PopulateProperly()
 76        {
 177            QuestModel quest = new QuestModel
 78            {
 79                id = "0",
 80                name = "quest0",
 81                description = "description0",
 82                oldProgress = 0.1f,
 83                status = QuestsLiterals.Status.ON_GOING,
 84                sections = new [] { new QuestSection { id = "section", progress = task_noProgressed.progress, tasks = ne
 85            };
 186            questEntry.Populate(quest);
 87
 188            Assert.AreEqual(quest.name, questEntry.questTitle.text);
 189            Assert.AreEqual(quest.oldProgress, questEntry.progress.fillAmount);
 190        }
 91
 92        [Test]
 93        public void PopulateAndPrepareSectionsWith_NoProgressedTask()
 94        {
 195            QuestModel quest = new QuestModel
 96            {
 97                id = "0",
 98                name = "quest0",
 99                description = "description0",
 100                sections = new [] { new QuestSection { id = "section", progress = task_noProgressed.progress, tasks = ne
 101            };
 1102            questEntry.Populate(quest);
 103
 104            //should be visible
 1105            Assert.IsTrue(questEntry.sectionEntries["section"].gameObject.activeSelf);
 1106        }
 107
 108        [Test]
 109        public void PopulateAndPrepareSectionsWith_JustProgressedTask()
 110        {
 1111            QuestModel quest = new QuestModel
 112            {
 113                id = "0",
 114                sections = new [] { new QuestSection { id = "section", progress = task_justProgressed.progress, tasks = 
 115            };
 1116            questEntry.Populate(quest);
 117
 118            //should be visible
 1119            Assert.IsTrue(questEntry.sectionEntries["section"].gameObject.activeSelf);
 1120        }
 121
 122        [Test]
 123        public void PopulateAndPrepareSectionsWith_JustUnlockedTask()
 124        {
 1125            QuestModel quest = new QuestModel
 126            {
 127                id = "0",
 128                sections = new [] { new QuestSection { id = "section", progress = task_justUnlocked.progress, tasks = ne
 129            };
 1130            questEntry.Populate(quest);
 131
 132            //should be invisible
 1133            Assert.IsFalse(questEntry.sectionEntries["section"].gameObject.activeSelf);
 1134        }
 135
 136        [Test]
 137        public void PopulateAndPrepareSectionsWith_JustCompletedTask()
 138        {
 1139            QuestModel quest = new QuestModel
 140            {
 141                id = "0",
 142                sections = new [] { new QuestSection { id = "section", progress = task_justCompleted.progress, tasks = n
 143            };
 1144            questEntry.Populate(quest);
 145
 146            //should be visible
 1147            Assert.IsTrue(questEntry.sectionEntries["section"].gameObject.activeSelf);
 1148        }
 149
 150        [Test]
 151        public void PopulateAndPrepareSectionsWith_CompletedTask()
 152        {
 1153            QuestModel quest = new QuestModel
 154            {
 155                id = "0",
 156                sections = new [] { new QuestSection { id = "section", progress = task_completed.progress, tasks = new [
 157            };
 1158            questEntry.Populate(quest);
 159
 160            //shouldn't exist
 1161            Assert.IsFalse(questEntry.sectionEntries.ContainsKey("section"));
 1162        }
 163
 164        [Test]
 165        [TestCase(true)]
 166        [TestCase(false)]
 167        public void SetPinStatus(bool status)
 168        {
 2169            questEntry.SetPinStatus(status);
 2170            Assert.AreEqual(status, questEntry.pinQuestToggle.isOn);
 2171        }
 172
 173        [TearDown]
 16174        public void TearDown() { Object.Destroy(questEntry.gameObject); }
 175    }
 176
 177    public class QuestsTrackerSectionShould
 178    {
 179        private QuestsTrackerSection sectionEntry;
 180
 181        private readonly QuestTask task_noProgressed = new QuestTask
 182        {
 183            id = "task_no_progressed",
 184            progress = 0.5f,
 185            justProgressed = false,
 186            justUnlocked = false,
 187            status = QuestsLiterals.Status.ON_GOING,
 188            type = "single",
 189            payload = JsonUtility.ToJson(new TaskPayload_Single { isDone = false }),
 190            oldProgress = 0.5f,
 191        };
 192
 193        private readonly QuestTask task_justProgressed = new QuestTask
 194        {
 195            id = "task_just_progressed",
 196            progress = 0.75f,
 197            justProgressed = true,
 198            justUnlocked = false,
 199            status = QuestsLiterals.Status.ON_GOING,
 200            type = "numeric",
 201            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 202            oldProgress = 0.5f,
 203        };
 204
 205        private readonly QuestTask task_justUnlocked = new QuestTask
 206        {
 207            id = "task_just_unlocked",
 208            progress = 0.75f,
 209            justProgressed = false,
 210            justUnlocked = true,
 211            status = QuestsLiterals.Status.ON_GOING,
 212            type = "numeric",
 213            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 214            oldProgress = 0.5f,
 215        };
 216
 217        private readonly QuestTask task_justCompleted = new QuestTask
 218        {
 219            id = "task_just_completed",
 220            progress = 1f,
 221            justProgressed = true,
 222            justUnlocked = false,
 223            status = QuestsLiterals.Status.ON_GOING,
 224            type = "numeric",
 225            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 226            oldProgress = 0.5f,
 227        };
 228
 229        private readonly QuestTask task_completed = new QuestTask
 230        {
 231            id = "task_completed",
 232            progress = 1f,
 233            justProgressed = false,
 234            justUnlocked = false,
 235            status = QuestsLiterals.Status.ON_GOING,
 236            type = "numeric",
 237            payload = JsonUtility.ToJson(new TaskPayload_Numeric() { start = 0, current = 2, end = 5 }),
 238            oldProgress = 1f,
 239        };
 240
 241        [SetUp]
 242        public void SetUp() { sectionEntry = Object.Instantiate(Resources.Load<GameObject>("QuestsTrackerSection")).GetC
 243
 244        [Test]
 245        public void PopulateProperly()
 246        {
 247            QuestSection section =  new QuestSection { id = "section", name = "sectionName", tasks = new QuestTask[0] };
 248            sectionEntry.Populate(section);
 249            Assert.AreEqual(section.name, sectionEntry.sectionTitle.text);
 250            Assert.IsTrue(sectionEntry.titleContainer.gameObject.activeSelf);
 251        }
 252
 253        [Test]
 254        public void PopulateProperly_NoSectionName()
 255        {
 256            QuestSection section =  new QuestSection { id = "section", name = "", tasks = new QuestTask[0] };
 257            sectionEntry.Populate(section);
 258            Assert.IsFalse(sectionEntry.titleContainer.gameObject.activeSelf);
 259        }
 260
 261        [Test]
 262        public void PopulateAndPrepareTasks_NoProgressed()
 263        {
 264            QuestSection section =  new QuestSection { id = "section", name = "", tasks = new [] { task_noProgressed } }
 265            sectionEntry.Populate(section);
 266
 267            //No completed tasks without progress are visible
 268            Assert.IsTrue(sectionEntry.taskEntries[task_noProgressed.id].gameObject.activeSelf);
 269        }
 270
 271        [Test]
 272        public void PopulateAndPrepareTasks_Completed()
 273        {
 274            QuestSection section =  new QuestSection { id = "section", name = "", tasks = new [] { task_completed } };
 275            sectionEntry.Populate(section);
 276
 277            //Completed tasks that has not been just completed are not even added
 278            Assert.IsFalse(sectionEntry.taskEntries.ContainsKey(task_completed.id));
 279        }
 280
 281        [Test]
 282        public void PopulateAndPrepareTasks_JustCompleted()
 283        {
 284            QuestSection section =  new QuestSection { id = "section", name = "", tasks = new [] { task_justCompleted } 
 285            sectionEntry.Populate(section);
 286
 287            //Completed tasks that has not been just completed are hidden
 288            Assert.IsTrue(sectionEntry.taskEntries[task_justCompleted.id].gameObject.activeSelf);
 289        }
 290
 291        [Test]
 292        public void PopulateAndPrepareTasks_JustProgressed()
 293        {
 294            QuestSection section =  new QuestSection { id = "section", name = "", tasks = new [] { task_justProgressed }
 295            sectionEntry.Populate(section);
 296
 297            //Just progressed tasks are visible
 298            Assert.IsTrue(sectionEntry.taskEntries[task_justProgressed.id].gameObject.activeSelf);
 299        }
 300
 301        [Test]
 302        public void PopulateAndPrepareTasks_JustUnlocked()
 303        {
 304            QuestSection section =  new QuestSection { id = "section", name = "", tasks = new [] { task_justUnlocked } }
 305            sectionEntry.Populate(section);
 306
 307            //Just unlocked tasks are hidden
 308            Assert.IsFalse(sectionEntry.taskEntries[task_justUnlocked.id].gameObject.activeSelf);
 309        }
 310    }
 311}