| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL; |
| | 3 | | using DCL.QuestsController; |
| | 4 | | using NUnit.Framework; |
| | 5 | |
|
| | 6 | | namespace Tests.QuestsTrackerHUD |
| | 7 | | { |
| | 8 | | public class QuestsControllerShould |
| | 9 | | { |
| | 10 | | private QuestsController questsController; |
| 0 | 11 | | private BaseDictionary<string, QuestModel> quests => DataStore.i.Quests.quests; |
| 0 | 12 | | private BaseCollection<string> pinnedQuests => DataStore.i.Quests.pinnedQuests; |
| | 13 | |
|
| | 14 | | [SetUp] |
| 16 | 15 | | public void SetUp() { questsController = new QuestsController(); } |
| | 16 | |
|
| | 17 | | [Test] |
| | 18 | | public void InitializeQuestsProperly() |
| | 19 | | { |
| 1 | 20 | | questsController.InitializeQuests(new List<QuestModel> |
| | 21 | | { |
| | 22 | | new QuestModel { id = "0", status = QuestsLiterals.Status.NOT_STARTED, sections = new [] { new QuestSect |
| | 23 | | new QuestModel { id = "1", status = QuestsLiterals.Status.NOT_STARTED, sections = new [] { new QuestSect |
| | 24 | | }); |
| | 25 | |
|
| 1 | 26 | | Assert.IsTrue(quests.ContainsKey("0")); |
| 1 | 27 | | Assert.IsTrue(quests.ContainsKey("1")); |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | | [Test] |
| | 31 | | public void InitializeQuestsFilterQuestsWithoutSections() |
| | 32 | | { |
| 1 | 33 | | questsController.InitializeQuests(new List<QuestModel> |
| | 34 | | { |
| | 35 | | new QuestModel { id = "0", status = QuestsLiterals.Status.NOT_STARTED, sections = new QuestSection[] { } |
| | 36 | | new QuestModel { id = "1", status = QuestsLiterals.Status.NOT_STARTED, sections = null }, |
| | 37 | | }); |
| | 38 | |
|
| 1 | 39 | | Assert.IsFalse(quests.ContainsKey("0")); |
| 1 | 40 | | Assert.IsFalse(quests.ContainsKey("1")); |
| 1 | 41 | | } |
| | 42 | |
|
| | 43 | | [Test] |
| | 44 | | public void InitializeQuestsUnpinNotPinnableQuests() |
| | 45 | | { |
| 1 | 46 | | pinnedQuests.Add("0"); |
| 1 | 47 | | pinnedQuests.Add("1"); |
| 1 | 48 | | questsController.InitializeQuests(new List<QuestModel> |
| | 49 | | { |
| | 50 | | new QuestModel { id = "0", status = QuestsLiterals.Status.COMPLETED, sections = new [] { new QuestSectio |
| | 51 | | new QuestModel { id = "1", status = QuestsLiterals.Status.BLOCKED, sections = new [] { new QuestSection |
| | 52 | | }); |
| | 53 | |
|
| 1 | 54 | | Assert.IsFalse(pinnedQuests.Contains("0")); |
| 1 | 55 | | Assert.IsFalse(pinnedQuests.Contains("1")); |
| 1 | 56 | | } |
| | 57 | |
|
| | 58 | | [Test] |
| | 59 | | public void InitializeQuestsSetProgressFlags() |
| | 60 | | { |
| 1 | 61 | | questsController.InitializeQuests(new List<QuestModel> |
| | 62 | | { |
| | 63 | | new QuestModel { id = "0", status = QuestsLiterals.Status.COMPLETED, sections = new [] { new QuestSectio |
| | 64 | | }); |
| | 65 | |
|
| 1 | 66 | | Assert.AreEqual(quests["0"].oldProgress, quests["0"].progress); |
| 1 | 67 | | Assert.AreEqual(quests["0"].sections[0].tasks[0].oldProgress, quests["0"].sections[0].tasks[0].progress); |
| 1 | 68 | | Assert.IsFalse(quests["0"].justProgressed); |
| 1 | 69 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justProgressed); |
| 1 | 70 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justUnlocked); |
| 1 | 71 | | } |
| | 72 | |
|
| | 73 | | [Test] |
| | 74 | | public void UpdateQuestProgressUnpinNotPinnableQuests() |
| | 75 | | { |
| 1 | 76 | | pinnedQuests.Add("0"); |
| 1 | 77 | | pinnedQuests.Add("1"); |
| 1 | 78 | | questsController.UpdateQuestProgress( |
| | 79 | | new QuestModel |
| | 80 | | { |
| | 81 | | id = "0", status = QuestsLiterals.Status.COMPLETED, sections = new [] { new QuestSection { id = "0_0 |
| | 82 | | }); |
| 1 | 83 | | questsController.UpdateQuestProgress( |
| | 84 | | new QuestModel |
| | 85 | | { |
| | 86 | | id = "1", status = QuestsLiterals.Status.BLOCKED, sections = new [] { new QuestSection { id = "1_0", |
| | 87 | | }); |
| | 88 | |
|
| 1 | 89 | | Assert.IsFalse(pinnedQuests.Contains("0")); |
| 1 | 90 | | Assert.IsFalse(pinnedQuests.Contains("1")); |
| 1 | 91 | | } |
| | 92 | |
|
| | 93 | | [Test] |
| | 94 | | public void UpdateQuestProgressProcessNewQuest() |
| | 95 | | { |
| 1 | 96 | | bool newQuestReceived = false; |
| 1 | 97 | | bool questUpdatedReceived = false; |
| 1 | 98 | | bool rewardObtainedReceived = false; |
| 2 | 99 | | questsController.OnNewQuest += (questId) => newQuestReceived = true; |
| 1 | 100 | | questsController.OnQuestUpdated += (questId, hasProgressed) => questUpdatedReceived = true; |
| 1 | 101 | | questsController.OnRewardObtained += (questId, rewardId) => rewardObtainedReceived = true; |
| | 102 | |
|
| 1 | 103 | | questsController.UpdateQuestProgress(new QuestModel { id = "0", status = QuestsLiterals.Status.NOT_STARTED, |
| | 104 | |
|
| 1 | 105 | | Assert.IsTrue(quests.ContainsKey("0")); |
| 1 | 106 | | Assert.AreEqual(quests["0"].oldProgress, quests["0"].progress); |
| 1 | 107 | | Assert.AreEqual(quests["0"].sections[0].tasks[0].oldProgress, quests["0"].sections[0].tasks[0].progress); |
| 1 | 108 | | Assert.IsFalse(quests["0"].justProgressed); |
| 1 | 109 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justProgressed); |
| 1 | 110 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justUnlocked); |
| 1 | 111 | | Assert.IsTrue(newQuestReceived); |
| 1 | 112 | | Assert.IsFalse(questUpdatedReceived); |
| 1 | 113 | | Assert.IsFalse(rewardObtainedReceived); |
| 1 | 114 | | } |
| | 115 | |
|
| | 116 | | [Test] |
| | 117 | | public void UpdateQuestProgressUpdateQuest() |
| | 118 | | { |
| 1 | 119 | | quests.Add("0", new QuestModel |
| | 120 | | { |
| | 121 | | id = "0", status = QuestsLiterals.Status.NOT_STARTED, |
| | 122 | | sections = new [] { new QuestSection { id = "0_0", tasks = new [] { new QuestTask { id = "0_0_0" } } } } |
| | 123 | | rewards = new [] { new QuestReward { id = "reward0", status = QuestsLiterals.RewardStatus.NOT_GIVEN } } |
| | 124 | | }); |
| | 125 | |
|
| 1 | 126 | | QuestModel progressedQuest = new QuestModel |
| | 127 | | { |
| | 128 | | id = "0", status = QuestsLiterals.Status.NOT_STARTED, |
| | 129 | | sections = new [] |
| | 130 | | { |
| | 131 | | new QuestSection |
| | 132 | | { |
| | 133 | | id = "0_0", |
| | 134 | | progress = 0.5f, |
| | 135 | | tasks = new [] |
| | 136 | | { |
| | 137 | | new QuestTask { id = "0_0_0", progress = 0.5f } |
| | 138 | | } |
| | 139 | | }, |
| | 140 | | }, |
| | 141 | | rewards = new [] { new QuestReward { id = "reward0", status = QuestsLiterals.RewardStatus.NOT_GIVEN } } |
| | 142 | | }; |
| | 143 | |
|
| 1 | 144 | | bool newQuestReceived = false; |
| 1 | 145 | | bool questUpdatedReceived = false; |
| 1 | 146 | | bool rewardObtainedReceived = false; |
| 1 | 147 | | questsController.OnNewQuest += (questId) => newQuestReceived = true; |
| 1 | 148 | | questsController.OnQuestUpdated += (questId, hasProgressed) => |
| | 149 | | { |
| 1 | 150 | | questUpdatedReceived = true; |
| | 151 | | //Check the progress flags are set propperly |
| 1 | 152 | | Assert.AreEqual(0, quests["0"].oldProgress); |
| 1 | 153 | | Assert.AreEqual(0.5f, quests["0"].progress); |
| 1 | 154 | | Assert.AreEqual(0, quests["0"].sections[0].tasks[0].oldProgress); |
| 1 | 155 | | Assert.AreEqual(0.5f, quests["0"].sections[0].tasks[0].progress); |
| 1 | 156 | | }; |
| 1 | 157 | | questsController.OnRewardObtained += (questId, rewardId) => rewardObtainedReceived = true; |
| | 158 | |
|
| 1 | 159 | | questsController.UpdateQuestProgress(progressedQuest); |
| | 160 | |
|
| 1 | 161 | | Assert.IsFalse(newQuestReceived); |
| 1 | 162 | | Assert.IsTrue(questUpdatedReceived); |
| 1 | 163 | | Assert.IsFalse(rewardObtainedReceived); |
| | 164 | |
|
| | 165 | | //Check progress flags are reverted |
| 1 | 166 | | Assert.AreEqual(quests["0"].oldProgress, quests["0"].progress); |
| 1 | 167 | | Assert.AreEqual(quests["0"].sections[0].tasks[0].oldProgress, quests["0"].sections[0].tasks[0].progress); |
| 1 | 168 | | Assert.IsFalse(quests["0"].justProgressed); |
| 1 | 169 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justProgressed); |
| 1 | 170 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justUnlocked); |
| 1 | 171 | | } |
| | 172 | |
|
| | 173 | | [Test] |
| | 174 | | public void UpdateQuestProgressUpdateQuest_Completed() |
| | 175 | | { |
| 1 | 176 | | quests.Add("0", new QuestModel |
| | 177 | | { |
| | 178 | | id = "0", status = QuestsLiterals.Status.NOT_STARTED, |
| | 179 | | sections = new [] { new QuestSection { id = "0_0", tasks = new [] { new QuestTask { id = "0_0_0" } } } } |
| | 180 | | rewards = new [] { new QuestReward { id = "reward0", status = QuestsLiterals.RewardStatus.NOT_GIVEN } } |
| | 181 | | }); |
| | 182 | |
|
| 1 | 183 | | QuestModel progressedQuest = new QuestModel |
| | 184 | | { |
| | 185 | | id = "0", |
| | 186 | | status = QuestsLiterals.Status.COMPLETED, |
| | 187 | | sections = new [] |
| | 188 | | { |
| | 189 | | new QuestSection |
| | 190 | | { |
| | 191 | | id = "0_0", |
| | 192 | | progress = 1f, |
| | 193 | | tasks = new [] |
| | 194 | | { |
| | 195 | | new QuestTask { id = "0_0_0", progress = 1f, status = QuestsLiterals.Status.COMPLETED } |
| | 196 | | } |
| | 197 | | } |
| | 198 | | }, |
| | 199 | | rewards = new [] { new QuestReward { id = "reward0", status = QuestsLiterals.RewardStatus.OK } } |
| | 200 | | }; |
| | 201 | |
|
| 1 | 202 | | bool newQuestReceived = false; |
| 1 | 203 | | bool questUpdatedReceived = false; |
| 1 | 204 | | bool rewardObtainedReceived = false; |
| 1 | 205 | | questsController.OnNewQuest += (questId) => newQuestReceived = true; |
| 1 | 206 | | questsController.OnQuestUpdated += (questId, hasProgressed) => |
| | 207 | | { |
| 1 | 208 | | questUpdatedReceived = true; |
| | 209 | | //Check the progress flags are set propperly |
| 1 | 210 | | Assert.AreEqual(0, quests["0"].oldProgress); |
| 1 | 211 | | Assert.AreEqual(1f, quests["0"].progress); |
| 1 | 212 | | Assert.AreEqual(0, quests["0"].sections[0].tasks[0].oldProgress); |
| 1 | 213 | | Assert.AreEqual(1f, quests["0"].sections[0].tasks[0].progress); |
| 1 | 214 | | }; |
| 1 | 215 | | questsController.OnRewardObtained += (questId, rewardId) => |
| | 216 | | { |
| 1 | 217 | | rewardObtainedReceived = true; |
| | 218 | | // Check reward |
| 1 | 219 | | Assert.AreEqual(questId, "0"); |
| 1 | 220 | | Assert.AreEqual(rewardId, "reward0"); |
| 1 | 221 | | }; |
| | 222 | |
|
| 1 | 223 | | questsController.UpdateQuestProgress(progressedQuest); |
| | 224 | |
|
| 1 | 225 | | Assert.IsFalse(newQuestReceived); |
| 1 | 226 | | Assert.IsTrue(questUpdatedReceived); |
| 1 | 227 | | Assert.IsTrue(rewardObtainedReceived); |
| | 228 | |
|
| | 229 | | //Check progress flags are reverted |
| 1 | 230 | | Assert.AreEqual(quests["0"].oldProgress, quests["0"].progress); |
| 1 | 231 | | Assert.AreEqual(quests["0"].sections[0].tasks[0].oldProgress, quests["0"].sections[0].tasks[0].progress); |
| 1 | 232 | | Assert.IsFalse(quests["0"].justProgressed); |
| 1 | 233 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justProgressed); |
| 1 | 234 | | Assert.IsFalse(quests["0"].sections[0].tasks[0].justUnlocked); |
| 1 | 235 | | } |
| | 236 | |
|
| | 237 | | [TearDown] |
| 16 | 238 | | public void TearDown() { DataStore.Clear(); } |
| | 239 | | } |
| | 240 | | } |