| | 1 | | using DCL; |
| | 2 | | using DCL.Huds.QuestsTracker; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using System.Collections; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | |
|
| | 8 | | namespace Tests.QuestsNotificationsHUD |
| | 9 | | { |
| | 10 | | public class QuestsNotificationsHUDViewShould |
| | 11 | | { |
| | 12 | | private QuestsNotificationsController controller; |
| | 13 | |
|
| | 14 | | [SetUp] |
| | 15 | | public void SetUp() |
| | 16 | | { |
| | 17 | | // Even though we set duration to 0, we have to wait a frame anyway for the yields to be performed. |
| 2 | 18 | | QuestsNotificationsController.DEFAULT_NOTIFICATION_DURATION = 0f; |
| 2 | 19 | | QuestsNotificationsController.NOTIFICATIONS_SEPARATION = 0f; |
| 2 | 20 | | controller = Object.Instantiate(Resources.Load<GameObject>("QuestsTrackerHUD")).GetComponentInChildren<Quest |
| 2 | 21 | | } |
| | 22 | |
|
| | 23 | | [Test] |
| | 24 | | public void ReactToQuestCompleted() |
| | 25 | | { |
| 1 | 26 | | controller.ShowQuestCompleted(new QuestModel { name = "theName" }); |
| 1 | 27 | | Assert.AreEqual(1, controller.transform.childCount); |
| 1 | 28 | | var notificationComponent = controller.transform.GetChild(0).GetComponent<QuestNotification_QuestCompleted>( |
| 1 | 29 | | Assert.NotNull(notificationComponent); |
| 1 | 30 | | Assert.AreEqual("theName", notificationComponent.questName.text); |
| 1 | 31 | | } |
| | 32 | |
|
| | 33 | | [UnityTest] |
| | 34 | | public IEnumerator ProcessNotificationsQueue() |
| | 35 | | { |
| 1 | 36 | | controller.ShowQuestCompleted(new QuestModel()); |
| 1 | 37 | | controller.ShowQuestCompleted(new QuestModel()); |
| | 38 | |
|
| 1 | 39 | | Assert.AreEqual(2, controller.notificationsQueue.Count); |
| | 40 | |
|
| 1 | 41 | | yield return null; // Wait for notification to go away. |
| 1 | 42 | | yield return null; // Wait for notification time separation. |
| 1 | 43 | | Assert.AreEqual(1, controller.notificationsQueue.Count); |
| | 44 | |
|
| 1 | 45 | | yield return null; // Wait for notification to go away. |
| 1 | 46 | | yield return null; // Wait for notification time separation. |
| 1 | 47 | | Assert.AreEqual(0, controller.notificationsQueue.Count); |
| 1 | 48 | | } |
| | 49 | |
|
| | 50 | | [TearDown] |
| 4 | 51 | | public void TearDown() { Object.Destroy(controller.gameObject); } |
| | 52 | | } |
| | 53 | | } |