< Summary

Class:UserContextMenuShould
Assembly:UserContextMenuTest
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/UserContextMenu/Tests/UserContextMenuShould.cs
Covered lines:79
Uncovered lines:0
Coverable lines:79
Total lines:188
Line coverage:100% (79 of 79)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%220100%
TearDown()0%220100%
ShowContextMenuProperly()0%110100%
HideContextMenuProperly()0%110100%
ClickOnPassportButton()0%110100%
ClickOnReportButton()0%110100%
ClickOnBlockButton()0%110100%
FriendSetupsCorrectly()0%110100%
MessageButtonSetupsCorrectly()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/UserContextMenu/Tests/UserContextMenuShould.cs

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections;
 3using UnityEngine;
 4using UnityEditor;
 5using System;
 6using UnityEngine.TestTools;
 7
 8public class UserContextMenuShould
 9{
 10    const string PREFAB_PATH = "Assets/Scripts/MainScripts/DCL/Controllers/UserContextMenu/Prefabs/UserContextMenuPanel.
 11    const string TEST_USER_ID = "TEST_USER_ID";
 12
 13    private UserContextMenu contextMenu;
 14    private FriendsController friendsController;
 15    private UserProfileController profileController;
 16
 17    [UnitySetUp]
 18    public IEnumerator SetUp()
 19    {
 720        var prefab = AssetDatabase.LoadAssetAtPath(PREFAB_PATH, (typeof(GameObject))) as GameObject;
 721        contextMenu = UnityEngine.Object.Instantiate(prefab).GetComponent<UserContextMenu>();
 22
 723        friendsController = (new GameObject()).AddComponent<FriendsController>();
 724        profileController = (new GameObject()).AddComponent<UserProfileController>();
 725        profileController.AddUserProfileToCatalog(new UserProfileModel()
 26        {
 27            name = TEST_USER_ID,
 28            userId = TEST_USER_ID
 29        });
 30
 731        yield break;
 32    }
 33
 34    [UnityTearDown]
 35    public IEnumerator TearDown()
 36    {
 737        UnityEngine.Object.Destroy(contextMenu.gameObject);
 738        UnityEngine.Object.Destroy(friendsController.gameObject);
 739        UnityEngine.Object.Destroy(profileController.gameObject);
 40
 741        yield break;
 42    }
 43
 44    [Test]
 45    public void ShowContextMenuProperly()
 46    {
 147        bool showEventCalled = false;
 248        Action onShow = () => showEventCalled = true;
 149        contextMenu.OnShowMenu += onShow;
 50
 151        contextMenu.Show(TEST_USER_ID);
 52
 153        contextMenu.OnShowMenu -= onShow;
 154        Assert.IsTrue(contextMenu.gameObject.activeSelf, "The context menu should be visible.");
 155        Assert.IsTrue(showEventCalled);
 156    }
 57
 58    [Test]
 59    public void HideContextMenuProperly()
 60    {
 161        contextMenu.Hide();
 62
 163        Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible.");
 164    }
 65
 66    [Test]
 67    public void ClickOnPassportButton()
 68    {
 169        bool passportEventInvoked = false;
 270        Action<string> onPassport = (id) => passportEventInvoked = true;
 171        contextMenu.OnPassport += onPassport;
 72
 173        contextMenu.Show(TEST_USER_ID);
 174        contextMenu.passportButton.onClick.Invoke();
 75
 176        contextMenu.OnPassport -= onPassport;
 177        Assert.IsTrue(passportEventInvoked);
 178        Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible.");
 179    }
 80
 81    [Test]
 82    public void ClickOnReportButton()
 83    {
 184        bool reportEventInvoked = false;
 285        Action<string> onReport = (id) => reportEventInvoked = true;
 186        contextMenu.OnReport += onReport;
 87
 188        contextMenu.Show(TEST_USER_ID);
 189        contextMenu.reportButton.onClick.Invoke();
 90
 191        contextMenu.OnReport -= onReport;
 192        Assert.IsTrue(reportEventInvoked);
 193        Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible.");
 194    }
 95
 96    [Test]
 97    public void ClickOnBlockButton()
 98    {
 199        bool blockEventInvoked = false;
 2100        Action<string, bool> onBlock = (id, block) => blockEventInvoked = true;
 1101        contextMenu.OnBlock += onBlock;
 102
 1103        contextMenu.Show(TEST_USER_ID);
 1104        contextMenu.blockButton.onClick.Invoke();
 105
 1106        contextMenu.OnBlock -= onBlock;
 1107        Assert.IsTrue(blockEventInvoked);
 1108        Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible.");
 1109    }
 110
 111    [Test]
 112    public void FriendSetupsCorrectly()
 113    {
 1114        contextMenu.Show(TEST_USER_ID, UserContextMenu.MenuConfigFlags.Friendship);
 115
 1116        Assert.IsTrue(contextMenu.friendshipContainer.activeSelf, "friendshipContainer should be active");
 117
 1118        Assert.IsTrue(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should be active");
 1119        Assert.IsFalse(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should not be active");
 1120        Assert.IsFalse(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should not be active")
 1121        Assert.IsFalse(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should not be active");
 122
 1123        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 124        {
 125            userId = TEST_USER_ID,
 126            action = FriendshipAction.REQUESTED_TO
 127        });
 128
 1129        Assert.IsFalse(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should not be active");
 1130        Assert.IsFalse(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should not be active");
 1131        Assert.IsTrue(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should be active");
 1132        Assert.IsFalse(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should not be active");
 133
 1134        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 135        {
 136            userId = TEST_USER_ID,
 137            action = FriendshipAction.APPROVED
 138        });
 139
 1140        Assert.IsFalse(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should not be active");
 1141        Assert.IsTrue(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should be active");
 1142        Assert.IsFalse(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should not be active")
 1143        Assert.IsTrue(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should be active");
 144
 1145        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 146        {
 147            userId = TEST_USER_ID,
 148            action = FriendshipAction.DELETED
 149        });
 150
 1151        Assert.IsTrue(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should be active");
 1152        Assert.IsFalse(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should not be active");
 1153        Assert.IsFalse(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should not be active")
 1154        Assert.IsFalse(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should not be active");
 1155    }
 156
 157    [Test]
 158    public void MessageButtonSetupsCorrectly()
 159    {
 1160        contextMenu.Show(TEST_USER_ID, UserContextMenu.MenuConfigFlags.Message);
 161
 1162        Assert.IsFalse(contextMenu.messageButton.gameObject.activeSelf, "messageButton should not be active");
 163
 1164        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 165        {
 166            userId = TEST_USER_ID,
 167            action = FriendshipAction.REQUESTED_TO
 168        });
 169
 1170        Assert.IsFalse(contextMenu.messageButton.gameObject.activeSelf, "messageButton should not be active");
 171
 1172        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 173        {
 174            userId = TEST_USER_ID,
 175            action = FriendshipAction.APPROVED
 176        });
 177
 1178        Assert.IsTrue(contextMenu.messageButton.gameObject.activeSelf, "messageButton should be active");
 179
 1180        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 181        {
 182            userId = TEST_USER_ID,
 183            action = FriendshipAction.DELETED
 184        });
 185
 1186        Assert.IsFalse(contextMenu.messageButton.gameObject.activeSelf, "messageButton should not be active");
 1187    }
 188}