| | 1 | | using DCL; |
| | 2 | | using DCL.Huds.QuestsPanel; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace Tests.QuestsPanelHUD |
| | 7 | | { |
| | 8 | | public class QuestsPanelPopupHUDViewShould |
| | 9 | | { |
| | 10 | | private const string MOCK_QUEST_ID = "quest0"; |
| | 11 | | private const string MOCK_SECTION_ID = "section0"; |
| | 12 | | private const string MOCK_TASK_ID = "task0"; |
| | 13 | |
|
| | 14 | | private QuestsPanelHUDView hudView; |
| | 15 | |
|
| | 16 | | [SetUp] |
| | 17 | | public void SetUp() |
| | 18 | | { |
| 6 | 19 | | QuestModel questMock = new QuestModel { id = MOCK_QUEST_ID, }; |
| 6 | 20 | | QuestSection sectionMock = new QuestSection { id = MOCK_SECTION_ID, }; |
| 6 | 21 | | QuestTask taskMock = new QuestTask |
| | 22 | | { |
| | 23 | | id = MOCK_TASK_ID, |
| | 24 | | type = "single", |
| | 25 | | payload = JsonUtility.ToJson(new TaskPayload_Single { isDone = false }) |
| | 26 | | }; |
| 6 | 27 | | sectionMock.tasks = new [] { taskMock }; |
| 6 | 28 | | questMock.sections = new [] { sectionMock }; |
| 6 | 29 | | DataStore.i.Quests.quests.Set(new [] { (questMock.id, questMock) }); |
| | 30 | |
|
| 6 | 31 | | QuestsPanelHUDView.ENTRIES_PER_FRAME = 1; |
| 6 | 32 | | hudView = Object.Instantiate(Resources.Load<GameObject>("QuestsPanelHUD")).GetComponent<QuestsPanelHUDView>( |
| 6 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void PopulateQuestProperly() |
| | 37 | | { |
| 1 | 38 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].name = "name"; |
| 1 | 39 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].description = "description"; |
| 1 | 40 | | hudView.AddOrUpdateQuest(MOCK_QUEST_ID); |
| | 41 | |
|
| 1 | 42 | | hudView.ShowQuestPopup(MOCK_QUEST_ID); |
| | 43 | |
|
| 1 | 44 | | Assert.AreEqual("name", hudView.questPopup.questName.text); |
| 1 | 45 | | Assert.AreEqual("description", hudView.questPopup.description.text); |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | public void PopulateSection() |
| | 50 | | { |
| 1 | 51 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].name = "name"; |
| 1 | 52 | | hudView.AddOrUpdateQuest(MOCK_QUEST_ID); |
| | 53 | |
|
| 1 | 54 | | hudView.ShowQuestPopup(MOCK_QUEST_ID); |
| | 55 | |
|
| 1 | 56 | | Assert.AreEqual("name", hudView.questPopup.sections[0].sectionName.text); |
| 1 | 57 | | } |
| | 58 | |
|
| | 59 | | [Test] |
| | 60 | | [TestCase(false, true)] |
| | 61 | | [TestCase(true, false)] |
| | 62 | | public void PopulateTask_Single(bool isDone, bool hasCoordinates) |
| | 63 | | { |
| 2 | 64 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].name = "name"; |
| 2 | 65 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].type = "single"; |
| 2 | 66 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].progress = isDone ? 1 : 0; |
| 2 | 67 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].coordinates = hasCoordinates ? "/goto 0,0" : n |
| 2 | 68 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].payload = JsonUtility.ToJson(new TaskPayload_S |
| 2 | 69 | | hudView.AddOrUpdateQuest(MOCK_QUEST_ID); |
| | 70 | |
|
| 2 | 71 | | hudView.ShowQuestPopup(MOCK_QUEST_ID); |
| | 72 | |
|
| 2 | 73 | | QuestsPanelTask_Single taskEntry = hudView.questPopup.sections[0].tasksContainer.GetComponentInChildren<Ques |
| | 74 | |
|
| 2 | 75 | | Assert.NotNull(taskEntry); |
| 2 | 76 | | Assert.AreEqual("name", taskEntry.taskName.text); |
| 2 | 77 | | Assert.AreEqual(isDone, taskEntry.status.isOn); |
| 2 | 78 | | Assert.AreEqual(hasCoordinates, taskEntry.jumpInButton.gameObject.activeSelf); |
| 2 | 79 | | } |
| | 80 | |
|
| | 81 | | [Test] |
| | 82 | | [TestCase(0, 1, 2, true)] |
| | 83 | | [TestCase(10, 13, 20, false)] |
| | 84 | | public void PopulateTask_Numeric(int start, int current, int end, bool hasCoordinates) |
| | 85 | | { |
| 2 | 86 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].name = "name"; |
| 2 | 87 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].type = "numeric"; |
| 2 | 88 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].progress = Mathf.InverseLerp(start, end, curre |
| 2 | 89 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].coordinates = hasCoordinates ? "/goto 0,0" : n |
| 2 | 90 | | DataStore.i.Quests.quests[MOCK_QUEST_ID].sections[0].tasks[0].payload = JsonUtility.ToJson(new TaskPayload_N |
| | 91 | | { |
| | 92 | | start = start, |
| | 93 | | current = current, |
| | 94 | | end = end |
| | 95 | | }); |
| 2 | 96 | | hudView.AddOrUpdateQuest(MOCK_QUEST_ID); |
| | 97 | |
|
| 2 | 98 | | hudView.ShowQuestPopup(MOCK_QUEST_ID); |
| | 99 | |
|
| 2 | 100 | | QuestsPanelTask_Numeric taskEntry = hudView.questPopup.sections[0].tasksContainer.GetComponentInChildren<Que |
| | 101 | |
|
| 2 | 102 | | Assert.NotNull(taskEntry); |
| 2 | 103 | | Assert.AreEqual("name", taskEntry.taskName.text); |
| 2 | 104 | | Assert.AreEqual(Mathf.InverseLerp(start, end, current), taskEntry.ongoingProgress.transform.localScale.x); |
| 2 | 105 | | Assert.AreEqual(hasCoordinates, taskEntry.jumpInButton.gameObject.activeSelf); |
| 2 | 106 | | } |
| | 107 | |
|
| | 108 | | [TearDown] |
| 12 | 109 | | public void TearDown() { Object.Destroy(hudView.gameObject); } |
| | 110 | | } |
| | 111 | | } |