< Summary

Class:FriendsHUDControllerShould
Assembly:FriendsHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Tests/FriendsHUDControllerShould.cs
Covered lines:114
Uncovered lines:0
Coverable lines:114
Total lines:218
Line coverage:100% (114 of 114)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
TearDown()0%330100%
ReactCorrectlyToWhisperClick()0%330100%
ReactCorrectlyToReportClick()0%330100%
ReactCorrectlyToPassportClick()0%330100%
HandleUsernameErrorCorrectly()0%110100%
SendFriendRequestCorrectly()0%110100%
ReactCorrectlyToFriendApproved()0%330100%
ReactCorrectlyToFriendRejected()0%330100%
ReactCorrectlyToFriendCancelled()0%330100%
GetBadge(...)0%110100%
TaskbarNotificationBadgeHasCorrectValue()0%990100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Tests/FriendsHUDControllerShould.cs

#LineLine coverage
 1using DCL.Interface;
 2using NUnit.Framework;
 3using System;
 4using System.Collections;
 5using DCL.Helpers;
 6using UnityEngine;
 7using UnityEngine.TestTools;
 8
 9public class FriendsHUDControllerShould : IntegrationTestSuite_Legacy
 10{
 11    FriendsHUDController controller;
 12    FriendsHUDView view;
 13    FriendsController_Mock friendsController;
 14
 915    protected override bool justSceneSetUp => true;
 16
 17    [UnitySetUp]
 18    protected override IEnumerator SetUp()
 19    {
 920        yield return base.SetUp();
 21
 922        NotificationsController.i.Initialize(new NotificationHUDController());
 23
 924        controller = new FriendsHUDController();
 925        friendsController = new FriendsController_Mock();
 926        controller.Initialize(friendsController, UserProfile.GetOwnUserProfile());
 927        this.view = controller.view;
 28
 929        Assert.IsTrue(view != null, "Friends hud view is null?");
 930        Assert.IsTrue(controller != null, "Friends hud controller is null?");
 931    }
 32
 33    protected override IEnumerator TearDown()
 34    {
 935        NotificationsController.i.Dispose();
 936        controller.Dispose();
 37
 938        yield return base.TearDown();
 939    }
 40
 41    [UnityTest]
 42    public IEnumerator ReactCorrectlyToWhisperClick()
 43    {
 144        var id = "test-id-1";
 145        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id);
 146        var entry = TestHelpers_Friends.GetEntry(view, id);
 147        Assert.IsNotNull(entry);
 48
 149        bool pressedWhisper = false;
 350        controller.OnPressWhisper += (x) => { pressedWhisper = x == id; };
 151        entry.whisperButton.onClick.Invoke();
 152        Assert.IsTrue(pressedWhisper);
 153    }
 54
 55    [UnityTest]
 56    public IEnumerator ReactCorrectlyToReportClick()
 57    {
 158        var id = "test-id-1";
 159        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id);
 160        var entry = TestHelpers_Friends.GetEntry(view, id);
 161        Assert.IsNotNull(entry);
 62
 163        bool reportPlayerSent = false;
 64
 165        Action<string, string> callback =
 66            (name, payload) =>
 67            {
 168                if (name == "ReportPlayer")
 69                {
 170                    reportPlayerSent = true;
 71                }
 172            };
 73
 174        WebInterface.OnMessageFromEngine += callback;
 75
 176        entry.menuButton.onClick.Invoke();
 77
 178        Assert.IsTrue(controller.view.friendsList.contextMenuPanel.gameObject.activeSelf);
 79
 180        controller.view.friendsList.contextMenuPanel.reportButton.onClick.Invoke();
 81
 182        Assert.IsTrue(reportPlayerSent);
 83
 184        WebInterface.OnMessageFromEngine -= callback;
 185    }
 86
 87    [UnityTest]
 88    public IEnumerator ReactCorrectlyToPassportClick()
 89    {
 190        var id = "test-id-1";
 191        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id);
 192        var entry = TestHelpers_Friends.GetEntry(view, id);
 193        Assert.IsNotNull(entry);
 94
 195        var currentPlayerId = Resources.Load<StringVariable>(UserContextMenu.CURRENT_PLAYER_ID);
 96
 197        entry.menuButton.onClick.Invoke();
 198        Assert.AreNotEqual(id, currentPlayerId.Get());
 99
 1100        view.friendsList.contextMenuPanel.passportButton.onClick.Invoke();
 101
 1102        Assert.AreEqual(id, currentPlayerId.Get());
 1103    }
 104
 105    [Test]
 2106    public void HandleUsernameErrorCorrectly() { friendsController.RaiseOnFriendNotFound("test"); }
 107
 108    [Test]
 109    public void SendFriendRequestCorrectly()
 110    {
 1111        bool messageSent = false;
 112
 1113        string id = "user test";
 1114        Action<string, string> callback = (name, payload) =>
 115        {
 1116            var msg = JsonUtility.FromJson<FriendsController.FriendshipUpdateStatusMessage>(payload);
 1117            if (msg.action == FriendshipAction.REQUESTED_TO &&
 118                msg.userId == id)
 119            {
 1120                messageSent = true;
 121            }
 1122        };
 123
 1124        WebInterface.OnMessageFromEngine += callback;
 125
 1126        view.friendRequestsList.friendSearchInputField.onSubmit.Invoke(id);
 127
 1128        Assert.IsTrue(messageSent);
 129
 1130        WebInterface.OnMessageFromEngine -= callback;
 1131    }
 132
 133    [UnityTest]
 134    public IEnumerator ReactCorrectlyToFriendApproved()
 135    {
 1136        var id = "test-id-1";
 1137        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id, FriendshipAction.APPROVED);
 1138        var entry = TestHelpers_Friends.GetEntry(view, id);
 1139        Assert.IsNotNull(entry);
 140
 1141        friendsController.RaiseUpdateFriendship(id, FriendshipAction.DELETED);
 1142        entry = controller.view.friendsList.GetEntry(id) as FriendEntry;
 1143        Assert.IsNull(entry);
 1144    }
 145
 146    [UnityTest]
 147    public IEnumerator ReactCorrectlyToFriendRejected()
 148    {
 1149        var id = "test-id-1";
 1150        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id);
 1151        var fentry = TestHelpers_Friends.GetEntry(view, id);
 1152        Assert.IsNotNull(fentry);
 153
 1154        friendsController.RaiseUpdateFriendship(id, FriendshipAction.REQUESTED_FROM);
 1155        friendsController.RaiseUpdateFriendship(id, FriendshipAction.REJECTED);
 156
 1157        var entry = controller.view.friendRequestsList.GetEntry(id);
 1158        Assert.IsNull(entry);
 1159    }
 160
 161    [UnityTest]
 162    public IEnumerator ReactCorrectlyToFriendCancelled()
 163    {
 1164        var id = "test-id-1";
 1165        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id);
 166
 1167        friendsController.RaiseUpdateFriendship(id, FriendshipAction.REQUESTED_TO);
 1168        var entry = controller.view.friendRequestsList.GetEntry(id);
 1169        Assert.IsNotNull(entry);
 1170        friendsController.RaiseUpdateFriendship(id, FriendshipAction.CANCELLED);
 1171        entry = controller.view.friendRequestsList.GetEntry(id);
 1172        Assert.IsNull(entry);
 1173    }
 174
 175    NotificationBadge GetBadge(string path)
 176    {
 2177        GameObject prefab = Resources.Load(path) as GameObject;
 2178        Assert.IsTrue(prefab != null);
 2179        GameObject go = this.InstantiateTestGameObject(prefab);
 2180        Assert.IsTrue(go != null);
 181
 2182        var noti = go.GetComponent<NotificationBadge>();
 2183        noti.Initialize();
 184
 2185        return noti;
 186    }
 187
 188    [UnityTest]
 189    public IEnumerator TaskbarNotificationBadgeHasCorrectValue()
 190    {
 1191        PlayerPrefsUtils.SetInt(FriendsHUDController.PLAYER_PREFS_SEEN_FRIEND_COUNT, 0);
 192
 1193        var friendsRequestBadge = GetBadge("NotificationBadge_FriendsRequestTab");
 1194        var friendsTaskbarBadge = GetBadge("NotificationBadge_FriendsButton");
 195
 1196        controller.SetVisibility(false);
 197
 1198        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-1");
 1199        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-2");
 1200        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-3");
 1201        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-4");
 1202        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-5", FriendshipAction.REQUESTED_F
 203
 1204        Assert.AreEqual(1, friendsRequestBadge.finalValue);
 1205        Assert.AreEqual(5, friendsTaskbarBadge.finalValue);
 206
 1207        controller.SetVisibility(true);
 208
 1209        Assert.AreEqual(1, friendsRequestBadge.finalValue);
 1210        Assert.AreEqual(1, friendsTaskbarBadge.finalValue);
 211
 1212        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-5", FriendshipAction.APPROVED);
 1213        yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-6", FriendshipAction.REQUESTED_F
 214
 1215        Assert.AreEqual(1, friendsRequestBadge.finalValue);
 1216        Assert.AreEqual(1, friendsTaskbarBadge.finalValue);
 1217    }
 218}