| | 1 | | using DCL.HelpAndSupportHUD; |
| | 2 | | using DCL.SettingsPanelHUD; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using System.Collections; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | |
|
| | 8 | | public class TaskbarHUDShould : IntegrationTestSuite_Legacy |
| | 9 | | { |
| | 10 | | private TaskbarHUDController controller; |
| | 11 | | private TaskbarHUDView view; |
| | 12 | |
|
| 1 | 13 | | private readonly FriendsController_Mock friendsController = new FriendsController_Mock(); |
| 1 | 14 | | private readonly ChatController_Mock chatController = new ChatController_Mock(); |
| | 15 | |
|
| | 16 | | private GameObject userProfileGO; |
| | 17 | | private PrivateChatWindowHUDController privateChatController; |
| | 18 | | private FriendsHUDController friendsHudController; |
| | 19 | | private WorldChatWindowHUDController worldChatWindowController; |
| | 20 | | private SettingsPanelHUDController settingsPanelHudController; |
| | 21 | | private HelpAndSupportHUDController helpAndSupportHUDController; |
| | 22 | | private ExploreHUDController exploreHUDController; |
| | 23 | |
|
| 10 | 24 | | protected override bool justSceneSetUp => true; |
| | 25 | |
|
| | 26 | | protected override IEnumerator SetUp() |
| | 27 | | { |
| 10 | 28 | | yield return base.SetUp(); |
| | 29 | |
|
| 10 | 30 | | CommonScriptableObjects.rendererState.Set(true); |
| | 31 | |
|
| 10 | 32 | | userProfileGO = new GameObject(); |
| | 33 | |
|
| 10 | 34 | | controller = new TaskbarHUDController(); |
| 10 | 35 | | controller.Initialize(null, chatController, null, null, null); |
| 10 | 36 | | view = controller.view; |
| | 37 | |
|
| 10 | 38 | | Assert.IsTrue(view != null, "Taskbar view is null?"); |
| 10 | 39 | | Assert.IsTrue(view.moreButton.gameObject.activeSelf, "More button is not actived?"); |
| 10 | 40 | | Assert.IsTrue(CommonScriptableObjects.isTaskbarHUDInitialized, "Taskbar controller is not initialized?"); |
| 10 | 41 | | } |
| | 42 | |
|
| | 43 | | protected override IEnumerator TearDown() |
| | 44 | | { |
| 10 | 45 | | yield return null; |
| | 46 | |
|
| 10 | 47 | | privateChatController?.Dispose(); |
| 10 | 48 | | worldChatWindowController?.Dispose(); |
| 10 | 49 | | friendsHudController?.Dispose(); |
| 10 | 50 | | settingsPanelHudController?.Dispose(); |
| 10 | 51 | | helpAndSupportHUDController?.Dispose(); |
| 10 | 52 | | exploreHUDController?.Dispose(); |
| | 53 | |
|
| 10 | 54 | | controller.Dispose(); |
| 10 | 55 | | UnityEngine.Object.Destroy(userProfileGO); |
| | 56 | |
|
| 10 | 57 | | yield return base.TearDown(); |
| 10 | 58 | | } |
| | 59 | |
|
| | 60 | | [Test] |
| | 61 | | public void AddWorldChatWindowProperly() |
| | 62 | | { |
| 1 | 63 | | worldChatWindowController = new WorldChatWindowHUDController(); |
| 1 | 64 | | worldChatWindowController.Initialize(null, null); |
| 1 | 65 | | controller.AddWorldChatWindow(worldChatWindowController); |
| | 66 | |
|
| 1 | 67 | | Assert.IsTrue(worldChatWindowController.view.transform.parent == view.leftWindowContainer, |
| | 68 | | "Chat window isn't inside taskbar window container!"); |
| 1 | 69 | | Assert.IsTrue(worldChatWindowController.view.gameObject.activeSelf, "Chat window is disabled!"); |
| 1 | 70 | | } |
| | 71 | |
|
| | 72 | | [Test] |
| | 73 | | public void AddFriendWindowProperly() |
| | 74 | | { |
| 1 | 75 | | friendsHudController = new FriendsHUDController(); |
| 1 | 76 | | friendsHudController.Initialize(null, null); |
| 1 | 77 | | controller.AddFriendsWindow(friendsHudController); |
| | 78 | |
|
| 1 | 79 | | Assert.IsTrue(friendsHudController.view.transform.parent == view.leftWindowContainer, |
| | 80 | | "Friends window isn't inside taskbar window container!"); |
| 1 | 81 | | Assert.IsTrue(friendsHudController.view.gameObject.activeSelf, "Friends window is disabled!"); |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | [Test] |
| | 85 | | public void AddSettingsWindowProperly() |
| | 86 | | { |
| 1 | 87 | | settingsPanelHudController = new SettingsPanelHUDController(); |
| 1 | 88 | | controller.AddSettingsWindow(settingsPanelHudController); |
| | 89 | |
|
| 1 | 90 | | Assert.IsTrue(settingsPanelHudController.view.gameObject.activeSelf, "Settings window is disabled!"); |
| 1 | 91 | | } |
| | 92 | |
|
| | 93 | | [Test] |
| | 94 | | public void AddHelpAndSupportWindowProperly() |
| | 95 | | { |
| 1 | 96 | | helpAndSupportHUDController = new HelpAndSupportHUDController(); |
| 1 | 97 | | controller.AddHelpAndSupportWindow(helpAndSupportHUDController); |
| | 98 | |
|
| 1 | 99 | | Assert.IsTrue(helpAndSupportHUDController.view.gameObject.activeSelf, "Help and Support window is disabled!"); |
| 1 | 100 | | } |
| | 101 | |
|
| | 102 | | [Test] |
| | 103 | | public void AddExploreWindowProperly() |
| | 104 | | { |
| 1 | 105 | | exploreHUDController = new ExploreHUDController(); |
| 1 | 106 | | exploreHUDController.Initialize(friendsController); |
| 1 | 107 | | controller.AddExploreWindow(exploreHUDController); |
| | 108 | |
|
| 1 | 109 | | Assert.IsTrue(exploreHUDController.view.gameObject.activeSelf, "Explore window is disabled!"); |
| 1 | 110 | | } |
| | 111 | |
|
| | 112 | | [Test] |
| | 113 | | public void AddControlsMoreButtonProperly() |
| | 114 | | { |
| 1 | 115 | | controller.AddControlsMoreOption(); |
| | 116 | |
|
| 1 | 117 | | Assert.IsTrue(view.moreMenu.controlsButton.mainButton.IsActive(), "Controls more button is disabled!"); |
| 1 | 118 | | } |
| | 119 | |
|
| | 120 | | [Test] |
| | 121 | | public void ToggleWindowsProperly() |
| | 122 | | { |
| 1 | 123 | | privateChatController = new PrivateChatWindowHUDController(); |
| 1 | 124 | | privateChatController.Initialize(chatController); |
| 1 | 125 | | controller.AddPrivateChatWindow(privateChatController); |
| | 126 | |
|
| | 127 | | const string badPositionMsg = |
| | 128 | | "Anchored position should be zero or it won't be correctly placed inside the taskbar"; |
| | 129 | | const string badPivotMsg = "Pivot should be zero or it won't be correctly placed inside the taskbar"; |
| | 130 | |
|
| 1 | 131 | | RectTransform rt = privateChatController.view.transform as RectTransform; |
| 1 | 132 | | Assert.AreEqual(Vector2.zero, rt.anchoredPosition, badPositionMsg); |
| 1 | 133 | | Assert.AreEqual(Vector2.zero, rt.pivot, badPivotMsg); |
| | 134 | |
|
| 1 | 135 | | worldChatWindowController = new WorldChatWindowHUDController(); |
| 1 | 136 | | worldChatWindowController.Initialize(chatController, null); |
| 1 | 137 | | controller.AddWorldChatWindow(worldChatWindowController); |
| | 138 | |
|
| 1 | 139 | | rt = worldChatWindowController.view.transform as RectTransform; |
| 1 | 140 | | Assert.AreEqual(Vector2.zero, rt.anchoredPosition, badPositionMsg); |
| 1 | 141 | | Assert.AreEqual(Vector2.zero, rt.pivot, badPivotMsg); |
| | 142 | |
|
| 1 | 143 | | friendsHudController = new FriendsHUDController(); |
| 1 | 144 | | friendsHudController.Initialize(friendsController, UserProfile.GetOwnUserProfile()); |
| 1 | 145 | | controller.AddFriendsWindow(friendsHudController); |
| | 146 | |
|
| 1 | 147 | | rt = friendsHudController.view.transform as RectTransform; |
| 1 | 148 | | Assert.AreEqual(Vector2.zero, rt.anchoredPosition, badPositionMsg); |
| 1 | 149 | | Assert.AreEqual(Vector2.zero, rt.pivot, badPivotMsg); |
| | 150 | |
|
| 1 | 151 | | TestHelpers_Friends.FakeAddFriend(friendsController, friendsHudController.view, "test-1"); |
| 1 | 152 | | TestHelpers_Chat.FakePrivateChatMessageFrom(chatController, "test-1", "test message!"); |
| | 153 | |
|
| 1 | 154 | | var buttonList = view.GetButtonList(); |
| | 155 | |
|
| 1 | 156 | | Assert.AreEqual(8, buttonList.Count, "Chat head is missing when receiving a private message?"); |
| | 157 | |
|
| 1 | 158 | | Assert.IsFalse(view.chatButton.toggledOn); |
| 1 | 159 | | Assert.IsTrue(buttonList[2] is ChatHeadButton); |
| | 160 | |
|
| 1 | 161 | | ChatHeadButton headButton = buttonList[2] as ChatHeadButton; |
| 1 | 162 | | Assert.IsFalse(headButton.toggledOn); |
| 1 | 163 | | Assert.IsTrue(headButton.toggleButton.interactable); |
| | 164 | |
|
| | 165 | | //NOTE(Brian): Toggle chat head on and test it works as intended |
| 1 | 166 | | headButton.toggleButton.onClick.Invoke(); |
| | 167 | |
|
| 1 | 168 | | Assert.IsTrue(headButton.lineOnIndicator.isVisible); |
| 1 | 169 | | Assert.IsFalse(view.friendsButton.lineOnIndicator.isVisible); |
| 1 | 170 | | Assert.IsFalse(view.chatButton.lineOnIndicator.isVisible); |
| 1 | 171 | | Assert.IsTrue(controller.privateChatWindowHud.view.gameObject.activeInHierarchy); |
| | 172 | |
|
| | 173 | | //NOTE(Brian): Toggle friends window on and test all other windows are untoggled |
| 1 | 174 | | view.friendsButton.toggleButton.onClick.Invoke(); |
| | 175 | |
|
| 1 | 176 | | Assert.IsFalse(controller.privateChatWindowHud.view.gameObject.activeInHierarchy); |
| 1 | 177 | | Assert.IsFalse(headButton.lineOnIndicator.isVisible); |
| 1 | 178 | | Assert.IsTrue(view.friendsButton.lineOnIndicator.isVisible); |
| 1 | 179 | | Assert.IsFalse(view.chatButton.lineOnIndicator.isVisible); |
| | 180 | |
|
| | 181 | | //NOTE(Brian): Toggle friends window off and test all other windows are untoggled |
| 1 | 182 | | view.friendsButton.toggleButton.onClick.Invoke(); |
| | 183 | |
|
| 1 | 184 | | Assert.IsFalse(controller.privateChatWindowHud.view.gameObject.activeInHierarchy); |
| 1 | 185 | | Assert.IsFalse(headButton.lineOnIndicator.isVisible); |
| 1 | 186 | | Assert.IsFalse(view.friendsButton.lineOnIndicator.isVisible); |
| | 187 | |
|
| | 188 | | //NOTE(Brian): Toggle friends on, and then chat button on. Then check if world chat window is showing up. |
| 1 | 189 | | view.friendsButton.toggleButton.onClick.Invoke(); |
| 1 | 190 | | view.chatButton.toggleButton.onClick.Invoke(); |
| | 191 | |
|
| 1 | 192 | | Assert.IsTrue(controller.worldChatWindowHud.view.gameObject.activeInHierarchy); |
| 1 | 193 | | Assert.IsFalse(controller.friendsHud.view.gameObject.activeInHierarchy); |
| 1 | 194 | | Assert.IsFalse(view.friendsButton.lineOnIndicator.isVisible); |
| 1 | 195 | | } |
| | 196 | |
|
| | 197 | | [Test] |
| | 198 | | public void ToggleBarVisibilityProperly() |
| | 199 | | { |
| 1 | 200 | | view.moreMenu.collapseBarButton.mainButton.onClick.Invoke(); |
| | 201 | |
|
| 1 | 202 | | Assert.IsFalse(view.isBarVisible, "The bar should not be visible!"); |
| 1 | 203 | | Assert.IsFalse(view.moreMenu.collapseIcon.activeSelf, "The collapse icon should not be actived!"); |
| 1 | 204 | | Assert.IsFalse(view.moreMenu.collapseText.activeSelf, "The collapse text should not be actived!"); |
| 1 | 205 | | Assert.IsTrue(view.moreMenu.expandIcon.activeSelf, "The expand icon should be actived!"); |
| 1 | 206 | | Assert.IsTrue(view.moreMenu.expandText.activeSelf, "The expand text should be actived!"); |
| | 207 | |
|
| 1 | 208 | | view.moreMenu.collapseBarButton.mainButton.onClick.Invoke(); |
| | 209 | |
|
| 1 | 210 | | Assert.IsTrue(view.isBarVisible, "The bar should be visible!"); |
| 1 | 211 | | Assert.IsTrue(view.moreMenu.collapseIcon.activeSelf, "The collapse icon should be actived!"); |
| 1 | 212 | | Assert.IsTrue(view.moreMenu.collapseText.activeSelf, "The collapse text should be actived!"); |
| 1 | 213 | | Assert.IsFalse(view.moreMenu.expandIcon.activeSelf, "The expand icon should not be actived!"); |
| 1 | 214 | | Assert.IsFalse(view.moreMenu.expandText.activeSelf, "The expand text should not be actived!"); |
| 1 | 215 | | } |
| | 216 | |
|
| | 217 | | [Test] |
| | 218 | | public void AddPortableExperienceItemProperly() |
| | 219 | | { |
| | 220 | | // Arrange |
| 1 | 221 | | string testPEId = "test-pe"; |
| | 222 | |
|
| | 223 | | // Act |
| 1 | 224 | | view.AddPortableExperienceElement(testPEId, "Test PE", ""); |
| | 225 | |
|
| | 226 | | // Assert |
| 1 | 227 | | Assert.IsTrue(view.portableExperiencesDiv.activeSelf, "The Portable Experiences Div should be actived!"); |
| 1 | 228 | | var newPE = view.rightButtonsContainer.GetComponentInChildren<PortableExperienceTaskbarItem>(); |
| 1 | 229 | | Assert.IsNotNull(newPE, "There should exists a PortableExperienceTaskbarItem as child!"); |
| 1 | 230 | | Assert.AreEqual(0, newPE.gameObject.transform.GetSiblingIndex(), "The sibling index for the new Portable Experie |
| 1 | 231 | | Assert.IsTrue(view.activePortableExperienceItems.ContainsKey(testPEId), "The activePortableExperienceItems dicti |
| 1 | 232 | | Assert.IsTrue(view.activePortableExperiencesPoolables.ContainsKey(testPEId), "The activePortableExperiencesPoola |
| 1 | 233 | | } |
| | 234 | |
|
| | 235 | | [Test] |
| | 236 | | public void RemovePortableExperienceItemProperly() |
| | 237 | | { |
| | 238 | | // Arrange |
| 1 | 239 | | string testPEId = "test-pe"; |
| | 240 | |
|
| | 241 | | // Act |
| 1 | 242 | | view.AddPortableExperienceElement(testPEId, "Test PE", ""); |
| 1 | 243 | | view.RemovePortableExperienceElement(testPEId); |
| | 244 | |
|
| | 245 | | // Assert |
| 1 | 246 | | Assert.IsFalse(view.portableExperiencesDiv.activeSelf, "The Portable Experiences Div should not be actived!"); |
| 1 | 247 | | var newPE = view.rightButtonsContainer.GetComponentInChildren<PortableExperienceTaskbarItem>(); |
| 1 | 248 | | Assert.IsNull(newPE, "There should not exists a PortableExperienceTaskbarItem as child!"); |
| 1 | 249 | | Assert.IsFalse(view.activePortableExperienceItems.ContainsKey(testPEId), "The activePortableExperienceItems dict |
| 1 | 250 | | Assert.IsFalse(view.activePortableExperiencesPoolables.ContainsKey(testPEId), "The activePortableExperiencesPool |
| 1 | 251 | | } |
| | 252 | | } |