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