< Summary

Class:Tests.UsersSearchPromptShould
Assembly:BuilderProjectsPanelTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/UsersSearchPromptShould.cs
Covered lines:106
Uncovered lines:0
Coverable lines:106
Total lines:183
Line coverage:100% (106 of 106)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
HavePrefabSetupCorrectly()0%110100%
ShowFriendsCorrectly()0%110100%
SearchFriendsCorrectly()0%110100%
ShowIfFriendsIsAddedToRolCorrectly()0%110100%
TriggerAddButtonCorrectlyOnClick()0%110100%
TriggerRemoveButtonCorrectlyOnClick()0%110100%
SearchUserCorrectly()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/UsersSearchPromptShould.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using NUnit.Framework;
 3using UnityEditor;
 4using UnityEngine;
 5
 6namespace 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
 717            var viewPrefab = AssetDatabase.LoadAssetAtPath<UsersSearchPromptView>(prefabAssetPath);
 718            promptView = Object.Instantiate(viewPrefab);
 719        }
 20
 21        [TearDown]
 1422        public void TearDown() { Object.Destroy(promptView.gameObject); }
 23
 24        [Test]
 225        public void HavePrefabSetupCorrectly() { Assert.AreEqual(1, promptView.friendListParent.childCount); }
 26
 27        [Test]
 28        public void ShowFriendsCorrectly()
 29        {
 130            FriendsController_Mock friendsController = new FriendsController_Mock();
 131            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship
 132            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "2", friendshipStatus = Friendship
 133            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "3", friendshipStatus = Friendship
 34
 135            var profile = ScriptableObject.CreateInstance<UserProfile>();
 136            profile.UpdateData(new UserProfileModel() { name = "Temp", userId = "1" });
 137            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 138            profile = ScriptableObject.CreateInstance<UserProfile>();
 139            profile.UpdateData(new UserProfileModel() { name = "ta", userId = "2" });
 140            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 141            profile = ScriptableObject.CreateInstance<UserProfile>();
 142            profile.UpdateData(new UserProfileModel() { name = "tion", userId = "3" });
 143            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 44
 145            FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController);
 146            controller.Show();
 47
 148            Assert.AreEqual(3, promptView.friendListParent.childCount);
 149            Assert.AreEqual("Temp", controller.userViewsHandler.userElementViews["1"].textUserName.text);
 150            Assert.AreEqual("ta", controller.userViewsHandler.userElementViews["2"].textUserName.text);
 151            Assert.AreEqual("tion", controller.userViewsHandler.userElementViews["3"].textUserName.text);
 52
 153            controller.Dispose();
 154        }
 55
 56        [Test]
 57        public void SearchFriendsCorrectly()
 58        {
 159            FriendsController_Mock friendsController = new FriendsController_Mock();
 160            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship
 161            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "2", friendshipStatus = Friendship
 162            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "3", friendshipStatus = Friendship
 63
 164            var profile = ScriptableObject.CreateInstance<UserProfile>();
 165            profile.UpdateData(new UserProfileModel() { name = "Temp", userId = "1" });
 166            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 167            profile = ScriptableObject.CreateInstance<UserProfile>();
 168            profile.UpdateData(new UserProfileModel() { name = "ta", userId = "2" });
 169            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 170            profile = ScriptableObject.CreateInstance<UserProfile>();
 171            profile.UpdateData(new UserProfileModel() { name = "tion", userId = "3" });
 172            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 73
 174            FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController);
 175            controller.Show();
 176            promptView.searchInputField.OnSubmit("Temp");
 77
 178            Assert.IsTrue(controller.userViewsHandler.userElementViews["1"].gameObject.activeSelf);
 179            Assert.IsFalse(controller.userViewsHandler.userElementViews["2"].gameObject.activeSelf);
 180            Assert.IsFalse(controller.userViewsHandler.userElementViews["3"].gameObject.activeSelf);
 81
 182            controller.Dispose();
 183        }
 84
 85        [Test]
 86        public void ShowIfFriendsIsAddedToRolCorrectly()
 87        {
 188            FriendsController_Mock friendsController = new FriendsController_Mock();
 189            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship
 190            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "2", friendshipStatus = Friendship
 191            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "3", friendshipStatus = Friendship
 92
 193            var profile = ScriptableObject.CreateInstance<UserProfile>();
 194            profile.UpdateData(new UserProfileModel() { name = "Temp", userId = "1" });
 195            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 196            profile = ScriptableObject.CreateInstance<UserProfile>();
 197            profile.UpdateData(new UserProfileModel() { name = "ta", userId = "2" });
 198            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 199            profile = ScriptableObject.CreateInstance<UserProfile>();
 1100            profile.UpdateData(new UserProfileModel() { name = "tion", userId = "3" });
 1101            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 102
 1103            FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController);
 1104            controller.Show();
 1105            controller.SetUsersInRolList(new List<string>() { "1" });
 106
 1107            Assert.IsTrue(controller.userViewsHandler.userElementViews["1"].removeButton.gameObject.activeSelf);
 1108            Assert.IsTrue(controller.userViewsHandler.userElementViews["2"].addButton.gameObject.activeSelf);
 1109            Assert.IsTrue(controller.userViewsHandler.userElementViews["3"].addButton.gameObject.activeSelf);
 110
 1111            controller.Dispose();
 1112        }
 113
 114        [Test]
 115        public void TriggerAddButtonCorrectlyOnClick()
 116        {
 1117            FriendsController_Mock friendsController = new FriendsController_Mock();
 1118            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship
 119
 1120            var profile = ScriptableObject.CreateInstance<UserProfile>();
 1121            profile.UpdateData(new UserProfileModel() { name = "Temptation", userId = "1" });
 1122            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 123
 1124            FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController);
 1125            controller.Show();
 126
 1127            bool triggered = false;
 128
 2129            void OnButtonPressed(string id) { triggered = id == "1"; }
 130
 1131            controller.userViewsHandler.userElementViews["1"].OnAddPressed += OnButtonPressed;
 1132            controller.userViewsHandler.userElementViews["1"].addButton.onClick.Invoke();
 133
 1134            Assert.IsTrue(triggered);
 1135            controller.Dispose();
 1136        }
 137
 138        [Test]
 139        public void TriggerRemoveButtonCorrectlyOnClick()
 140        {
 1141            FriendsController_Mock friendsController = new FriendsController_Mock();
 1142            friendsController.AddFriend(new FriendsController.UserStatus() { userId = "1", friendshipStatus = Friendship
 143
 1144            var profile = ScriptableObject.CreateInstance<UserProfile>();
 1145            profile.UpdateData(new UserProfileModel() { name = "Temptation", userId = "1" });
 1146            UserProfileController.userProfilesCatalog.Add(profile.userId, profile);
 147
 1148            FriendsSearchPromptController controller = new FriendsSearchPromptController(promptView, friendsController);
 1149            controller.Show();
 150
 1151            bool triggered = false;
 152
 2153            void OnButtonPressed(string id) { triggered = id == "1"; }
 154
 1155            controller.userViewsHandler.userElementViews["1"].OnRemovePressed += OnButtonPressed;
 1156            controller.userViewsHandler.userElementViews["1"].removeButton.onClick.Invoke();
 157
 1158            Assert.IsTrue(triggered);
 1159            controller.Dispose();
 1160        }
 161
 162        [Test]
 163        public void SearchUserCorrectly()
 164        {
 1165            UsersSearchPromptController controller = new UsersSearchPromptController(promptView);
 1166            controller.Show();
 1167            promptView.searchInputField.OnSubmit("Temp");
 1168            controller.usersSearchPromise.Resolve(new []
 169            {
 170                new UserProfileModel() { userId = "Temp" },
 171                new UserProfileModel() { userId = "ta" },
 172                new UserProfileModel() { userId = "tion" },
 173            });
 174
 1175            Assert.AreEqual(3, promptView.friendListParent.childCount);
 1176            Assert.IsTrue(controller.userViewsHandler.userElementViews["Temp"].gameObject.activeSelf);
 1177            Assert.IsTrue(controller.userViewsHandler.userElementViews["ta"].gameObject.activeSelf);
 1178            Assert.IsTrue(controller.userViewsHandler.userElementViews["tion"].gameObject.activeSelf);
 179
 1180            controller.Dispose();
 1181        }
 182    }
 183}