< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%220100%
TearDown()0%220100%
FriendChangesHisPosition()0%110100%
FriendChangesHisRealm()0%110100%
FriendChangesHisPresence()0%110100%
ReactCorrectlyToJumpInClick()0%110100%

File(s)

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

#LineLine coverage
 1using DCL.Interface;
 2using NUnit.Framework;
 3using System.Collections;
 4using UnityEngine;
 5using UnityEngine.TestTools;
 6
 7public class JumpInButtonShould : IntegrationTestSuite_Legacy
 8{
 9    private const string JUMP_IN_BUTTON_RESOURCE_NAME = "JumpInButton";
 10    private const string TEST_USER_ID = "testFriend";
 11    private const string TEST_SERVER_NAME = "test server name";
 12    private const string TEST_LAYER_NAME = "test layer name";
 13
 14    private FriendsController_Mock friendsController;
 15    private JumpInButton jumpInButton;
 16
 17    [UnitySetUp]
 18    protected override IEnumerator SetUp()
 19    {
 420        Vector2 testCoords = new Vector2(5, 20);
 21
 422        friendsController = new FriendsController_Mock();
 423        friendsController.AddFriend(new FriendsController.UserStatus
 24        {
 25            userId = TEST_USER_ID,
 26            friendshipStatus = FriendshipStatus.FRIEND,
 27            position = testCoords,
 28            presence = PresenceStatus.ONLINE,
 29            realm = new FriendsController.UserStatus.Realm
 30            {
 31                serverName = TEST_SERVER_NAME,
 32                layer = TEST_LAYER_NAME
 33            }
 34        });
 35
 436        GameObject go = Object.Instantiate((GameObject)Resources.Load(JUMP_IN_BUTTON_RESOURCE_NAME));
 437        jumpInButton = go.GetComponent<JumpInButton>();
 438        jumpInButton.Initialize(friendsController, TEST_USER_ID);
 39
 440        Assert.AreEqual(testCoords, jumpInButton.currentCoords, "Position coords should match with [testCoords]");
 441        Assert.AreEqual(PresenceStatus.ONLINE, jumpInButton.currentPresenceStatus, "Presence status should be ONLINE");
 442        Assert.AreEqual(TEST_SERVER_NAME, jumpInButton.currentRealmServerName, "Server name should match with [TEST_SERV
 443        Assert.AreEqual(TEST_LAYER_NAME, jumpInButton.currentRealmLayerName, "Server layer should match with [TEST_LAYER
 444        Assert.AreEqual(true, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be actived");
 45
 446        yield break;
 47    }
 48
 49    protected override IEnumerator TearDown()
 50    {
 451        Object.Destroy(jumpInButton.gameObject);
 452        yield break;
 53    }
 54
 55    [Test]
 56    public void FriendChangesHisPosition()
 57    {
 158        Vector2 newTestCoords = new Vector2(10, 20);
 59
 160        friendsController.RaiseUpdateUserStatus(TEST_USER_ID, new FriendsController.UserStatus
 61        {
 62            userId = TEST_USER_ID,
 63            friendshipStatus = FriendshipStatus.FRIEND,
 64            position = newTestCoords,
 65            presence = PresenceStatus.ONLINE,
 66            realm = new FriendsController.UserStatus.Realm
 67            {
 68                serverName = TEST_SERVER_NAME,
 69                layer = TEST_LAYER_NAME
 70            }
 71        });
 72
 173        Assert.AreEqual(newTestCoords, jumpInButton.currentCoords, "Position coords should match with [newTestCoords]");
 174        Assert.AreEqual(PresenceStatus.ONLINE, jumpInButton.currentPresenceStatus, "Presence status should be ONLINE");
 175        Assert.AreEqual(TEST_SERVER_NAME, jumpInButton.currentRealmServerName, "Server name should match with [TEST_SERV
 176        Assert.AreEqual(TEST_LAYER_NAME, jumpInButton.currentRealmLayerName, "Server layer should match with [TEST_LAYER
 177        Assert.AreEqual(true, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be actived");
 178    }
 79
 80    [Test]
 81    public void FriendChangesHisRealm()
 82    {
 183        Vector2 newTestCoords = new Vector2(10, 20);
 184        string newRealmServerName = "test server name 2";
 185        string newRealmLayerName = "test layer name 2";
 86
 187        friendsController.RaiseUpdateUserStatus(TEST_USER_ID, new FriendsController.UserStatus
 88        {
 89            userId = TEST_USER_ID,
 90            friendshipStatus = FriendshipStatus.FRIEND,
 91            position = newTestCoords,
 92            presence = PresenceStatus.ONLINE,
 93            realm = new FriendsController.UserStatus.Realm
 94            {
 95                serverName = newRealmServerName,
 96                layer = newRealmLayerName
 97            }
 98        });
 99
 1100        Assert.AreEqual(newTestCoords, jumpInButton.currentCoords, "Position coords should match with [newTestCoords]");
 1101        Assert.AreEqual(PresenceStatus.ONLINE, jumpInButton.currentPresenceStatus, "Presence status should be ONLINE");
 1102        Assert.AreEqual(newRealmServerName, jumpInButton.currentRealmServerName, "Server name should match with [newReal
 1103        Assert.AreEqual(newRealmLayerName, jumpInButton.currentRealmLayerName, "Server layer should match with [newRealm
 1104        Assert.AreEqual(true, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be actived");
 1105    }
 106
 107    [Test]
 108    public void FriendChangesHisPresence()
 109    {
 1110        Vector2 newTestCoords = new Vector2(10, 20);
 111
 1112        friendsController.RaiseUpdateUserStatus(TEST_USER_ID, new FriendsController.UserStatus
 113        {
 114            userId = TEST_USER_ID,
 115            friendshipStatus = FriendshipStatus.FRIEND,
 116            position = newTestCoords,
 117            presence = PresenceStatus.OFFLINE,
 118            realm = new FriendsController.UserStatus.Realm
 119            {
 120                serverName = TEST_SERVER_NAME,
 121                layer = TEST_LAYER_NAME
 122            }
 123        });
 124
 1125        Assert.AreEqual(newTestCoords, jumpInButton.currentCoords, "Position coords should match with [testCoords]");
 1126        Assert.AreEqual(PresenceStatus.OFFLINE, jumpInButton.currentPresenceStatus, "Presence status should be OFFLINE")
 1127        Assert.AreEqual(TEST_SERVER_NAME, jumpInButton.currentRealmServerName, "Server name should match with [TEST_SERV
 1128        Assert.AreEqual(TEST_LAYER_NAME, jumpInButton.currentRealmLayerName, "Server layer should match with [TEST_LAYER
 1129        Assert.AreEqual(false, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be deactived");
 1130    }
 131
 132    [Test]
 133    public void ReactCorrectlyToJumpInClick()
 134    {
 1135        bool jumpInCalled = false;
 136
 1137        System.Action<string, string> callback = (type, message) =>
 138        {
 1139            if (type == "JumpIn")
 140            {
 1141                jumpInCalled = true;
 142            }
 1143        };
 144
 1145        WebInterface.OnMessageFromEngine += callback;
 146
 1147        jumpInButton.button.onClick.Invoke();
 148
 1149        WebInterface.OnMessageFromEngine -= callback;
 150
 1151        Assert.IsTrue(jumpInCalled);
 1152    }
 153}