< Summary

Class:UnreadNotificationBadgeShould
Assembly:NotificationBadgeTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/Tests/UnreadNotificationBadgeShould.cs
Covered lines:45
Uncovered lines:0
Coverable lines:45
Total lines:135
Line coverage:100% (45 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%220100%
TearDown()0%220100%
ReceiveOneUnreadNotification()0%110100%
ReceiveSeveralUnreadNotifications()0%220100%
NotReceiveUnreadNotificationsBecauseOfPublicMessage()0%110100%
NotReceiveUnreadNotificationsBecauseOfDifferentUser()0%110100%
CleanAllUnreadNotifications()0%110100%
NotCleanUnreadNotificationsBecauseOfFifferentUser()0%110100%
ReadLastMessages(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/Tests/UnreadNotificationBadgeShould.cs

#LineLine coverage
 1using DCL.Interface;
 2using NUnit.Framework;
 3using System.Collections;
 4using UnityEngine;
 5using UnityEngine.TestTools;
 6
 7public 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    {
 619        chatController = new ChatController_Mock();
 20
 621        GameObject go = Object.Instantiate((GameObject)Resources.Load(UNREAD_NOTIFICATION_BADGE_RESOURCE_NAME));
 622        unreadNotificationBadge = go.GetComponent<UnreadNotificationBadge>();
 623        unreadNotificationBadge.Initialize(chatController, TEST_USER_ID);
 24
 625        CommonScriptableObjects.lastReadChatMessages.Remove(TEST_USER_ID);
 626        CommonScriptableObjects.lastReadChatMessages.Remove(INVALID_TEST_USER_ID);
 27
 628        Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification af
 629        Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b
 30
 631        yield break;
 32    }
 33
 34    protected override IEnumerator TearDown()
 35    {
 636        Object.Destroy(unreadNotificationBadge.gameObject);
 637        CommonScriptableObjects.lastReadChatMessages.Remove(TEST_USER_ID);
 638        CommonScriptableObjects.lastReadChatMessages.Remove(INVALID_TEST_USER_ID);
 639        yield break;
 40    }
 41
 42    [Test]
 43    public void ReceiveOneUnreadNotification()
 44    {
 345        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
 354        Assert.AreEqual(1, unreadNotificationBadge.currentUnreadMessages, "There should be 1 unread notification");
 355        Assert.AreEqual(true, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should be
 356        Assert.AreEqual("1", unreadNotificationBadge.notificationText.text, "Notification text should be 1");
 357    }
 58
 59    [Test]
 60    public void ReceiveSeveralUnreadNotifications()
 61    {
 162        unreadNotificationBadge.maxNumberToShow = 9;
 63
 2264        for (int i = 0; i < unreadNotificationBadge.maxNumberToShow + 1; i++)
 65        {
 1066            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
 176        Assert.AreEqual(unreadNotificationBadge.maxNumberToShow + 1, unreadNotificationBadge.currentUnreadMessages, "The
 177        Assert.AreEqual(true, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should be
 178        Assert.AreEqual(string.Format("+{0}", unreadNotificationBadge.maxNumberToShow), unreadNotificationBadge.notifica
 179    }
 80
 81    [Test]
 82    public void NotReceiveUnreadNotificationsBecauseOfPublicMessage()
 83    {
 184        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
 193        Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification");
 194        Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b
 195    }
 96
 97    [Test]
 98    public void NotReceiveUnreadNotificationsBecauseOfDifferentUser()
 99    {
 1100        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
 1109        Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification");
 1110        Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b
 1111    }
 112
 113    [Test]
 114    public void CleanAllUnreadNotifications()
 115    {
 1116        ReceiveOneUnreadNotification();
 1117        ReadLastMessages(TEST_USER_ID);
 118
 1119        Assert.AreEqual(0, unreadNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notification");
 1120        Assert.AreEqual(false, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should b
 1121    }
 122
 123    [Test]
 124    public void NotCleanUnreadNotificationsBecauseOfFifferentUser()
 125    {
 1126        ReceiveOneUnreadNotification();
 1127        ReadLastMessages(INVALID_TEST_USER_ID);
 128
 1129        Assert.AreEqual(1, unreadNotificationBadge.currentUnreadMessages, "There should be 1 unread notification");
 1130        Assert.AreEqual(true, unreadNotificationBadge.notificationContainer.activeSelf, "Notificaton container should be
 1131        Assert.AreEqual("1", unreadNotificationBadge.notificationText.text, "Notification text should be 1");
 1132    }
 133
 4134    private static void ReadLastMessages(string userId) { CommonScriptableObjects.lastReadChatMessages.Add(userId, Syste
 135}