| | 1 | | using System.Collections.Generic; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEditor; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace Tests |
| | 7 | | { |
| | 8 | | public class UsersSearchPromptShould |
| | 9 | | { |
| | 10 | | private UsersSearchPromptView promptView; |
| | 11 | |
|
| | 12 | | [SetUp] |
| | 13 | | public void SetUp() |
| | 14 | | { |
| | 15 | | const string prefabAssetPath = |
| | 16 | | "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/UsersSearchPrompt/UsersSear |
| 7 | 17 | | var viewPrefab = AssetDatabase.LoadAssetAtPath<UsersSearchPromptView>(prefabAssetPath); |
| 7 | 18 | | promptView = Object.Instantiate(viewPrefab); |
| 7 | 19 | | } |
| | 20 | |
|
| | 21 | | [TearDown] |
| 14 | 22 | | public void TearDown() { Object.Destroy(promptView.gameObject); } |
| | 23 | |
|
| | 24 | | [Test] |
| 2 | 25 | | public void HavePrefabSetupCorrectly() { Assert.AreEqual(1, promptView.friendListParent.childCount); } |
| | 26 | |
|
| | 27 | | [Test] |
| | 28 | | public void ShowFriendsCorrectly() |
| | 29 | | { |
| 1 | 30 | | FriendsController_Mock friendsController = new FriendsController_Mock(); |
| 1 | 31 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship |
| 1 | 32 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "2", friendshipStatus = Friendship |
| 1 | 33 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "3", friendshipStatus = Friendship |
| | 34 | |
|
| 1 | 35 | | var profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 36 | | profile.UpdateData(new UserProfileModel() { name = "Temp", userId = "1" }); |
| 1 | 37 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| 1 | 38 | | profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 39 | | profile.UpdateData(new UserProfileModel() { name = "ta", userId = "2" }); |
| 1 | 40 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| 1 | 41 | | profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 42 | | profile.UpdateData(new UserProfileModel() { name = "tion", userId = "3" }); |
| 1 | 43 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| | 44 | |
|
| 1 | 45 | | FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController); |
| 1 | 46 | | controller.Show(); |
| | 47 | |
|
| 1 | 48 | | Assert.AreEqual(3, promptView.friendListParent.childCount); |
| 1 | 49 | | Assert.AreEqual("Temp", controller.userViewsHandler.userElementViews["1"].textUserName.text); |
| 1 | 50 | | Assert.AreEqual("ta", controller.userViewsHandler.userElementViews["2"].textUserName.text); |
| 1 | 51 | | Assert.AreEqual("tion", controller.userViewsHandler.userElementViews["3"].textUserName.text); |
| | 52 | |
|
| 1 | 53 | | controller.Dispose(); |
| 1 | 54 | | } |
| | 55 | |
|
| | 56 | | [Test] |
| | 57 | | public void SearchFriendsCorrectly() |
| | 58 | | { |
| 1 | 59 | | FriendsController_Mock friendsController = new FriendsController_Mock(); |
| 1 | 60 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship |
| 1 | 61 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "2", friendshipStatus = Friendship |
| 1 | 62 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "3", friendshipStatus = Friendship |
| | 63 | |
|
| 1 | 64 | | var profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 65 | | profile.UpdateData(new UserProfileModel() { name = "Temp", userId = "1" }); |
| 1 | 66 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| 1 | 67 | | profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 68 | | profile.UpdateData(new UserProfileModel() { name = "ta", userId = "2" }); |
| 1 | 69 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| 1 | 70 | | profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 71 | | profile.UpdateData(new UserProfileModel() { name = "tion", userId = "3" }); |
| 1 | 72 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| | 73 | |
|
| 1 | 74 | | FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController); |
| 1 | 75 | | controller.Show(); |
| 1 | 76 | | promptView.searchInputField.OnSubmit("Temp"); |
| | 77 | |
|
| 1 | 78 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["1"].gameObject.activeSelf); |
| 1 | 79 | | Assert.IsFalse(controller.userViewsHandler.userElementViews["2"].gameObject.activeSelf); |
| 1 | 80 | | Assert.IsFalse(controller.userViewsHandler.userElementViews["3"].gameObject.activeSelf); |
| | 81 | |
|
| 1 | 82 | | controller.Dispose(); |
| 1 | 83 | | } |
| | 84 | |
|
| | 85 | | [Test] |
| | 86 | | public void ShowIfFriendsIsAddedToRolCorrectly() |
| | 87 | | { |
| 1 | 88 | | FriendsController_Mock friendsController = new FriendsController_Mock(); |
| 1 | 89 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship |
| 1 | 90 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "2", friendshipStatus = Friendship |
| 1 | 91 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "3", friendshipStatus = Friendship |
| | 92 | |
|
| 1 | 93 | | var profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 94 | | profile.UpdateData(new UserProfileModel() { name = "Temp", userId = "1" }); |
| 1 | 95 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| 1 | 96 | | profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 97 | | profile.UpdateData(new UserProfileModel() { name = "ta", userId = "2" }); |
| 1 | 98 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| 1 | 99 | | profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 100 | | profile.UpdateData(new UserProfileModel() { name = "tion", userId = "3" }); |
| 1 | 101 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| | 102 | |
|
| 1 | 103 | | FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController); |
| 1 | 104 | | controller.Show(); |
| 1 | 105 | | controller.SetUsersInRolList(new List<string>() { "1" }); |
| | 106 | |
|
| 1 | 107 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["1"].removeButton.gameObject.activeSelf); |
| 1 | 108 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["2"].addButton.gameObject.activeSelf); |
| 1 | 109 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["3"].addButton.gameObject.activeSelf); |
| | 110 | |
|
| 1 | 111 | | controller.Dispose(); |
| 1 | 112 | | } |
| | 113 | |
|
| | 114 | | [Test] |
| | 115 | | public void TriggerAddButtonCorrectlyOnClick() |
| | 116 | | { |
| 1 | 117 | | FriendsController_Mock friendsController = new FriendsController_Mock(); |
| 1 | 118 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship |
| | 119 | |
|
| 1 | 120 | | var profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 121 | | profile.UpdateData(new UserProfileModel() { name = "Temptation", userId = "1" }); |
| 1 | 122 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| | 123 | |
|
| 1 | 124 | | FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController); |
| 1 | 125 | | controller.Show(); |
| | 126 | |
|
| 1 | 127 | | bool triggered = false; |
| | 128 | |
|
| 2 | 129 | | void OnButtonPressed(string id) { triggered = id == "1"; } |
| | 130 | |
|
| 1 | 131 | | controller.userViewsHandler.userElementViews["1"].OnAddPressed += OnButtonPressed; |
| 1 | 132 | | controller.userViewsHandler.userElementViews["1"].addButton.onClick.Invoke(); |
| | 133 | |
|
| 1 | 134 | | Assert.IsTrue(triggered); |
| 1 | 135 | | controller.Dispose(); |
| 1 | 136 | | } |
| | 137 | |
|
| | 138 | | [Test] |
| | 139 | | public void TriggerRemoveButtonCorrectlyOnClick() |
| | 140 | | { |
| 1 | 141 | | FriendsController_Mock friendsController = new FriendsController_Mock(); |
| 1 | 142 | | friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship |
| | 143 | |
|
| 1 | 144 | | var profile = ScriptableObject.CreateInstance<UserProfile>(); |
| 1 | 145 | | profile.UpdateData(new UserProfileModel() { name = "Temptation", userId = "1" }); |
| 1 | 146 | | UserProfileController.userProfilesCatalog.Add(profile.userId, profile); |
| | 147 | |
|
| 1 | 148 | | FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController); |
| 1 | 149 | | controller.Show(); |
| | 150 | |
|
| 1 | 151 | | bool triggered = false; |
| | 152 | |
|
| 2 | 153 | | void OnButtonPressed(string id) { triggered = id == "1"; } |
| | 154 | |
|
| 1 | 155 | | controller.userViewsHandler.userElementViews["1"].OnRemovePressed += OnButtonPressed; |
| 1 | 156 | | controller.userViewsHandler.userElementViews["1"].removeButton.onClick.Invoke(); |
| | 157 | |
|
| 1 | 158 | | Assert.IsTrue(triggered); |
| 1 | 159 | | controller.Dispose(); |
| 1 | 160 | | } |
| | 161 | |
|
| | 162 | | [Test] |
| | 163 | | public void SearchUserCorrectly() |
| | 164 | | { |
| 1 | 165 | | UsersSearchPromptController controller = new UsersSearchPromptController(promptView); |
| 1 | 166 | | controller.Show(); |
| 1 | 167 | | promptView.searchInputField.OnSubmit("Temp"); |
| 1 | 168 | | controller.usersSearchPromise.Resolve(new [] |
| | 169 | | { |
| | 170 | | new UserProfileModel() { userId = "Temp" }, |
| | 171 | | new UserProfileModel() { userId = "ta" }, |
| | 172 | | new UserProfileModel() { userId = "tion" }, |
| | 173 | | }); |
| | 174 | |
|
| 1 | 175 | | Assert.AreEqual(3, promptView.friendListParent.childCount); |
| 1 | 176 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["Temp"].gameObject.activeSelf); |
| 1 | 177 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["ta"].gameObject.activeSelf); |
| 1 | 178 | | Assert.IsTrue(controller.userViewsHandler.userElementViews["tion"].gameObject.activeSelf); |
| | 179 | |
|
| 1 | 180 | | controller.Dispose(); |
| 1 | 181 | | } |
| | 182 | | } |
| | 183 | | } |