| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEditor; |
| | 5 | | using System; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | |
|
| | 8 | | public 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 | | { |
| 7 | 20 | | var prefab = AssetDatabase.LoadAssetAtPath(PREFAB_PATH, (typeof(GameObject))) as GameObject; |
| 7 | 21 | | contextMenu = UnityEngine.Object.Instantiate(prefab).GetComponent<UserContextMenu>(); |
| | 22 | |
|
| 7 | 23 | | friendsController = (new GameObject()).AddComponent<FriendsController>(); |
| 7 | 24 | | profileController = (new GameObject()).AddComponent<UserProfileController>(); |
| 7 | 25 | | profileController.AddUserProfileToCatalog(new UserProfileModel() |
| | 26 | | { |
| | 27 | | name = TEST_USER_ID, |
| | 28 | | userId = TEST_USER_ID |
| | 29 | | }); |
| | 30 | |
|
| 7 | 31 | | yield break; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | [UnityTearDown] |
| | 35 | | public IEnumerator TearDown() |
| | 36 | | { |
| 7 | 37 | | UnityEngine.Object.Destroy(contextMenu.gameObject); |
| 7 | 38 | | UnityEngine.Object.Destroy(friendsController.gameObject); |
| 7 | 39 | | UnityEngine.Object.Destroy(profileController.gameObject); |
| | 40 | |
|
| 7 | 41 | | yield break; |
| | 42 | | } |
| | 43 | |
|
| | 44 | | [Test] |
| | 45 | | public void ShowContextMenuProperly() |
| | 46 | | { |
| 1 | 47 | | bool showEventCalled = false; |
| 2 | 48 | | Action onShow = () => showEventCalled = true; |
| 1 | 49 | | contextMenu.OnShowMenu += onShow; |
| | 50 | |
|
| 1 | 51 | | contextMenu.Show(TEST_USER_ID); |
| | 52 | |
|
| 1 | 53 | | contextMenu.OnShowMenu -= onShow; |
| 1 | 54 | | Assert.IsTrue(contextMenu.gameObject.activeSelf, "The context menu should be visible."); |
| 1 | 55 | | Assert.IsTrue(showEventCalled); |
| 1 | 56 | | } |
| | 57 | |
|
| | 58 | | [Test] |
| | 59 | | public void HideContextMenuProperly() |
| | 60 | | { |
| 1 | 61 | | contextMenu.Hide(); |
| | 62 | |
|
| 1 | 63 | | Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible."); |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | [Test] |
| | 67 | | public void ClickOnPassportButton() |
| | 68 | | { |
| 1 | 69 | | bool passportEventInvoked = false; |
| 2 | 70 | | Action<string> onPassport = (id) => passportEventInvoked = true; |
| 1 | 71 | | contextMenu.OnPassport += onPassport; |
| | 72 | |
|
| 1 | 73 | | contextMenu.Show(TEST_USER_ID); |
| 1 | 74 | | contextMenu.passportButton.onClick.Invoke(); |
| | 75 | |
|
| 1 | 76 | | contextMenu.OnPassport -= onPassport; |
| 1 | 77 | | Assert.IsTrue(passportEventInvoked); |
| 1 | 78 | | Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible."); |
| 1 | 79 | | } |
| | 80 | |
|
| | 81 | | [Test] |
| | 82 | | public void ClickOnReportButton() |
| | 83 | | { |
| 1 | 84 | | bool reportEventInvoked = false; |
| 2 | 85 | | Action<string> onReport = (id) => reportEventInvoked = true; |
| 1 | 86 | | contextMenu.OnReport += onReport; |
| | 87 | |
|
| 1 | 88 | | contextMenu.Show(TEST_USER_ID); |
| 1 | 89 | | contextMenu.reportButton.onClick.Invoke(); |
| | 90 | |
|
| 1 | 91 | | contextMenu.OnReport -= onReport; |
| 1 | 92 | | Assert.IsTrue(reportEventInvoked); |
| 1 | 93 | | Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible."); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | [Test] |
| | 97 | | public void ClickOnBlockButton() |
| | 98 | | { |
| 1 | 99 | | bool blockEventInvoked = false; |
| 2 | 100 | | Action<string, bool> onBlock = (id, block) => blockEventInvoked = true; |
| 1 | 101 | | contextMenu.OnBlock += onBlock; |
| | 102 | |
|
| 1 | 103 | | contextMenu.Show(TEST_USER_ID); |
| 1 | 104 | | contextMenu.blockButton.onClick.Invoke(); |
| | 105 | |
|
| 1 | 106 | | contextMenu.OnBlock -= onBlock; |
| 1 | 107 | | Assert.IsTrue(blockEventInvoked); |
| 1 | 108 | | Assert.IsFalse(contextMenu.gameObject.activeSelf, "The context menu should not be visible."); |
| 1 | 109 | | } |
| | 110 | |
|
| | 111 | | [Test] |
| | 112 | | public void FriendSetupsCorrectly() |
| | 113 | | { |
| 1 | 114 | | contextMenu.Show(TEST_USER_ID, UserContextMenu.MenuConfigFlags.Friendship); |
| | 115 | |
|
| 1 | 116 | | Assert.IsTrue(contextMenu.friendshipContainer.activeSelf, "friendshipContainer should be active"); |
| | 117 | |
|
| 1 | 118 | | Assert.IsTrue(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should be active"); |
| 1 | 119 | | Assert.IsFalse(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should not be active"); |
| 1 | 120 | | Assert.IsFalse(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should not be active") |
| 1 | 121 | | Assert.IsFalse(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should not be active"); |
| | 122 | |
|
| 1 | 123 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 124 | | { |
| | 125 | | userId = TEST_USER_ID, |
| | 126 | | action = FriendshipAction.REQUESTED_TO |
| | 127 | | }); |
| | 128 | |
|
| 1 | 129 | | Assert.IsFalse(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should not be active"); |
| 1 | 130 | | Assert.IsFalse(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should not be active"); |
| 1 | 131 | | Assert.IsTrue(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should be active"); |
| 1 | 132 | | Assert.IsFalse(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should not be active"); |
| | 133 | |
|
| 1 | 134 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 135 | | { |
| | 136 | | userId = TEST_USER_ID, |
| | 137 | | action = FriendshipAction.APPROVED |
| | 138 | | }); |
| | 139 | |
|
| 1 | 140 | | Assert.IsFalse(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should not be active"); |
| 1 | 141 | | Assert.IsTrue(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should be active"); |
| 1 | 142 | | Assert.IsFalse(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should not be active") |
| 1 | 143 | | Assert.IsTrue(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should be active"); |
| | 144 | |
|
| 1 | 145 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 146 | | { |
| | 147 | | userId = TEST_USER_ID, |
| | 148 | | action = FriendshipAction.DELETED |
| | 149 | | }); |
| | 150 | |
|
| 1 | 151 | | Assert.IsTrue(contextMenu.friendAddContainer.activeSelf, "friendAddContainer should be active"); |
| 1 | 152 | | Assert.IsFalse(contextMenu.friendRemoveContainer.activeSelf, "friendRemoveContainer should not be active"); |
| 1 | 153 | | Assert.IsFalse(contextMenu.friendRequestedContainer.activeSelf, "friendRequestedContainer should not be active") |
| 1 | 154 | | Assert.IsFalse(contextMenu.deleteFriendButton.gameObject.activeSelf, "deleteFriendButton should not be active"); |
| 1 | 155 | | } |
| | 156 | |
|
| | 157 | | [Test] |
| | 158 | | public void MessageButtonSetupsCorrectly() |
| | 159 | | { |
| 1 | 160 | | contextMenu.Show(TEST_USER_ID, UserContextMenu.MenuConfigFlags.Message); |
| | 161 | |
|
| 1 | 162 | | Assert.IsFalse(contextMenu.messageButton.gameObject.activeSelf, "messageButton should not be active"); |
| | 163 | |
|
| 1 | 164 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 165 | | { |
| | 166 | | userId = TEST_USER_ID, |
| | 167 | | action = FriendshipAction.REQUESTED_TO |
| | 168 | | }); |
| | 169 | |
|
| 1 | 170 | | Assert.IsFalse(contextMenu.messageButton.gameObject.activeSelf, "messageButton should not be active"); |
| | 171 | |
|
| 1 | 172 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 173 | | { |
| | 174 | | userId = TEST_USER_ID, |
| | 175 | | action = FriendshipAction.APPROVED |
| | 176 | | }); |
| | 177 | |
|
| 1 | 178 | | Assert.IsTrue(contextMenu.messageButton.gameObject.activeSelf, "messageButton should be active"); |
| | 179 | |
|
| 1 | 180 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 181 | | { |
| | 182 | | userId = TEST_USER_ID, |
| | 183 | | action = FriendshipAction.DELETED |
| | 184 | | }); |
| | 185 | |
|
| 1 | 186 | | Assert.IsFalse(contextMenu.messageButton.gameObject.activeSelf, "messageButton should not be active"); |
| 1 | 187 | | } |
| | 188 | | } |