| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Huds.QuestsTracker; |
| | 4 | | using DCL.QuestsController; |
| | 5 | | using NSubstitute; |
| | 6 | | using NSubstitute.Extensions; |
| | 7 | | using NUnit.Framework; |
| | 8 | | using System; |
| | 9 | |
|
| | 10 | | namespace Tests.QuestsTrackerHUD |
| | 11 | | { |
| | 12 | | public class QuestsTrackerHUDControllerShould |
| | 13 | | { |
| | 14 | | private const string MOCK_QUEST_ID = "quest0"; |
| | 15 | | private const string MOCK_SECTION_ID = "section0"; |
| | 16 | | private const string MOCK_TASK_ID = "task0"; |
| | 17 | | private const string MOCK_REWARD_ID = "reward0"; |
| | 18 | |
|
| | 19 | | private IQuestsController questsController; |
| | 20 | | private QuestsTrackerHUDController hudController; |
| | 21 | | private IQuestsTrackerHUDView hudView; |
| | 22 | |
|
| | 23 | | [SetUp] |
| | 24 | | public void SetUp() |
| | 25 | | { |
| 7 | 26 | | QuestModel questMock = new QuestModel { id = MOCK_QUEST_ID, status = QuestsLiterals.Status.ON_GOING }; |
| 7 | 27 | | QuestSection sectionMock = new QuestSection { id = MOCK_SECTION_ID }; |
| 7 | 28 | | QuestTask taskMock = new QuestTask { id = MOCK_TASK_ID }; |
| 7 | 29 | | QuestReward rewardMock = new QuestReward { id = MOCK_REWARD_ID }; |
| 7 | 30 | | sectionMock.tasks = new [] { taskMock }; |
| 7 | 31 | | questMock.sections = new [] { sectionMock }; |
| 7 | 32 | | questMock.rewards = new [] { rewardMock }; |
| 7 | 33 | | DataStore.i.Quests.quests.Set(new [] |
| | 34 | | { |
| | 35 | | (questMock.id, questMock) |
| | 36 | | }); |
| | 37 | |
|
| 7 | 38 | | questsController = Substitute.For<IQuestsController>(); |
| 7 | 39 | | hudView = Substitute.For<IQuestsTrackerHUDView>(); |
| 7 | 40 | | hudController = Substitute.ForPartsOf<QuestsTrackerHUDController>(); |
| 14 | 41 | | hudController.Configure().CreateView().Returns(info => hudView); |
| 7 | 42 | | } |
| | 43 | |
|
| | 44 | | [Test] |
| | 45 | | public void InitializeProperly() |
| | 46 | | { |
| 1 | 47 | | hudController.Initialize(questsController); |
| | 48 | |
|
| 1 | 49 | | Assert.AreEqual(questsController, hudController.questsController); |
| 1 | 50 | | Assert.AreEqual(hudView, hudController.view); |
| 1 | 51 | | } |
| | 52 | |
|
| | 53 | | [Test] |
| | 54 | | public void CallViewWhenQuestProgressed() |
| | 55 | | { |
| 1 | 56 | | hudController.Initialize(questsController); |
| 1 | 57 | | questsController.OnQuestUpdated += Raise.Event<QuestUpdated>(MOCK_QUEST_ID, true); |
| | 58 | |
|
| 1 | 59 | | hudView.Received().UpdateQuest(MOCK_QUEST_ID, true); |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | [Test] |
| | 63 | | public void CallViewWhenPinnedQuestAdded() |
| | 64 | | { |
| 1 | 65 | | hudController.Initialize(questsController); |
| 1 | 66 | | DataStore.i.Quests.pinnedQuests.Add(MOCK_QUEST_ID); |
| | 67 | |
|
| 1 | 68 | | hudView.Received().PinQuest(MOCK_QUEST_ID); |
| 1 | 69 | | } |
| | 70 | |
|
| | 71 | | [Test] |
| | 72 | | public void CallViewWhenQuestRemoved() |
| | 73 | | { |
| 1 | 74 | | hudController.Initialize(questsController); |
| 1 | 75 | | DataStore.i.Quests.quests.Remove(MOCK_QUEST_ID); |
| | 76 | |
|
| 1 | 77 | | hudView.Received().RemoveEntry(MOCK_QUEST_ID); |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | [Test] |
| | 81 | | public void CallViewWhenPinnedQuestsSet() |
| | 82 | | { |
| 1 | 83 | | DataStore.i.Quests.quests.Set(new [] |
| | 84 | | { |
| | 85 | | ("newQuest1", new QuestModel { id = "newQuest1" }), |
| | 86 | | ("newQuest2", new QuestModel { id = "newQuest2" }) |
| | 87 | | }); |
| | 88 | |
|
| 1 | 89 | | hudController.Initialize(questsController); |
| 1 | 90 | | DataStore.i.Quests.pinnedQuests.Set(new [] |
| | 91 | | { |
| | 92 | | "newQuest1", "newQuest2" |
| | 93 | | }); |
| 1 | 94 | | hudView.Received().ClearEntries(); |
| 1 | 95 | | hudView.Received().PinQuest("newQuest1"); |
| 1 | 96 | | hudView.Received().PinQuest("newQuest2"); |
| 1 | 97 | | } |
| | 98 | |
|
| | 99 | | [Test] |
| | 100 | | public void CallViewWhenQuestsSet() |
| | 101 | | { |
| 1 | 102 | | DataStore.i.Quests.pinnedQuests.Set(new [] |
| | 103 | | { |
| | 104 | | "newQuest1", "newQuest2" |
| | 105 | | }); |
| 1 | 106 | | hudController.Initialize(questsController); |
| 1 | 107 | | DataStore.i.Quests.quests.Set(new List<(string, QuestModel)> |
| | 108 | | { |
| | 109 | | ("newQuest1", new QuestModel |
| | 110 | | { |
| | 111 | | id = "newQuest1" |
| | 112 | | }), |
| | 113 | | ("newQuest2", new QuestModel |
| | 114 | | { |
| | 115 | | id = "newQuest2" |
| | 116 | | }), |
| | 117 | | }); |
| | 118 | |
|
| 1 | 119 | | hudView.Received().ClearEntries(); |
| 1 | 120 | | hudView.Received().PinQuest("newQuest1"); |
| 1 | 121 | | hudView.Received().PinQuest("newQuest2"); |
| 1 | 122 | | } |
| | 123 | |
|
| | 124 | | [Test] |
| | 125 | | public void CallViewWhenRewardObtained() |
| | 126 | | { |
| 1 | 127 | | hudController.Initialize(questsController); |
| | 128 | |
|
| 1 | 129 | | questsController.OnRewardObtained += Raise.Event<RewardObtained>(MOCK_QUEST_ID, MOCK_REWARD_ID); |
| | 130 | |
|
| 1 | 131 | | hudView.Received().AddReward(MOCK_QUEST_ID, DataStore.i.Quests.quests[MOCK_QUEST_ID].rewards[0]); |
| 1 | 132 | | } |
| | 133 | |
|
| | 134 | | [TearDown] |
| 14 | 135 | | public void TearDown() { DataStore.Clear(); } |
| | 136 | | } |
| | 137 | |
|
| | 138 | | } |