| | 1 | | using DCL.Interface; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.TestTools; |
| | 8 | |
|
| | 9 | | public class FriendsHUDControllerShould : IntegrationTestSuite_Legacy |
| | 10 | | { |
| | 11 | | FriendsHUDController controller; |
| | 12 | | FriendsHUDView view; |
| | 13 | | FriendsController_Mock friendsController; |
| | 14 | |
|
| 9 | 15 | | protected override bool justSceneSetUp => true; |
| | 16 | |
|
| | 17 | | [UnitySetUp] |
| | 18 | | protected override IEnumerator SetUp() |
| | 19 | | { |
| 9 | 20 | | yield return base.SetUp(); |
| | 21 | |
|
| 9 | 22 | | NotificationsController.i.Initialize(new NotificationHUDController()); |
| | 23 | |
|
| 9 | 24 | | controller = new FriendsHUDController(); |
| 9 | 25 | | friendsController = new FriendsController_Mock(); |
| 9 | 26 | | controller.Initialize(friendsController, UserProfile.GetOwnUserProfile()); |
| 9 | 27 | | this.view = controller.view; |
| | 28 | |
|
| 9 | 29 | | Assert.IsTrue(view != null, "Friends hud view is null?"); |
| 9 | 30 | | Assert.IsTrue(controller != null, "Friends hud controller is null?"); |
| 9 | 31 | | } |
| | 32 | |
|
| | 33 | | protected override IEnumerator TearDown() |
| | 34 | | { |
| 9 | 35 | | NotificationsController.i.Dispose(); |
| 9 | 36 | | controller.Dispose(); |
| | 37 | |
|
| 9 | 38 | | yield return base.TearDown(); |
| 9 | 39 | | } |
| | 40 | |
|
| | 41 | | [UnityTest] |
| | 42 | | public IEnumerator ReactCorrectlyToWhisperClick() |
| | 43 | | { |
| 1 | 44 | | var id = "test-id-1"; |
| 1 | 45 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id); |
| 1 | 46 | | var entry = TestHelpers_Friends.GetEntry(view, id); |
| 1 | 47 | | Assert.IsNotNull(entry); |
| | 48 | |
|
| 1 | 49 | | bool pressedWhisper = false; |
| 3 | 50 | | controller.OnPressWhisper += (x) => { pressedWhisper = x == id; }; |
| 1 | 51 | | entry.whisperButton.onClick.Invoke(); |
| 1 | 52 | | Assert.IsTrue(pressedWhisper); |
| 1 | 53 | | } |
| | 54 | |
|
| | 55 | | [UnityTest] |
| | 56 | | public IEnumerator ReactCorrectlyToReportClick() |
| | 57 | | { |
| 1 | 58 | | var id = "test-id-1"; |
| 1 | 59 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id); |
| 1 | 60 | | var entry = TestHelpers_Friends.GetEntry(view, id); |
| 1 | 61 | | Assert.IsNotNull(entry); |
| | 62 | |
|
| 1 | 63 | | bool reportPlayerSent = false; |
| | 64 | |
|
| 1 | 65 | | Action<string, string> callback = |
| | 66 | | (name, payload) => |
| | 67 | | { |
| 1 | 68 | | if (name == "ReportPlayer") |
| | 69 | | { |
| 1 | 70 | | reportPlayerSent = true; |
| | 71 | | } |
| 1 | 72 | | }; |
| | 73 | |
|
| 1 | 74 | | WebInterface.OnMessageFromEngine += callback; |
| | 75 | |
|
| 1 | 76 | | entry.menuButton.onClick.Invoke(); |
| | 77 | |
|
| 1 | 78 | | Assert.IsTrue(controller.view.friendsList.contextMenuPanel.gameObject.activeSelf); |
| | 79 | |
|
| 1 | 80 | | controller.view.friendsList.contextMenuPanel.reportButton.onClick.Invoke(); |
| | 81 | |
|
| 1 | 82 | | Assert.IsTrue(reportPlayerSent); |
| | 83 | |
|
| 1 | 84 | | WebInterface.OnMessageFromEngine -= callback; |
| 1 | 85 | | } |
| | 86 | |
|
| | 87 | | [UnityTest] |
| | 88 | | public IEnumerator ReactCorrectlyToPassportClick() |
| | 89 | | { |
| 1 | 90 | | var id = "test-id-1"; |
| 1 | 91 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id); |
| 1 | 92 | | var entry = TestHelpers_Friends.GetEntry(view, id); |
| 1 | 93 | | Assert.IsNotNull(entry); |
| | 94 | |
|
| 1 | 95 | | var currentPlayerId = Resources.Load<StringVariable>(UserContextMenu.CURRENT_PLAYER_ID); |
| | 96 | |
|
| 1 | 97 | | entry.menuButton.onClick.Invoke(); |
| 1 | 98 | | Assert.AreNotEqual(id, currentPlayerId.Get()); |
| | 99 | |
|
| 1 | 100 | | view.friendsList.contextMenuPanel.passportButton.onClick.Invoke(); |
| | 101 | |
|
| 1 | 102 | | Assert.AreEqual(id, currentPlayerId.Get()); |
| 1 | 103 | | } |
| | 104 | |
|
| | 105 | | [Test] |
| 2 | 106 | | public void HandleUsernameErrorCorrectly() { friendsController.RaiseOnFriendNotFound("test"); } |
| | 107 | |
|
| | 108 | | [Test] |
| | 109 | | public void SendFriendRequestCorrectly() |
| | 110 | | { |
| 1 | 111 | | bool messageSent = false; |
| | 112 | |
|
| 1 | 113 | | string id = "user test"; |
| 1 | 114 | | Action<string, string> callback = (name, payload) => |
| | 115 | | { |
| 1 | 116 | | var msg = JsonUtility.FromJson<FriendsController.FriendshipUpdateStatusMessage>(payload); |
| 1 | 117 | | if (msg.action == FriendshipAction.REQUESTED_TO && |
| | 118 | | msg.userId == id) |
| | 119 | | { |
| 1 | 120 | | messageSent = true; |
| | 121 | | } |
| 1 | 122 | | }; |
| | 123 | |
|
| 1 | 124 | | WebInterface.OnMessageFromEngine += callback; |
| | 125 | |
|
| 1 | 126 | | view.friendRequestsList.friendSearchInputField.onSubmit.Invoke(id); |
| | 127 | |
|
| 1 | 128 | | Assert.IsTrue(messageSent); |
| | 129 | |
|
| 1 | 130 | | WebInterface.OnMessageFromEngine -= callback; |
| 1 | 131 | | } |
| | 132 | |
|
| | 133 | | [UnityTest] |
| | 134 | | public IEnumerator ReactCorrectlyToFriendApproved() |
| | 135 | | { |
| 1 | 136 | | var id = "test-id-1"; |
| 1 | 137 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id, FriendshipAction.APPROVED); |
| 1 | 138 | | var entry = TestHelpers_Friends.GetEntry(view, id); |
| 1 | 139 | | Assert.IsNotNull(entry); |
| | 140 | |
|
| 1 | 141 | | friendsController.RaiseUpdateFriendship(id, FriendshipAction.DELETED); |
| 1 | 142 | | entry = controller.view.friendsList.GetEntry(id) as FriendEntry; |
| 1 | 143 | | Assert.IsNull(entry); |
| 1 | 144 | | } |
| | 145 | |
|
| | 146 | | [UnityTest] |
| | 147 | | public IEnumerator ReactCorrectlyToFriendRejected() |
| | 148 | | { |
| 1 | 149 | | var id = "test-id-1"; |
| 1 | 150 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id); |
| 1 | 151 | | var fentry = TestHelpers_Friends.GetEntry(view, id); |
| 1 | 152 | | Assert.IsNotNull(fentry); |
| | 153 | |
|
| 1 | 154 | | friendsController.RaiseUpdateFriendship(id, FriendshipAction.REQUESTED_FROM); |
| 1 | 155 | | friendsController.RaiseUpdateFriendship(id, FriendshipAction.REJECTED); |
| | 156 | |
|
| 1 | 157 | | var entry = controller.view.friendRequestsList.GetEntry(id); |
| 1 | 158 | | Assert.IsNull(entry); |
| 1 | 159 | | } |
| | 160 | |
|
| | 161 | | [UnityTest] |
| | 162 | | public IEnumerator ReactCorrectlyToFriendCancelled() |
| | 163 | | { |
| 1 | 164 | | var id = "test-id-1"; |
| 1 | 165 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, id); |
| | 166 | |
|
| 1 | 167 | | friendsController.RaiseUpdateFriendship(id, FriendshipAction.REQUESTED_TO); |
| 1 | 168 | | var entry = controller.view.friendRequestsList.GetEntry(id); |
| 1 | 169 | | Assert.IsNotNull(entry); |
| 1 | 170 | | friendsController.RaiseUpdateFriendship(id, FriendshipAction.CANCELLED); |
| 1 | 171 | | entry = controller.view.friendRequestsList.GetEntry(id); |
| 1 | 172 | | Assert.IsNull(entry); |
| 1 | 173 | | } |
| | 174 | |
|
| | 175 | | NotificationBadge GetBadge(string path) |
| | 176 | | { |
| 2 | 177 | | GameObject prefab = Resources.Load(path) as GameObject; |
| 2 | 178 | | Assert.IsTrue(prefab != null); |
| 2 | 179 | | GameObject go = this.InstantiateTestGameObject(prefab); |
| 2 | 180 | | Assert.IsTrue(go != null); |
| | 181 | |
|
| 2 | 182 | | var noti = go.GetComponent<NotificationBadge>(); |
| 2 | 183 | | noti.Initialize(); |
| | 184 | |
|
| 2 | 185 | | return noti; |
| | 186 | | } |
| | 187 | |
|
| | 188 | | [UnityTest] |
| | 189 | | public IEnumerator TaskbarNotificationBadgeHasCorrectValue() |
| | 190 | | { |
| 1 | 191 | | PlayerPrefsUtils.SetInt(FriendsHUDController.PLAYER_PREFS_SEEN_FRIEND_COUNT, 0); |
| | 192 | |
|
| 1 | 193 | | var friendsRequestBadge = GetBadge("NotificationBadge_FriendsRequestTab"); |
| 1 | 194 | | var friendsTaskbarBadge = GetBadge("NotificationBadge_FriendsButton"); |
| | 195 | |
|
| 1 | 196 | | controller.SetVisibility(false); |
| | 197 | |
|
| 1 | 198 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-1"); |
| 1 | 199 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-2"); |
| 1 | 200 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-3"); |
| 1 | 201 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-4"); |
| 1 | 202 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-5", FriendshipAction.REQUESTED_F |
| | 203 | |
|
| 1 | 204 | | Assert.AreEqual(1, friendsRequestBadge.finalValue); |
| 1 | 205 | | Assert.AreEqual(5, friendsTaskbarBadge.finalValue); |
| | 206 | |
|
| 1 | 207 | | controller.SetVisibility(true); |
| | 208 | |
|
| 1 | 209 | | Assert.AreEqual(1, friendsRequestBadge.finalValue); |
| 1 | 210 | | Assert.AreEqual(1, friendsTaskbarBadge.finalValue); |
| | 211 | |
|
| 1 | 212 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-5", FriendshipAction.APPROVED); |
| 1 | 213 | | yield return TestHelpers_Friends.FakeAddFriend(friendsController, view, "friend-6", FriendshipAction.REQUESTED_F |
| | 214 | |
|
| 1 | 215 | | Assert.AreEqual(1, friendsRequestBadge.finalValue); |
| 1 | 216 | | Assert.AreEqual(1, friendsTaskbarBadge.finalValue); |
| 1 | 217 | | } |
| | 218 | | } |