| | 1 | | using DCL; |
| | 2 | | using DCL.Huds.QuestsPanel; |
| | 3 | | using DCL.QuestsController; |
| | 4 | | using NSubstitute; |
| | 5 | | using NSubstitute.Extensions; |
| | 6 | | using NUnit.Framework; |
| | 7 | | using System.Collections.Generic; |
| | 8 | |
|
| | 9 | | namespace 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 | | { |
| 11 | 24 | | QuestModel questMock = new QuestModel { id = MOCK_QUEST_ID }; |
| 11 | 25 | | QuestSection sectionMock = new QuestSection { id = MOCK_SECTION_ID }; |
| 11 | 26 | | QuestTask taskMock = new QuestTask { id = MOCK_TASK_ID }; |
| 11 | 27 | | sectionMock.tasks = new [] { taskMock }; |
| 11 | 28 | | questMock.sections = new [] { sectionMock }; |
| 11 | 29 | | DataStore.i.Quests.quests.Set(new [] { (questMock.id, questMock) }); |
| | 30 | |
|
| 11 | 31 | | questsController = Substitute.For<IQuestsController>(); |
| 11 | 32 | | hudView = Substitute.For<IQuestsPanelHUDView>(); |
| 11 | 33 | | hudController = Substitute.ForPartsOf<QuestsPanelHUDController>(); |
| 22 | 34 | | hudController.Configure().CreateView().Returns(info => hudView); |
| 11 | 35 | | } |
| | 36 | |
|
| | 37 | | [Test] |
| | 38 | | public void InitializeProperly() |
| | 39 | | { |
| 1 | 40 | | hudController.Initialize(questsController); |
| | 41 | |
|
| 1 | 42 | | Assert.AreEqual(questsController, hudController.questsController); |
| 1 | 43 | | Assert.AreEqual(hudView, hudController.view); |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | [Test] |
| | 47 | | [TestCase(true)] |
| | 48 | | [TestCase(false)] |
| | 49 | | public void ToggleViewVisibilityWhenActionPerformedForInitialState(bool initialState) |
| | 50 | | { |
| 2 | 51 | | hudView.Configure().isVisible.Returns(initialState); |
| | 52 | |
|
| 2 | 53 | | hudController.Initialize(questsController); |
| 2 | 54 | | hudController.toggleQuestsPanel.RaiseOnTriggered(); |
| | 55 | |
|
| 2 | 56 | | hudView.Received().SetVisibility(!initialState); |
| 2 | 57 | | } |
| | 58 | |
|
| | 59 | | [Test] |
| | 60 | | public void CallViewWhenQuestProgressed() |
| | 61 | | { |
| 1 | 62 | | hudController.Initialize(questsController); |
| 1 | 63 | | questsController.OnQuestUpdated += Raise.Event<QuestUpdated>(MOCK_QUEST_ID, true); |
| | 64 | |
|
| 1 | 65 | | hudView.Received().RequestAddOrUpdateQuest(MOCK_QUEST_ID); |
| 1 | 66 | | } |
| | 67 | |
|
| | 68 | | [Test] |
| | 69 | | public void CallViewWhenQuestBlocked() |
| | 70 | | { |
| 1 | 71 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].status = QuestsLiterals.Status.BLOCKED; |
| 1 | 72 | | hudController.Initialize(questsController); |
| 1 | 73 | | questsController.OnQuestUpdated += Raise.Event<QuestUpdated>(MOCK_QUEST_ID, true); |
| | 74 | |
|
| 1 | 75 | | hudView.Received().RemoveQuest(MOCK_QUEST_ID); |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | [Test] |
| | 79 | | public void CallViewWhenQuestRemoved() |
| | 80 | | { |
| 1 | 81 | | hudController.Initialize(questsController); |
| 1 | 82 | | DataStore.i.Quests.quests.Remove(MOCK_QUEST_ID); |
| | 83 | |
|
| 1 | 84 | | hudView.Received().RemoveQuest(MOCK_QUEST_ID); |
| 1 | 85 | | } |
| | 86 | |
|
| | 87 | | [Test] |
| | 88 | | public void CallViewWhenQuestsSet() |
| | 89 | | { |
| 1 | 90 | | hudController.Initialize(questsController); |
| 1 | 91 | | DataStore.i.Quests.quests.Set(new List<(string, QuestModel)> |
| | 92 | | { |
| | 93 | | ("newQuest1", new QuestModel { id = "newQuest1" }), |
| | 94 | | ("newQuest2", new QuestModel { id = "newQuest2" }), |
| | 95 | | }); |
| | 96 | |
|
| 1 | 97 | | hudView.Received().RequestAddOrUpdateQuest("newQuest1"); |
| 1 | 98 | | hudView.Received().RequestAddOrUpdateQuest("newQuest2"); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | [Test] |
| | 102 | | public void NotShowNotStartedSecretQuests_Add() |
| | 103 | | { |
| 1 | 104 | | hudController.Initialize(questsController); |
| 1 | 105 | | 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 | |
|
| 1 | 115 | | hudView.DidNotReceive().RequestAddOrUpdateQuest("newQuest1"); |
| 1 | 116 | | } |
| | 117 | |
|
| | 118 | | [Test] |
| | 119 | | public void ShowNewStartedSecretQuests_Add() |
| | 120 | | { |
| 1 | 121 | | hudController.Initialize(questsController); |
| 1 | 122 | | 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 | |
|
| 1 | 132 | | hudView.Received().RequestAddOrUpdateQuest("newQuest1"); |
| 1 | 133 | | } |
| | 134 | |
|
| | 135 | | [Test] |
| | 136 | | public void NotShowNotStartedSecretQuests_Update() |
| | 137 | | { |
| 1 | 138 | | 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 | |
|
| 1 | 148 | | hudController.Initialize(questsController); |
| 1 | 149 | | hudView.ClearReceivedCalls(); |
| 1 | 150 | | DataStore.i.Quests.quests["newQuest1"].visibility = QuestsLiterals.Visibility.SECRET; |
| 1 | 151 | | questsController.OnQuestUpdated += Raise.Event<QuestUpdated>("newQuest1", true); |
| 1 | 152 | | hudView.DidNotReceive().RequestAddOrUpdateQuest("newQuest1"); |
| 1 | 153 | | } |
| | 154 | |
|
| | 155 | | [Test] |
| | 156 | | public void ShowNewStartedSecretQuests_Update() |
| | 157 | | { |
| 1 | 158 | | 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 | |
|
| 1 | 168 | | hudController.Initialize(questsController); |
| 1 | 169 | | hudView.ClearReceivedCalls(); |
| 1 | 170 | | DataStore.i.Quests.quests["newQuest1"].status = QuestsLiterals.Status.NOT_STARTED; |
| 1 | 171 | | questsController.OnQuestUpdated += Raise.Event<QuestUpdated>("newQuest1", true); |
| 1 | 172 | | hudView.DidNotReceive().RequestAddOrUpdateQuest("newQuest1"); |
| 1 | 173 | | } |
| | 174 | |
|
| | 175 | | [TearDown] |
| 22 | 176 | | public void TearDown() { DataStore.Clear(); } |
| | 177 | | } |
| | 178 | |
|
| | 179 | | } |