| | 1 | | using DCL.Interface; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.TestTools; |
| | 6 | |
|
| | 7 | | public 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 | | { |
| 4 | 20 | | Vector2 testCoords = new Vector2(5, 20); |
| | 21 | |
|
| 4 | 22 | | friendsController = new FriendsController_Mock(); |
| 4 | 23 | | 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 | |
|
| 4 | 36 | | GameObject go = Object.Instantiate((GameObject)Resources.Load(JUMP_IN_BUTTON_RESOURCE_NAME)); |
| 4 | 37 | | jumpInButton = go.GetComponent<JumpInButton>(); |
| 4 | 38 | | jumpInButton.Initialize(friendsController, TEST_USER_ID); |
| | 39 | |
|
| 4 | 40 | | Assert.AreEqual(testCoords, jumpInButton.currentCoords, "Position coords should match with [testCoords]"); |
| 4 | 41 | | Assert.AreEqual(PresenceStatus.ONLINE, jumpInButton.currentPresenceStatus, "Presence status should be ONLINE"); |
| 4 | 42 | | Assert.AreEqual(TEST_SERVER_NAME, jumpInButton.currentRealmServerName, "Server name should match with [TEST_SERV |
| 4 | 43 | | Assert.AreEqual(TEST_LAYER_NAME, jumpInButton.currentRealmLayerName, "Server layer should match with [TEST_LAYER |
| 4 | 44 | | Assert.AreEqual(true, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be actived"); |
| | 45 | |
|
| 4 | 46 | | yield break; |
| | 47 | | } |
| | 48 | |
|
| | 49 | | protected override IEnumerator TearDown() |
| | 50 | | { |
| 4 | 51 | | Object.Destroy(jumpInButton.gameObject); |
| 4 | 52 | | yield break; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | [Test] |
| | 56 | | public void FriendChangesHisPosition() |
| | 57 | | { |
| 1 | 58 | | Vector2 newTestCoords = new Vector2(10, 20); |
| | 59 | |
|
| 1 | 60 | | 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 | |
|
| 1 | 73 | | Assert.AreEqual(newTestCoords, jumpInButton.currentCoords, "Position coords should match with [newTestCoords]"); |
| 1 | 74 | | Assert.AreEqual(PresenceStatus.ONLINE, jumpInButton.currentPresenceStatus, "Presence status should be ONLINE"); |
| 1 | 75 | | Assert.AreEqual(TEST_SERVER_NAME, jumpInButton.currentRealmServerName, "Server name should match with [TEST_SERV |
| 1 | 76 | | Assert.AreEqual(TEST_LAYER_NAME, jumpInButton.currentRealmLayerName, "Server layer should match with [TEST_LAYER |
| 1 | 77 | | Assert.AreEqual(true, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be actived"); |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | [Test] |
| | 81 | | public void FriendChangesHisRealm() |
| | 82 | | { |
| 1 | 83 | | Vector2 newTestCoords = new Vector2(10, 20); |
| 1 | 84 | | string newRealmServerName = "test server name 2"; |
| 1 | 85 | | string newRealmLayerName = "test layer name 2"; |
| | 86 | |
|
| 1 | 87 | | 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 | |
|
| 1 | 100 | | Assert.AreEqual(newTestCoords, jumpInButton.currentCoords, "Position coords should match with [newTestCoords]"); |
| 1 | 101 | | Assert.AreEqual(PresenceStatus.ONLINE, jumpInButton.currentPresenceStatus, "Presence status should be ONLINE"); |
| 1 | 102 | | Assert.AreEqual(newRealmServerName, jumpInButton.currentRealmServerName, "Server name should match with [newReal |
| 1 | 103 | | Assert.AreEqual(newRealmLayerName, jumpInButton.currentRealmLayerName, "Server layer should match with [newRealm |
| 1 | 104 | | Assert.AreEqual(true, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be actived"); |
| 1 | 105 | | } |
| | 106 | |
|
| | 107 | | [Test] |
| | 108 | | public void FriendChangesHisPresence() |
| | 109 | | { |
| 1 | 110 | | Vector2 newTestCoords = new Vector2(10, 20); |
| | 111 | |
|
| 1 | 112 | | 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 | |
|
| 1 | 125 | | Assert.AreEqual(newTestCoords, jumpInButton.currentCoords, "Position coords should match with [testCoords]"); |
| 1 | 126 | | Assert.AreEqual(PresenceStatus.OFFLINE, jumpInButton.currentPresenceStatus, "Presence status should be OFFLINE") |
| 1 | 127 | | Assert.AreEqual(TEST_SERVER_NAME, jumpInButton.currentRealmServerName, "Server name should match with [TEST_SERV |
| 1 | 128 | | Assert.AreEqual(TEST_LAYER_NAME, jumpInButton.currentRealmLayerName, "Server layer should match with [TEST_LAYER |
| 1 | 129 | | Assert.AreEqual(false, jumpInButton.gameObject.activeSelf, "JumpInButton game object should be deactived"); |
| 1 | 130 | | } |
| | 131 | |
|
| | 132 | | [Test] |
| | 133 | | public void ReactCorrectlyToJumpInClick() |
| | 134 | | { |
| 1 | 135 | | bool jumpInCalled = false; |
| | 136 | |
|
| 1 | 137 | | System.Action<string, string> callback = (type, message) => |
| | 138 | | { |
| 1 | 139 | | if (type == "JumpIn") |
| | 140 | | { |
| 1 | 141 | | jumpInCalled = true; |
| | 142 | | } |
| 1 | 143 | | }; |
| | 144 | |
|
| 1 | 145 | | WebInterface.OnMessageFromEngine += callback; |
| | 146 | |
|
| 1 | 147 | | jumpInButton.button.onClick.Invoke(); |
| | 148 | |
|
| 1 | 149 | | WebInterface.OnMessageFromEngine -= callback; |
| | 150 | |
|
| 1 | 151 | | Assert.IsTrue(jumpInCalled); |
| 1 | 152 | | } |
| | 153 | | } |