| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.TestTools; |
| | 5 | |
|
| | 6 | | public class FriendsHUDViewShould : IntegrationTestSuite_Legacy |
| | 7 | | { |
| | 8 | | FriendsHUDController controller; |
| | 9 | | FriendsHUDView view; |
| | 10 | |
|
| 9 | 11 | | protected override bool justSceneSetUp => true; |
| | 12 | |
|
| | 13 | | [UnitySetUp] |
| | 14 | | protected override IEnumerator SetUp() |
| | 15 | | { |
| 9 | 16 | | yield return base.SetUp(); |
| | 17 | |
|
| 9 | 18 | | controller = new FriendsHUDController(); |
| 9 | 19 | | controller.Initialize(null, null); |
| 9 | 20 | | this.view = controller.view; |
| | 21 | |
|
| 9 | 22 | | Assert.IsTrue(view != null, "Friends hud view is null?"); |
| 9 | 23 | | Assert.IsTrue(controller != null, "Friends hud controller is null?"); |
| 9 | 24 | | } |
| | 25 | |
|
| | 26 | | protected override IEnumerator TearDown() |
| | 27 | | { |
| 9 | 28 | | controller.Dispose(); |
| 9 | 29 | | yield return base.TearDown(); |
| 9 | 30 | | } |
| | 31 | |
|
| | 32 | | [Test] |
| | 33 | | public void ChangeContentWhenClickingTabs() |
| | 34 | | { |
| 1 | 35 | | controller.view.friendsButton.onClick.Invoke(); |
| | 36 | |
|
| 1 | 37 | | Assert.IsTrue(controller.view.friendsList.gameObject.activeSelf); |
| 1 | 38 | | Assert.IsFalse(controller.view.friendRequestsList.gameObject.activeSelf); |
| | 39 | |
|
| 1 | 40 | | controller.view.friendRequestsButton.onClick.Invoke(); |
| | 41 | |
|
| 1 | 42 | | Assert.IsFalse(controller.view.friendsList.gameObject.activeSelf); |
| 1 | 43 | | Assert.IsTrue(controller.view.friendRequestsList.gameObject.activeSelf); |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | [UnityTest] |
| | 47 | | public IEnumerator PopulateFriendListCorrectly() |
| | 48 | | { |
| 1 | 49 | | string id1 = "userId-1"; |
| 1 | 50 | | string id2 = "userId-2"; |
| | 51 | |
|
| 1 | 52 | | RequestCreateFriendEntry(id1, "Pravus", PresenceStatus.ONLINE); |
| 1 | 53 | | RequestCreateFriendEntry(id2, "Brian", PresenceStatus.OFFLINE); |
| 3 | 54 | | yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0); |
| 1 | 55 | | var entry1 = GetFriendEntry( id1); |
| 1 | 56 | | var entry2 = GetFriendEntry( id2); |
| | 57 | |
|
| 1 | 58 | | Assert.IsNotNull(entry1); |
| 1 | 59 | | Assert.AreEqual(entry1.model.userName, entry1.playerNameText.text); |
| 1 | 60 | | Assert.AreEqual(controller.view.friendsList.onlineFriendsList.container, entry1.transform.parent); |
| | 61 | |
|
| 1 | 62 | | Assert.IsNotNull(entry2); |
| 1 | 63 | | Assert.AreEqual(entry2.model.userName, entry2.playerNameText.text); |
| 1 | 64 | | Assert.AreEqual(controller.view.friendsList.offlineFriendsList.container, entry2.transform.parent); |
| | 65 | |
|
| 1 | 66 | | var model2 = entry2.model; |
| 1 | 67 | | model2.status = PresenceStatus.ONLINE; |
| 1 | 68 | | controller.view.friendsList.CreateOrUpdateEntryDeferred(id2, model2); |
| | 69 | |
|
| 1 | 70 | | Assert.AreEqual(controller.view.friendsList.onlineFriendsList.container, entry2.transform.parent); |
| 1 | 71 | | } |
| | 72 | |
|
| | 73 | | [Test] |
| | 74 | | public void RemoveFriendCorrectly() |
| | 75 | | { |
| 1 | 76 | | string id1 = "userId-1"; |
| | 77 | |
|
| 1 | 78 | | controller.view.friendRequestsList.CreateOrUpdateEntry(id1, new FriendEntry.Model(), isReceived: true); |
| | 79 | |
|
| 1 | 80 | | Assert.IsNotNull(controller.view.friendRequestsList.GetEntry(id1)); |
| | 81 | |
|
| 1 | 82 | | controller.view.friendRequestsList.RemoveEntry(id1); |
| | 83 | |
|
| 1 | 84 | | Assert.IsNull(controller.view.friendRequestsList.GetEntry(id1)); |
| 1 | 85 | | } |
| | 86 | |
|
| | 87 | | [Test] |
| | 88 | | public void PopulateFriendRequestCorrectly() |
| | 89 | | { |
| 1 | 90 | | string id1 = "userId-1"; |
| 1 | 91 | | string id2 = "userId-2"; |
| | 92 | |
|
| 1 | 93 | | var entry1 = CreateFriendRequestEntry(id1, "Pravus", true); |
| 1 | 94 | | var entry2 = CreateFriendRequestEntry(id2, "Brian", false); |
| | 95 | |
|
| 1 | 96 | | Assert.IsNotNull(entry1); |
| 1 | 97 | | Assert.AreEqual("Pravus", entry1.playerNameText.text); |
| 1 | 98 | | Assert.AreEqual(controller.view.friendRequestsList.receivedRequestsList.container, entry1.transform.parent); |
| | 99 | |
|
| 1 | 100 | | Assert.IsNotNull(entry2); |
| 1 | 101 | | Assert.AreEqual("Brian", entry2.playerNameText.text); |
| 1 | 102 | | Assert.AreEqual(controller.view.friendRequestsList.sentRequestsList.container, entry2.transform.parent); |
| | 103 | |
|
| 1 | 104 | | controller.view.friendRequestsList.UpdateEntry(id2, entry2.model, true); |
| 1 | 105 | | Assert.AreEqual(controller.view.friendRequestsList.receivedRequestsList.container, entry2.transform.parent); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [UnityTest] |
| | 109 | | public IEnumerator CountProperlyStatus() |
| | 110 | | { |
| 1 | 111 | | RequestCreateFriendEntry("user1", "Armando Barreda", PresenceStatus.ONLINE); |
| 1 | 112 | | RequestCreateFriendEntry("user2", "Guillermo Andino", PresenceStatus.ONLINE); |
| | 113 | |
|
| 1 | 114 | | RequestCreateFriendEntry("user3", "Wanda Nara", PresenceStatus.OFFLINE); |
| 1 | 115 | | RequestCreateFriendEntry("user4", "Mirtha Legrand", PresenceStatus.OFFLINE); |
| | 116 | |
|
| 3 | 117 | | yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0); |
| | 118 | |
|
| 1 | 119 | | Assert.AreEqual(2, view.friendsList.onlineFriendsList.Count()); |
| 1 | 120 | | Assert.AreEqual(2, view.friendsList.offlineFriendsList.Count()); |
| | 121 | |
|
| 1 | 122 | | view.friendsList.RemoveEntry("user1"); |
| 1 | 123 | | view.friendsList.RemoveEntry("user3"); |
| | 124 | |
|
| 1 | 125 | | Assert.AreEqual(1, view.friendsList.onlineFriendsList.Count()); |
| 1 | 126 | | Assert.AreEqual(1, view.friendsList.offlineFriendsList.Count()); |
| 1 | 127 | | } |
| | 128 | |
|
| | 129 | | [UnityTest] |
| | 130 | | public IEnumerator OpenContextMenuProperly() |
| | 131 | | { |
| 1 | 132 | | string id1 = "userId-1"; |
| 1 | 133 | | RequestCreateFriendEntry(id1, "Pravus"); |
| 3 | 134 | | yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0); |
| 1 | 135 | | var entry = GetFriendEntry(id1); |
| | 136 | |
|
| 1 | 137 | | bool onMenuToggleCalled = false; |
| | 138 | |
|
| 3 | 139 | | System.Action<FriendEntryBase> callback = (x) => { onMenuToggleCalled = true; }; |
| | 140 | |
|
| 1 | 141 | | Assert.IsFalse(view.friendsList.contextMenuPanel.gameObject.activeSelf); |
| | 142 | |
|
| 1 | 143 | | entry.OnMenuToggle += callback; |
| 1 | 144 | | entry.menuButton.onClick.Invoke(); |
| 1 | 145 | | entry.OnMenuToggle -= callback; |
| | 146 | |
|
| 1 | 147 | | Assert.IsTrue(onMenuToggleCalled); |
| 1 | 148 | | Assert.IsTrue(view.friendsList.contextMenuPanel.gameObject.activeSelf); |
| 1 | 149 | | } |
| | 150 | |
|
| | 151 | | [UnityTest] |
| | 152 | | public IEnumerator DeleteFriendProperly() |
| | 153 | | { |
| 1 | 154 | | string id1 = "userId-1"; |
| 1 | 155 | | RequestCreateFriendEntry(id1, "Ted Bundy"); |
| 3 | 156 | | yield return new WaitUntil(() => controller.view.friendsList.creationQueue.Count == 0); |
| 1 | 157 | | var entry = GetFriendEntry(id1); |
| | 158 | |
|
| 1 | 159 | | entry.menuButton.onClick.Invoke(); |
| | 160 | |
|
| 1 | 161 | | view.friendsList.contextMenuPanel.deleteFriendButton.onClick.Invoke(); |
| 1 | 162 | | view.friendsList.confirmationDialog.confirmButton.onClick.Invoke(); |
| | 163 | |
|
| 1 | 164 | | Assert.IsNull(view.friendsList.GetEntry(id1)); |
| 1 | 165 | | } |
| | 166 | |
|
| | 167 | | [Test] |
| | 168 | | public void RejectIncomingFriendRequestsProperly() |
| | 169 | | { |
| | 170 | | //NOTE(Brian): Confirm cancellation |
| 1 | 171 | | var entry = CreateFriendRequestEntry("id1", "Padre Grassi", isReceived: true); |
| | 172 | |
|
| 1 | 173 | | entry.rejectButton.onClick.Invoke(); |
| | 174 | |
|
| 1 | 175 | | Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| | 176 | |
|
| 1 | 177 | | view.friendRequestsList.confirmationDialog.confirmButton.onClick.Invoke(); |
| | 178 | |
|
| 1 | 179 | | Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| 1 | 180 | | Assert.IsNull(view.friendRequestsList.GetEntry(entry.userId)); |
| | 181 | |
|
| | 182 | | //NOTE(Brian): Deny cancellation |
| 1 | 183 | | var entry2 = CreateFriendRequestEntry("id1", "Warren Buffet", isReceived: true); |
| | 184 | |
|
| 1 | 185 | | entry2.rejectButton.onClick.Invoke(); |
| | 186 | |
|
| 1 | 187 | | Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| | 188 | |
|
| 1 | 189 | | view.friendRequestsList.confirmationDialog.cancelButton.onClick.Invoke(); |
| | 190 | |
|
| 1 | 191 | | Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| 1 | 192 | | Assert.IsNotNull(view.friendRequestsList.GetEntry(entry2.userId)); |
| 1 | 193 | | } |
| | 194 | |
|
| | 195 | | [Test] |
| | 196 | | public void SendAndCancelFriendRequestsProperly() |
| | 197 | | { |
| | 198 | | //NOTE(Brian): Confirm cancellation |
| 1 | 199 | | var entry = CreateFriendRequestEntry("id1", "Padre Grassi", isReceived: false); |
| | 200 | |
|
| 1 | 201 | | entry.cancelButton.onClick.Invoke(); |
| | 202 | |
|
| 1 | 203 | | Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| | 204 | |
|
| 1 | 205 | | view.friendRequestsList.confirmationDialog.confirmButton.onClick.Invoke(); |
| | 206 | |
|
| 1 | 207 | | Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| 1 | 208 | | Assert.IsNull(view.friendRequestsList.GetEntry(entry.userId)); |
| | 209 | |
|
| | 210 | | //NOTE(Brian): Deny cancellation |
| 1 | 211 | | var entry2 = CreateFriendRequestEntry("id1", "Warren Buffet", isReceived: false); |
| | 212 | |
|
| 1 | 213 | | entry2.cancelButton.onClick.Invoke(); |
| | 214 | |
|
| 1 | 215 | | Assert.IsTrue(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| | 216 | |
|
| 1 | 217 | | view.friendRequestsList.confirmationDialog.cancelButton.onClick.Invoke(); |
| | 218 | |
|
| 1 | 219 | | Assert.IsFalse(view.friendRequestsList.confirmationDialog.gameObject.activeSelf); |
| 1 | 220 | | Assert.IsNotNull(view.friendRequestsList.GetEntry(entry2.userId)); |
| 1 | 221 | | } |
| | 222 | |
|
| | 223 | | void RequestCreateFriendEntry(string id, string name, PresenceStatus status = PresenceStatus.ONLINE) |
| | 224 | | { |
| 8 | 225 | | var model1 = new FriendEntry.Model() |
| | 226 | | { |
| | 227 | | status = status, |
| | 228 | | userName = name, |
| | 229 | | }; |
| | 230 | |
|
| 8 | 231 | | controller.view.friendsList.CreateOrUpdateEntryDeferred(id, model1); |
| 8 | 232 | | } |
| | 233 | |
|
| 4 | 234 | | FriendEntry GetFriendEntry(string id) { return controller.view.friendsList.GetEntry(id) as FriendEntry; } |
| | 235 | |
|
| | 236 | | FriendRequestEntry CreateFriendRequestEntry(string id, string name, bool isReceived) |
| | 237 | | { |
| 6 | 238 | | var model1 = new FriendEntry.Model() |
| | 239 | | { |
| | 240 | | userName = name, |
| | 241 | | }; |
| | 242 | |
|
| 6 | 243 | | controller.view.friendRequestsList.CreateOrUpdateEntry(id, model1, isReceived); |
| | 244 | |
|
| 6 | 245 | | return controller.view.friendRequestsList.GetEntry(id) as FriendRequestEntry; |
| | 246 | | } |
| | 247 | | } |