| | 1 | | using DCL.Interface; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.TestTools; |
| | 6 | |
|
| | 7 | | public class UnreadNotificationBadgeShould : IntegrationTestSuite_Legacy |
| | 8 | | { |
| | 9 | | private const string UNREAD_NOTIFICATION_BADGE_RESOURCE_NAME = "UnreadNotificationBadge"; |
| | 10 | | private const string TEST_USER_ID = "testFriend"; |
| | 11 | | private const string INVALID_TEST_USER_ID = "invalidTestFriend"; |
| | 12 | |
|
| | 13 | | private ChatController_Mock chatController; |
| | 14 | | private UnreadNotificationBadge unreadNotificationBadge; |
| | 15 | |
|
| | 16 | | [UnitySetUp] |
| | 17 | | protected override IEnumerator SetUp() |
| | 18 | | { |
| 6 | 19 | | chatController = new ChatController_Mock(); |
| | 20 | |
|
| 6 | 21 | | GameObject go = Object.Instantiate((GameObject)Resources.Load(UNREAD_NOTIFICATION_BADGE_RESOURCE_NAME)); |
| 6 | 22 | | unreadNotificationBadge = go.GetComponent<UnreadNotificationBadge>(); |
| 6 | 23 | | unreadNotificationBadge.Initialize(chatController, TEST_USER_ID); |
| | 24 | |
|
| 6 | 25 | | CommonScriptableObjects.lastReadChatMessages.Remove(TEST_USER_ID); |
| 6 | 26 | | CommonScriptableObjects.lastReadChatMessages.Remove(INVALID_TEST_USER_ID); |
| | 27 | |
|
| 6 | 28 | | Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification af |
| 6 | 29 | | Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b |
| | 30 | |
|
| 6 | 31 | | yield break; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | protected override IEnumerator TearDown() |
| | 35 | | { |
| 6 | 36 | | Object.Destroy(unreadNotificationBadge.gameObject); |
| 6 | 37 | | CommonScriptableObjects.lastReadChatMessages.Remove(TEST_USER_ID); |
| 6 | 38 | | CommonScriptableObjects.lastReadChatMessages.Remove(INVALID_TEST_USER_ID); |
| 6 | 39 | | yield break; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | [Test] |
| | 43 | | public void ReceiveOneUnreadNotification() |
| | 44 | | { |
| 3 | 45 | | chatController.RaiseAddMessage(new ChatMessage |
| | 46 | | { |
| | 47 | | messageType = ChatMessage.Type.PRIVATE, |
| | 48 | | sender = TEST_USER_ID, |
| | 49 | | body = "test body", |
| | 50 | | recipient = "test recipient", |
| | 51 | | timestamp = (ulong) System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() |
| | 52 | | }); |
| | 53 | |
|
| 3 | 54 | | Assert.AreEqual(1, unreadNotificationBadge.currentUnreadMessages, "There should be 1 unread notification"); |
| 3 | 55 | | Assert.AreEqual(true, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should be |
| 3 | 56 | | Assert.AreEqual("1", unreadNotificationBadge.notificationText.text, "Notification text should be 1"); |
| 3 | 57 | | } |
| | 58 | |
|
| | 59 | | [Test] |
| | 60 | | public void ReceiveSeveralUnreadNotifications() |
| | 61 | | { |
| 1 | 62 | | unreadNotificationBadge.maxNumberToShow = 9; |
| | 63 | |
|
| 22 | 64 | | for (int i = 0; i < unreadNotificationBadge.maxNumberToShow + 1; i++) |
| | 65 | | { |
| 10 | 66 | | chatController.RaiseAddMessage(new ChatMessage |
| | 67 | | { |
| | 68 | | messageType = ChatMessage.Type.PRIVATE, |
| | 69 | | sender = TEST_USER_ID, |
| | 70 | | body = string.Format("test body {0}", i + 1), |
| | 71 | | recipient = "test recipient", |
| | 72 | | timestamp = (ulong)System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() |
| | 73 | | }); |
| | 74 | | } |
| | 75 | |
|
| 1 | 76 | | Assert.AreEqual(unreadNotificationBadge.maxNumberToShow + 1, unreadNotificationBadge.currentUnreadMessages, "The |
| 1 | 77 | | Assert.AreEqual(true, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should be |
| 1 | 78 | | Assert.AreEqual(string.Format("+{0}", unreadNotificationBadge.maxNumberToShow), unreadNotificationBadge.notifica |
| 1 | 79 | | } |
| | 80 | |
|
| | 81 | | [Test] |
| | 82 | | public void NotReceiveUnreadNotificationsBecauseOfPublicMessage() |
| | 83 | | { |
| 1 | 84 | | chatController.RaiseAddMessage(new ChatMessage |
| | 85 | | { |
| | 86 | | messageType = ChatMessage.Type.PUBLIC, |
| | 87 | | sender = TEST_USER_ID, |
| | 88 | | body = "test body", |
| | 89 | | recipient = "test recipient", |
| | 90 | | timestamp = (ulong)System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() |
| | 91 | | }); |
| | 92 | |
|
| 1 | 93 | | Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification"); |
| 1 | 94 | | Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b |
| 1 | 95 | | } |
| | 96 | |
|
| | 97 | | [Test] |
| | 98 | | public void NotReceiveUnreadNotificationsBecauseOfDifferentUser() |
| | 99 | | { |
| 1 | 100 | | chatController.RaiseAddMessage(new ChatMessage |
| | 101 | | { |
| | 102 | | messageType = ChatMessage.Type.PRIVATE, |
| | 103 | | sender = INVALID_TEST_USER_ID, |
| | 104 | | body = "test body", |
| | 105 | | recipient = "test recipient", |
| | 106 | | timestamp = (ulong)System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() |
| | 107 | | }); |
| | 108 | |
|
| 1 | 109 | | Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification"); |
| 1 | 110 | | Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b |
| 1 | 111 | | } |
| | 112 | |
|
| | 113 | | [Test] |
| | 114 | | public void CleanAllUnreadNotifications() |
| | 115 | | { |
| 1 | 116 | | ReceiveOneUnreadNotification(); |
| 1 | 117 | | ReadLastMessages(TEST_USER_ID); |
| | 118 | |
|
| 1 | 119 | | Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification"); |
| 1 | 120 | | Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b |
| 1 | 121 | | } |
| | 122 | |
|
| | 123 | | [Test] |
| | 124 | | public void NotCleanUnreadNotificationsBecauseOfFifferentUser() |
| | 125 | | { |
| 1 | 126 | | ReceiveOneUnreadNotification(); |
| 1 | 127 | | ReadLastMessages(INVALID_TEST_USER_ID); |
| | 128 | |
|
| 1 | 129 | | Assert.AreEqual(1, unreadNotificationBadge.currentUnreadMessages, "There should be 1 unread notification"); |
| 1 | 130 | | Assert.AreEqual(true, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should be |
| 1 | 131 | | Assert.AreEqual("1", unreadNotificationBadge.notificationText.text, "Notification text should be 1"); |
| 1 | 132 | | } |
| | 133 | |
|
| 4 | 134 | | private static void ReadLastMessages(string userId) { CommonScriptableObjects.lastReadChatMessages.Add(userId, Syste |
| | 135 | | } |