| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.TestTools; |
| | 5 | |
|
| | 6 | | namespace Tests |
| | 7 | | { |
| | 8 | | public class NotificationHudTests : IntegrationTestSuite_Legacy |
| | 9 | | { |
| | 10 | | private NotificationHUDController controller; |
| | 11 | |
|
| | 12 | | protected override IEnumerator SetUp() |
| | 13 | | { |
| 5 | 14 | | yield return base.SetUp(); |
| 5 | 15 | | controller = new NotificationHUDController(); |
| 5 | 16 | | sceneInitialized = false; |
| 5 | 17 | | } |
| | 18 | |
|
| | 19 | | protected override IEnumerator TearDown() |
| | 20 | | { |
| 5 | 21 | | controller.Dispose(); |
| 5 | 22 | | yield return base.TearDown(); |
| 5 | 23 | | } |
| | 24 | |
|
| | 25 | | [Test] |
| | 26 | | public void NotificationHud_Creation() |
| | 27 | | { |
| 1 | 28 | | var views = GameObject.FindObjectsOfType<NotificationHUDView>(); |
| | 29 | |
|
| 1 | 30 | | Assert.AreEqual(1, views.Length); |
| | 31 | |
|
| 1 | 32 | | var view = views[0]; |
| 1 | 33 | | Assert.NotNull(view); |
| 1 | 34 | | Assert.AreEqual(view, controller.view); |
| 1 | 35 | | } |
| | 36 | |
|
| | 37 | | [Test] |
| | 38 | | public void NotificationHud_ModelDefaulted() |
| | 39 | | { |
| 1 | 40 | | Assert.IsNotNull(controller.model); |
| 1 | 41 | | Assert.IsNotNull(controller.model.notifications); |
| 1 | 42 | | Assert.AreEqual(controller.model.notifications.Count, 0); |
| 1 | 43 | | } |
| | 44 | |
|
| | 45 | | [UnityTest] |
| | 46 | | public IEnumerator NotificationHud_ShowNotification() |
| | 47 | | { |
| 1 | 48 | | Notification.Model model = new Notification.Model() |
| | 49 | | { |
| | 50 | | type = NotificationFactory.Type.GENERIC, |
| | 51 | | message = "text", |
| | 52 | | timer = -1, |
| | 53 | | scene = "" |
| | 54 | | }; |
| | 55 | |
|
| 1 | 56 | | controller.ShowNotification(model); |
| | 57 | |
|
| 1 | 58 | | yield return null; |
| | 59 | |
|
| 1 | 60 | | Notification[] notifications = GameObject.FindObjectsOfType<Notification>(); |
| 1 | 61 | | Assert.AreEqual(notifications.Length, 1); |
| | 62 | |
|
| 1 | 63 | | Notification n = notifications[0]; |
| 1 | 64 | | Assert.AreEqual(n.model.type, model.type); |
| 1 | 65 | | Assert.AreEqual(n.model.message, model.message); |
| 1 | 66 | | Assert.AreEqual(n.model.timer, model.timer); |
| 1 | 67 | | Assert.AreEqual(n.model.scene, model.scene); |
| 1 | 68 | | } |
| | 69 | |
|
| | 70 | | [UnityTest] |
| | 71 | | public IEnumerator NotificationHud_ShowSeveralNotifications() |
| | 72 | | { |
| 1 | 73 | | Notification.Model model = new Notification.Model() |
| | 74 | | { |
| | 75 | | type = NotificationFactory.Type.GENERIC, |
| | 76 | | message = "text", |
| | 77 | | timer = -1, |
| | 78 | | scene = "" |
| | 79 | | }; |
| | 80 | |
|
| 1 | 81 | | controller.ShowNotification(model); |
| | 82 | |
|
| 1 | 83 | | Notification.Model model2 = new Notification.Model() |
| | 84 | | { |
| | 85 | | type = NotificationFactory.Type.SCRIPTING_ERROR, |
| | 86 | | message = "text", |
| | 87 | | timer = -1, |
| | 88 | | scene = "" |
| | 89 | | }; |
| | 90 | |
|
| 1 | 91 | | controller.ShowNotification(model2); |
| | 92 | |
|
| 1 | 93 | | yield return null; |
| | 94 | |
|
| 1 | 95 | | Notification[] notifications = GameObject.FindObjectsOfType<Notification>(); |
| 1 | 96 | | Assert.AreEqual(2, notifications.Length); |
| 1 | 97 | | } |
| | 98 | |
|
| | 99 | | [UnityTest] |
| | 100 | | public IEnumerator NotificationHud_ShowTimedNotification() |
| | 101 | | { |
| 1 | 102 | | Notification.Model model = new Notification.Model() |
| | 103 | | { |
| | 104 | | type = NotificationFactory.Type.GENERIC, |
| | 105 | | message = "text", |
| | 106 | | timer = 0.25f, |
| | 107 | | scene = "" |
| | 108 | | }; |
| | 109 | |
|
| 1 | 110 | | controller.ShowNotification(model); |
| 1 | 111 | | yield return null; |
| | 112 | |
|
| 1 | 113 | | Notification[] notifications = GameObject.FindObjectsOfType<Notification>(); |
| 1 | 114 | | Assert.AreEqual(notifications.Length, 1); |
| 1 | 115 | | Assert.AreEqual(controller.model.notifications.Count, 1); |
| | 116 | |
|
| 108 | 117 | | yield return new DCL.WaitUntil(() => notifications.Length == 0, 0.5f); |
| | 118 | |
|
| 1 | 119 | | notifications = GameObject.FindObjectsOfType<Notification>(); |
| 1 | 120 | | Assert.AreEqual(notifications.Length, 0); |
| 1 | 121 | | Assert.AreEqual(controller.model.notifications.Count, 0); |
| 1 | 122 | | } |
| | 123 | | } |
| | 124 | | } |