< Summary

Class:Tests.QuestsPanelHUD.QuestsPanelHUDControllerShould
Assembly:QuestsPanelHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsPanelHUD/Tests/QuestsPanelHUDControllerShould.cs
Covered lines:61
Uncovered lines:0
Coverable lines:61
Total lines:179
Line coverage:100% (61 of 61)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
InitializeProperly()0%110100%
ToggleViewVisibilityWhenActionPerformedForInitialState(...)0%110100%
CallViewWhenQuestProgressed()0%110100%
CallViewWhenQuestBlocked()0%110100%
CallViewWhenQuestRemoved()0%110100%
CallViewWhenQuestsSet()0%110100%
NotShowNotStartedSecretQuests_Add()0%110100%
ShowNewStartedSecretQuests_Add()0%110100%
NotShowNotStartedSecretQuests_Update()0%110100%
ShowNewStartedSecretQuests_Update()0%110100%
TearDown()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsPanelHUD/Tests/QuestsPanelHUDControllerShould.cs

#LineLine coverage
 1using DCL;
 2using DCL.Huds.QuestsPanel;
 3using DCL.QuestsController;
 4using NSubstitute;
 5using NSubstitute.Extensions;
 6using NUnit.Framework;
 7using System.Collections.Generic;
 8
 9namespace Tests.QuestsPanelHUD
 10{
 11    public class QuestsPanelHUDControllerShould
 12    {
 13        private const string MOCK_QUEST_ID = "quest0";
 14        private const string MOCK_SECTION_ID = "section0";
 15        private const string MOCK_TASK_ID = "task0";
 16
 17        private IQuestsController questsController;
 18        private QuestsPanelHUDController hudController;
 19        private IQuestsPanelHUDView hudView;
 20
 21        [SetUp]
 22        public void SetUp()
 23        {
 1124            QuestModel questMock = new QuestModel { id = MOCK_QUEST_ID };
 1125            QuestSection sectionMock = new QuestSection { id = MOCK_SECTION_ID };
 1126            QuestTask taskMock = new QuestTask { id = MOCK_TASK_ID };
 1127            sectionMock.tasks = new [] { taskMock };
 1128            questMock.sections = new [] { sectionMock };
 1129            DataStore.i.Quests.quests.Set(new [] { (questMock.id, questMock) });
 30
 1131            questsController = Substitute.For<IQuestsController>();
 1132            hudView = Substitute.For<IQuestsPanelHUDView>();
 1133            hudController = Substitute.ForPartsOf<QuestsPanelHUDController>();
 2234            hudController.Configure().CreateView().Returns(info => hudView);
 1135        }
 36
 37        [Test]
 38        public void InitializeProperly()
 39        {
 140            hudController.Initialize(questsController);
 41
 142            Assert.AreEqual(questsController, hudController.questsController);
 143            Assert.AreEqual(hudView, hudController.view);
 144        }
 45
 46        [Test]
 47        [TestCase(true)]
 48        [TestCase(false)]
 49        public void ToggleViewVisibilityWhenActionPerformedForInitialState(bool initialState)
 50        {
 251            hudView.Configure().isVisible.Returns(initialState);
 52
 253            hudController.Initialize(questsController);
 254            hudController.toggleQuestsPanel.RaiseOnTriggered();
 55
 256            hudView.Received().SetVisibility(!initialState);
 257        }
 58
 59        [Test]
 60        public void CallViewWhenQuestProgressed()
 61        {
 162            hudController.Initialize(questsController);
 163            questsController.OnQuestUpdated += Raise.Event<QuestUpdated>(MOCK_QUEST_ID, true);
 64
 165            hudView.Received().RequestAddOrUpdateQuest(MOCK_QUEST_ID);
 166        }
 67
 68        [Test]
 69        public void CallViewWhenQuestBlocked()
 70        {
 171            DataStore.i.Quests.quests[MOCK_QUEST_ID].status = QuestsLiterals.Status.BLOCKED;
 172            hudController.Initialize(questsController);
 173            questsController.OnQuestUpdated += Raise.Event<QuestUpdated>(MOCK_QUEST_ID, true);
 74
 175            hudView.Received().RemoveQuest(MOCK_QUEST_ID);
 176        }
 77
 78        [Test]
 79        public void CallViewWhenQuestRemoved()
 80        {
 181            hudController.Initialize(questsController);
 182            DataStore.i.Quests.quests.Remove(MOCK_QUEST_ID);
 83
 184            hudView.Received().RemoveQuest(MOCK_QUEST_ID);
 185        }
 86
 87        [Test]
 88        public void CallViewWhenQuestsSet()
 89        {
 190            hudController.Initialize(questsController);
 191            DataStore.i.Quests.quests.Set(new List<(string, QuestModel)>
 92            {
 93                ("newQuest1", new QuestModel { id = "newQuest1" }),
 94                ("newQuest2", new QuestModel { id = "newQuest2" }),
 95            });
 96
 197            hudView.Received().RequestAddOrUpdateQuest("newQuest1");
 198            hudView.Received().RequestAddOrUpdateQuest("newQuest2");
 199        }
 100
 101        [Test]
 102        public void NotShowNotStartedSecretQuests_Add()
 103        {
 1104            hudController.Initialize(questsController);
 1105            DataStore.i.Quests.quests.Set(new List<(string, QuestModel)>
 106            {
 107                ("newQuest1", new QuestModel
 108                {
 109                    id = "newQuest1",
 110                    status = QuestsLiterals.Status.NOT_STARTED,
 111                    visibility = QuestsLiterals.Visibility.SECRET
 112                }),
 113            });
 114
 1115            hudView.DidNotReceive().RequestAddOrUpdateQuest("newQuest1");
 1116        }
 117
 118        [Test]
 119        public void ShowNewStartedSecretQuests_Add()
 120        {
 1121            hudController.Initialize(questsController);
 1122            DataStore.i.Quests.quests.Set(new List<(string, QuestModel)>
 123            {
 124                ("newQuest1", new QuestModel
 125                {
 126                    id = "newQuest1",
 127                    status = QuestsLiterals.Status.ON_GOING,
 128                    visibility = QuestsLiterals.Visibility.SECRET
 129                }),
 130            });
 131
 1132            hudView.Received().RequestAddOrUpdateQuest("newQuest1");
 1133        }
 134
 135        [Test]
 136        public void NotShowNotStartedSecretQuests_Update()
 137        {
 1138            DataStore.i.Quests.quests.Set(new List<(string, QuestModel)>
 139            {
 140                ("newQuest1", new QuestModel
 141                {
 142                    id = "newQuest1",
 143                    status = QuestsLiterals.Status.NOT_STARTED,
 144                    visibility = QuestsLiterals.Visibility.VISIBLE
 145                }),
 146            });
 147
 1148            hudController.Initialize(questsController);
 1149            hudView.ClearReceivedCalls();
 1150            DataStore.i.Quests.quests["newQuest1"].visibility = QuestsLiterals.Visibility.SECRET;
 1151            questsController.OnQuestUpdated += Raise.Event<QuestUpdated>("newQuest1", true);
 1152            hudView.DidNotReceive().RequestAddOrUpdateQuest("newQuest1");
 1153        }
 154
 155        [Test]
 156        public void ShowNewStartedSecretQuests_Update()
 157        {
 1158            DataStore.i.Quests.quests.Set(new List<(string, QuestModel)>
 159            {
 160                ("newQuest1", new QuestModel
 161                {
 162                    id = "newQuest1",
 163                    status = QuestsLiterals.Status.NOT_STARTED,
 164                    visibility = QuestsLiterals.Visibility.SECRET
 165                }),
 166            });
 167
 1168            hudController.Initialize(questsController);
 1169            hudView.ClearReceivedCalls();
 1170            DataStore.i.Quests.quests["newQuest1"].status = QuestsLiterals.Status.NOT_STARTED;
 1171            questsController.OnQuestUpdated += Raise.Event<QuestUpdated>("newQuest1", true);
 1172            hudView.DidNotReceive().RequestAddOrUpdateQuest("newQuest1");
 1173        }
 174
 175        [TearDown]
 22176        public void TearDown() { DataStore.Clear(); }
 177    }
 178
 179}