< Summary

Class:UnreadWorldNotificationBadgeShould
Assembly:NotificationBadgeTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/Tests/UnreadWorldNotificationBadgeShould.cs
Covered lines:35
Uncovered lines:0
Coverable lines:35
Total lines:118
Line coverage:100% (35 of 35)
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%
NotReceiveUnreadNotificationsBecauseOfPrivateMessage()0%110100%
NotReceiveUnreadNotificationsBecauseOfSenderIsThePlayer()0%110100%
CleanAllUnreadNotifications()0%110100%
ReadLastMessages()0%110100%

File(s)

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

#LineLine coverage
 1using DCL.Interface;
 2using NUnit.Framework;
 3using System.Collections;
 4using UnityEngine;
 5using UnityEngine.TestTools;
 6
 7public 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    {
 518        chatController = new ChatController_Mock();
 19
 520        GameObject go = Object.Instantiate((GameObject)Resources.Load(UNREAD_NOTIFICATION_BADGE_RESOURCE_NAME));
 521        unreadWorldNotificationBadge = go.GetComponent<UnreadWorldNotificationBadge>();
 522        unreadWorldNotificationBadge.Initialize(chatController);
 23
 524        Assert.AreEqual(0, unreadWorldNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notificati
 525        Assert.AreEqual(false, unreadWorldNotificationBadge.notificationContainer.activeSelf, "Notificaton container sho
 26
 527        yield break;
 28    }
 29
 30    protected override IEnumerator TearDown()
 31    {
 532        Object.Destroy(unreadWorldNotificationBadge.gameObject);
 533        yield break;
 34    }
 35
 36    [Test]
 37    public void ReceiveOneUnreadNotification()
 38    {
 239        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
 248        Assert.AreEqual(1, unreadWorldNotificationBadge.currentUnreadMessages, "There should be 1 unread notification");
 249        Assert.AreEqual(true, unreadWorldNotificationBadge.notificationContainer.activeSelf, "Notificaton container shou
 250        Assert.AreEqual("1", unreadWorldNotificationBadge.notificationText.text, "Notification text should be 1");
 251    }
 52
 53    [Test]
 54    public void ReceiveSeveralUnreadNotifications()
 55    {
 156        unreadWorldNotificationBadge.maxNumberToShow = 9;
 57
 2258        for (int i = 0; i < unreadWorldNotificationBadge.maxNumberToShow + 1; i++)
 59        {
 1060            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
 170        Assert.AreEqual(unreadWorldNotificationBadge.maxNumberToShow + 1, unreadWorldNotificationBadge.currentUnreadMess
 171        Assert.AreEqual(true, unreadWorldNotificationBadge.notificationContainer.activeSelf, "Notificaton container shou
 172        Assert.AreEqual(string.Format("+{0}", unreadWorldNotificationBadge.maxNumberToShow), unreadWorldNotificationBadg
 173    }
 74
 75    [Test]
 76    public void NotReceiveUnreadNotificationsBecauseOfPrivateMessage()
 77    {
 178        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
 187        Assert.AreEqual(0, unreadWorldNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notificati
 188        Assert.AreEqual(false, unreadWorldNotificationBadge.notificationContainer.activeSelf, "Notificaton container sho
 189    }
 90
 91    [Test]
 92    public void NotReceiveUnreadNotificationsBecauseOfSenderIsThePlayer()
 93    {
 194        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
 1103        Assert.AreEqual(0, unreadWorldNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notificati
 1104        Assert.AreEqual(false, unreadWorldNotificationBadge.notificationContainer.activeSelf, "Notificaton container sho
 1105    }
 106
 107    [Test]
 108    public void CleanAllUnreadNotifications()
 109    {
 1110        ReceiveOneUnreadNotification();
 1111        ReadLastMessages();
 112
 1113        Assert.AreEqual(0, unreadWorldNotificationBadge.currentUnreadMessages, "There shouldn't be any unread notificati
 1114        Assert.AreEqual(false, unreadWorldNotificationBadge.notificationContainer.activeSelf, "Notificaton container sho
 1115    }
 116
 2117    private static void ReadLastMessages() { CommonScriptableObjects.lastReadWorldChatMessages.Set(System.DateTimeOffset
 118}