< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
TearDown()0%330100%
ChangeContentWhenClickingTabs()0%110100%
PopulateFriendListCorrectly()0%330100%
RemoveFriendCorrectly()0%110100%
PopulateFriendRequestCorrectly()0%110100%
CountProperlyStatus()0%330100%
OpenContextMenuProperly()0%330100%
DeleteFriendProperly()0%330100%
RejectIncomingFriendRequestsProperly()0%110100%
SendAndCancelFriendRequestsProperly()0%110100%
RequestCreateFriendEntry(...)0%110100%
GetFriendEntry(...)0%110100%
CreateFriendRequestEntry(...)0%110100%

File(s)

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

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections;
 3using UnityEngine;
 4using UnityEngine.TestTools;
 5
 6public class FriendsHUDViewShould : IntegrationTestSuite_Legacy
 7{
 8    FriendsHUDController controller;
 9    FriendsHUDView view;
 10
 911    protected override bool justSceneSetUp => true;
 12
 13    [UnitySetUp]
 14    protected override IEnumerator SetUp()
 15    {
 916        yield return base.SetUp();
 17
 918        controller = new FriendsHUDController();
 919        controller.Initialize(null, null);
 920        this.view = controller.view;
 21
 922        Assert.IsTrue(view != null, "Friends hud view is null?");
 923        Assert.IsTrue(controller != null, "Friends hud controller is null?");
 924    }
 25
 26    protected override IEnumerator TearDown()
 27    {
 928        controller.Dispose();
 929        yield return base.TearDown();
 930    }
 31
 32    [Test]
 33    public void ChangeContentWhenClickingTabs()
 34    {
 135        controller.view.friendsButton.onClick.Invoke();
 36
 137        Assert.IsTrue(controller.view.friendsList.gameObject.activeSelf);
 138        Assert.IsFalse(controller.view.friendRequestsList.gameObject.activeSelf);
 39
 140        controller.view.friendRequestsButton.onClick.Invoke();
 41
 142        Assert.IsFalse(controller.view.friendsList.gameObject.activeSelf);
 143        Assert.IsTrue(controller.view.friendRequestsList.gameObject.activeSelf);
 144    }
 45
 46    [UnityTest]
 47    public IEnumerator PopulateFriendListCorrectly()
 48    {
 149        string id1 = "userId-1";
 150        string id2 = "userId-2";
 51
 152        RequestCreateFriendEntry(id1, "Pravus", PresenceStatus.ONLINE);
 153        RequestCreateFriendEntry(id2, "Brian", PresenceStatus.OFFLINE);
 354        yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0);
 155        var entry1 = GetFriendEntry( id1);
 156        var entry2 = GetFriendEntry( id2);
 57
 158        Assert.IsNotNull(entry1);
 159        Assert.AreEqual(entry1.model.userName, entry1.playerNameText.text);
 160        Assert.AreEqual(controller.view.friendsList.onlineFriendsList.container, entry1.transform.parent);
 61
 162        Assert.IsNotNull(entry2);
 163        Assert.AreEqual(entry2.model.userName, entry2.playerNameText.text);
 164        Assert.AreEqual(controller.view.friendsList.offlineFriendsList.container, entry2.transform.parent);
 65
 166        var model2 = entry2.model;
 167        model2.status = PresenceStatus.ONLINE;
 168        controller.view.friendsList.CreateOrUpdateEntryDeferred(id2, model2);
 69
 170        Assert.AreEqual(controller.view.friendsList.onlineFriendsList.container, entry2.transform.parent);
 171    }
 72
 73    [Test]
 74    public void RemoveFriendCorrectly()
 75    {
 176        string id1 = "userId-1";
 77
 178        controller.view.friendRequestsList.CreateOrUpdateEntry(id1, new FriendEntry.Model(), isReceived: true);
 79
 180        Assert.IsNotNull(controller.view.friendRequestsList.GetEntry(id1));
 81
 182        controller.view.friendRequestsList.RemoveEntry(id1);
 83
 184        Assert.IsNull(controller.view.friendRequestsList.GetEntry(id1));
 185    }
 86
 87    [Test]
 88    public void PopulateFriendRequestCorrectly()
 89    {
 190        string id1 = "userId-1";
 191        string id2 = "userId-2";
 92
 193        var entry1 = CreateFriendRequestEntry(id1, "Pravus", true);
 194        var entry2 = CreateFriendRequestEntry(id2, "Brian", false);
 95
 196        Assert.IsNotNull(entry1);
 197        Assert.AreEqual("Pravus", entry1.playerNameText.text);
 198        Assert.AreEqual(controller.view.friendRequestsList.receivedRequestsList.container, entry1.transform.parent);
 99
 1100        Assert.IsNotNull(entry2);
 1101        Assert.AreEqual("Brian", entry2.playerNameText.text);
 1102        Assert.AreEqual(controller.view.friendRequestsList.sentRequestsList.container, entry2.transform.parent);
 103
 1104        controller.view.friendRequestsList.UpdateEntry(id2, entry2.model, true);
 1105        Assert.AreEqual(controller.view.friendRequestsList.receivedRequestsList.container, entry2.transform.parent);
 1106    }
 107
 108    [UnityTest]
 109    public IEnumerator CountProperlyStatus()
 110    {
 1111        RequestCreateFriendEntry("user1", "Armando Barreda", PresenceStatus.ONLINE);
 1112        RequestCreateFriendEntry("user2", "Guillermo Andino", PresenceStatus.ONLINE);
 113
 1114        RequestCreateFriendEntry("user3", "Wanda Nara", PresenceStatus.OFFLINE);
 1115        RequestCreateFriendEntry("user4", "Mirtha Legrand", PresenceStatus.OFFLINE);
 116
 3117        yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0);
 118
 1119        Assert.AreEqual(2, view.friendsList.onlineFriendsList.Count());
 1120        Assert.AreEqual(2, view.friendsList.offlineFriendsList.Count());
 121
 1122        view.friendsList.RemoveEntry("user1");
 1123        view.friendsList.RemoveEntry("user3");
 124
 1125        Assert.AreEqual(1, view.friendsList.onlineFriendsList.Count());
 1126        Assert.AreEqual(1, view.friendsList.offlineFriendsList.Count());
 1127    }
 128
 129    [UnityTest]
 130    public IEnumerator OpenContextMenuProperly()
 131    {
 1132        string id1 = "userId-1";
 1133        RequestCreateFriendEntry(id1, "Pravus");
 3134        yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0);
 1135        var entry = GetFriendEntry(id1);
 136
 1137        bool onMenuToggleCalled = false;
 138
 3139        System.Action<FriendEntryBase> callback = (x) => { onMenuToggleCalled = true; };
 140
 1141        Assert.IsFalse(view.friendsList.contextMenuPanel.gameObject.activeSelf);
 142
 1143        entry.OnMenuToggle += callback;
 1144        entry.menuButton.onClick.Invoke();
 1145        entry.OnMenuToggle -= callback;
 146
 1147        Assert.IsTrue(onMenuToggleCalled);
 1148        Assert.IsTrue(view.friendsList.contextMenuPanel.gameObject.activeSelf);
 1149    }
 150
 151    [UnityTest]
 152    public IEnumerator DeleteFriendProperly()
 153    {
 1154        string id1 = "userId-1";
 1155        RequestCreateFriendEntry(id1, "Ted Bundy");
 3156        yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0);
 1157        var entry = GetFriendEntry(id1);
 158
 1159        entry.menuButton.onClick.Invoke();
 160
 1161        view.friendsList.contextMenuPanel.deleteFriendButton.onClick.Invoke();
 1162        view.friendsList.confirmationDialog.confirmButton.onClick.Invoke();
 163
 1164        Assert.IsNull(view.friendsList.GetEntry(id1));
 1165    }
 166
 167    [Test]
 168    public void RejectIncomingFriendRequestsProperly()
 169    {
 170        //NOTE(Brian): Confirm cancellation
 1171        var entry = CreateFriendRequestEntry("id1", "Padre Grassi", isReceived: true);
 172
 1173        entry.rejectButton.onClick.Invoke();
 174
 1175        Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 176
 1177        view.friendRequestsList.confirmationDialog.confirmButton.onClick.Invoke();
 178
 1179        Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 1180        Assert.IsNull(view.friendRequestsList.GetEntry(entry.userId));
 181
 182        //NOTE(Brian): Deny cancellation
 1183        var entry2 = CreateFriendRequestEntry("id1", "Warren Buffet", isReceived: true);
 184
 1185        entry2.rejectButton.onClick.Invoke();
 186
 1187        Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 188
 1189        view.friendRequestsList.confirmationDialog.cancelButton.onClick.Invoke();
 190
 1191        Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 1192        Assert.IsNotNull(view.friendRequestsList.GetEntry(entry2.userId));
 1193    }
 194
 195    [Test]
 196    public void SendAndCancelFriendRequestsProperly()
 197    {
 198        //NOTE(Brian): Confirm cancellation
 1199        var entry = CreateFriendRequestEntry("id1", "Padre Grassi", isReceived: false);
 200
 1201        entry.cancelButton.onClick.Invoke();
 202
 1203        Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 204
 1205        view.friendRequestsList.confirmationDialog.confirmButton.onClick.Invoke();
 206
 1207        Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 1208        Assert.IsNull(view.friendRequestsList.GetEntry(entry.userId));
 209
 210        //NOTE(Brian): Deny cancellation
 1211        var entry2 = CreateFriendRequestEntry("id1", "Warren Buffet", isReceived: false);
 212
 1213        entry2.cancelButton.onClick.Invoke();
 214
 1215        Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 216
 1217        view.friendRequestsList.confirmationDialog.cancelButton.onClick.Invoke();
 218
 1219        Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf);
 1220        Assert.IsNotNull(view.friendRequestsList.GetEntry(entry2.userId));
 1221    }
 222
 223    void RequestCreateFriendEntry(string id, string name, PresenceStatus status = PresenceStatus.ONLINE)
 224    {
 8225        var model1 = new FriendEntry.Model()
 226        {
 227            status = status,
 228            userName = name,
 229        };
 230
 8231        controller.view.friendsList.CreateOrUpdateEntryDeferred(id, model1);
 8232    }
 233
 4234    FriendEntry GetFriendEntry(string id) { return controller.view.friendsList.GetEntry(id) as FriendEntry; }
 235
 236    FriendRequestEntry CreateFriendRequestEntry(string id, string name, bool isReceived)
 237    {
 6238        var model1 = new FriendEntry.Model()
 239        {
 240            userName = name,
 241        };
 242
 6243        controller.view.friendRequestsList.CreateOrUpdateEntry(id, model1, isReceived);
 244
 6245        return controller.view.friendRequestsList.GetEntry(id) as FriendRequestEntry;
 246    }
 247}