| | 1 | | using DCL.Interface; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.TestTools; |
| | 6 | |
|
| | 7 | | public class WorldChatWindowHUDShould : IntegrationTestSuite_Legacy |
| | 8 | | { |
| | 9 | | private WorldChatWindowHUDController controller; |
| | 10 | | private WorldChatWindowHUDView view; |
| | 11 | | private ChatController_Mock chatController; |
| | 12 | | private MouseCatcher_Mock mouseCatcher; |
| | 13 | |
|
| | 14 | | private UserProfileModel ownProfileModel; |
| | 15 | | private UserProfileModel testProfileModel; |
| | 16 | |
|
| 7 | 17 | | protected override bool justSceneSetUp => true; |
| | 18 | |
|
| | 19 | | protected override IEnumerator SetUp() |
| | 20 | | { |
| 7 | 21 | | yield return base.SetUp(); |
| | 22 | |
|
| 7 | 23 | | UserProfileController.i.ClearProfilesCatalog(); |
| | 24 | |
|
| 7 | 25 | | var ownProfile = UserProfile.GetOwnUserProfile(); |
| | 26 | |
|
| 7 | 27 | | ownProfileModel = new UserProfileModel(); |
| 7 | 28 | | ownProfileModel.userId = "my-user-id"; |
| 7 | 29 | | ownProfileModel.name = "NO_USER"; |
| 7 | 30 | | ownProfile.UpdateData(ownProfileModel, false); |
| | 31 | |
|
| 7 | 32 | | testProfileModel = new UserProfileModel(); |
| 7 | 33 | | testProfileModel.userId = "my-user-id-2"; |
| 7 | 34 | | testProfileModel.name = "TEST_USER"; |
| 7 | 35 | | UserProfileController.i.AddUserProfileToCatalog(testProfileModel); |
| | 36 | |
|
| | 37 | | //NOTE(Brian): This profile is added by the LoadProfile message in the normal flow. |
| | 38 | | // Adding this here because its used by the chat flow in ChatMessageToChatEntry. |
| 7 | 39 | | UserProfileController.i.AddUserProfileToCatalog(ownProfileModel); |
| | 40 | |
|
| 7 | 41 | | controller = new WorldChatWindowHUDController(); |
| 7 | 42 | | chatController = new ChatController_Mock(); |
| 7 | 43 | | mouseCatcher = new MouseCatcher_Mock(); |
| | 44 | |
|
| 7 | 45 | | controller.Initialize(chatController, mouseCatcher); |
| 7 | 46 | | this.view = controller.view; |
| | 47 | |
|
| 7 | 48 | | Assert.IsTrue(view != null, "World chat hud view is null?"); |
| 7 | 49 | | Assert.IsTrue(controller != null, "World chat hud controller is null?"); |
| 7 | 50 | | } |
| | 51 | |
|
| | 52 | | protected override IEnumerator TearDown() |
| | 53 | | { |
| 7 | 54 | | controller.Dispose(); |
| 7 | 55 | | yield return base.TearDown(); |
| 7 | 56 | | } |
| | 57 | |
|
| | 58 | | [Test] |
| | 59 | | public void HandlePrivateMessagesProperly() |
| | 60 | | { |
| 1 | 61 | | var sentPM = new ChatMessage() |
| | 62 | | { |
| | 63 | | messageType = ChatMessage.Type.PRIVATE, |
| | 64 | | body = "test message", |
| | 65 | | sender = ownProfileModel.userId, |
| | 66 | | recipient = testProfileModel.userId |
| | 67 | | }; |
| | 68 | |
|
| 1 | 69 | | chatController.RaiseAddMessage(sentPM); |
| | 70 | |
|
| 1 | 71 | | Assert.AreEqual(1, controller.view.chatHudView.entries.Count); |
| | 72 | |
|
| 1 | 73 | | ChatEntry entry = controller.view.chatHudView.entries[0]; |
| | 74 | |
|
| 1 | 75 | | Assert.AreEqual("<b>To TEST_USER:</b>", entry.username.text); |
| 1 | 76 | | Assert.AreEqual("<b>To TEST_USER:</b> test message", entry.body.text); |
| | 77 | |
|
| 1 | 78 | | var receivedPM = new ChatMessage() |
| | 79 | | { |
| | 80 | | messageType = ChatMessage.Type.PRIVATE, |
| | 81 | | body = "test message", |
| | 82 | | sender = testProfileModel.userId, |
| | 83 | | recipient = ownProfileModel.userId |
| | 84 | | }; |
| | 85 | |
|
| 1 | 86 | | chatController.RaiseAddMessage(receivedPM); |
| | 87 | |
|
| 1 | 88 | | ChatEntry entry2 = controller.view.chatHudView.entries[1]; |
| | 89 | |
|
| 1 | 90 | | Assert.AreEqual("<b>From TEST_USER:</b>", entry2.username.text); |
| 1 | 91 | | Assert.AreEqual("<b>From TEST_USER:</b> test message", entry2.body.text); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [Test] |
| | 95 | | public void HandleChatControllerProperly() |
| | 96 | | { |
| 1 | 97 | | var chatMessage = new ChatMessage() |
| | 98 | | { |
| | 99 | | messageType = ChatMessage.Type.PUBLIC, |
| | 100 | | body = "test message", |
| | 101 | | sender = testProfileModel.userId |
| | 102 | | }; |
| | 103 | |
|
| 1 | 104 | | chatController.RaiseAddMessage(chatMessage); |
| | 105 | |
|
| 1 | 106 | | Assert.AreEqual(1, controller.view.chatHudView.entries.Count); |
| | 107 | |
|
| 1 | 108 | | var entry = controller.view.chatHudView.entries[0]; |
| | 109 | |
|
| 1 | 110 | | var chatEntryModel = ChatHUDController.ChatMessageToChatEntry(chatMessage); |
| | 111 | |
|
| 1 | 112 | | Assert.AreEqual(entry.model, chatEntryModel); |
| 1 | 113 | | } |
| | 114 | |
|
| | 115 | | [Test] |
| | 116 | | public void HandleMouseCatcherProperly() |
| | 117 | | { |
| 1 | 118 | | mouseCatcher.RaiseMouseLock(); |
| 1 | 119 | | Assert.AreEqual(0, view.group.alpha); |
| 1 | 120 | | } |
| | 121 | |
|
| | 122 | | [UnityTest] |
| | 123 | | public IEnumerator SendChatMessageProperly() |
| | 124 | | { |
| 1 | 125 | | bool messageWasSent = false; |
| | 126 | |
|
| 1 | 127 | | System.Action<string, string> messageCallback = |
| | 128 | | (type, msg) => |
| | 129 | | { |
| 1 | 130 | | if (type == "SendChatMessage" && msg.Contains("test message")) |
| | 131 | | { |
| 1 | 132 | | messageWasSent = true; |
| | 133 | | } |
| 1 | 134 | | }; |
| | 135 | |
|
| 1 | 136 | | WebInterface.OnMessageFromEngine += messageCallback; |
| 1 | 137 | | controller.resetInputFieldOnSubmit = false; |
| 1 | 138 | | controller.SendChatMessage(new ChatMessage() { body = "test message" }); |
| 1 | 139 | | Assert.IsTrue(messageWasSent); |
| 1 | 140 | | WebInterface.OnMessageFromEngine -= messageCallback; |
| 1 | 141 | | yield return null; |
| 1 | 142 | | yield return null; |
| 1 | 143 | | yield return null; |
| 1 | 144 | | yield break; |
| | 145 | | } |
| | 146 | |
|
| | 147 | | [Test] |
| | 148 | | public void CloseWhenButtonPressed() |
| | 149 | | { |
| 1 | 150 | | controller.SetVisibility(true); |
| 1 | 151 | | Assert.AreEqual(true, controller.view.gameObject.activeSelf); |
| 1 | 152 | | controller.view.closeButton.onClick.Invoke(); |
| 1 | 153 | | Assert.AreEqual(false, controller.view.gameObject.activeSelf); |
| 1 | 154 | | } |
| | 155 | |
|
| | 156 | | [UnityTest] |
| | 157 | | public IEnumerator KeepWhisperCommandAfterUsage() |
| | 158 | | { |
| 1 | 159 | | string baseCommand = "/w testUser "; |
| | 160 | |
|
| 1 | 161 | | controller.resetInputFieldOnSubmit = false; |
| | 162 | |
|
| 1 | 163 | | controller.view.chatHudView.inputField.text = baseCommand + "testMessage"; |
| 1 | 164 | | yield return null; |
| | 165 | |
|
| 1 | 166 | | controller.view.chatHudView.inputField.onSubmit.Invoke(controller.view.chatHudView.inputField.text); |
| | 167 | |
|
| 1 | 168 | | yield return null; |
| | 169 | |
|
| 1 | 170 | | Assert.AreEqual(baseCommand, controller.view.chatHudView.inputField.text); |
| | 171 | |
|
| 1 | 172 | | baseCommand = "/w testUser "; |
| | 173 | |
|
| 1 | 174 | | controller.view.chatHudView.inputField.text = baseCommand + "testMessage"; |
| 1 | 175 | | yield return null; |
| | 176 | |
|
| 1 | 177 | | controller.view.chatHudView.inputField.onSubmit.Invoke(controller.view.chatHudView.inputField.text); |
| | 178 | |
|
| 1 | 179 | | yield return null; |
| | 180 | |
|
| 1 | 181 | | Assert.AreEqual(baseCommand, controller.view.chatHudView.inputField.text); |
| 1 | 182 | | yield break; |
| | 183 | | } |
| | 184 | |
|
| | 185 | | [UnityTest] |
| | 186 | | public IEnumerator WhisperLastPrivateMessageSenderOnReply() |
| | 187 | | { |
| 1 | 188 | | UserProfile ownProfile = UserProfile.GetOwnUserProfile(); |
| | 189 | |
|
| 1 | 190 | | var model = new UserProfileModel() |
| | 191 | | { |
| | 192 | | userId = "testUserId", |
| | 193 | | name = "testUserName", |
| | 194 | | }; |
| | 195 | |
|
| 1 | 196 | | UserProfileController.i.AddUserProfileToCatalog(model); |
| | 197 | |
|
| 1 | 198 | | var msg = new ChatMessage() |
| | 199 | | { |
| | 200 | | body = "test message", |
| | 201 | | sender = model.userId, |
| | 202 | | recipient = ownProfile.userId, |
| | 203 | | messageType = ChatMessage.Type.PRIVATE |
| | 204 | | }; |
| | 205 | |
|
| 1 | 206 | | yield return null; |
| | 207 | |
|
| 1 | 208 | | chatController.AddMessageToChatWindow(JsonUtility.ToJson(msg)); |
| | 209 | |
|
| 1 | 210 | | yield return null; |
| | 211 | |
|
| 1 | 212 | | Assert.AreEqual(controller.lastPrivateMessageReceivedSender, model.name); |
| | 213 | |
|
| 1 | 214 | | controller.view.chatHudView.inputField.text = "/r "; |
| | 215 | |
|
| 1 | 216 | | Assert.AreEqual($"/w {model.name} ", controller.view.chatHudView.inputField.text); |
| | 217 | |
|
| 1 | 218 | | yield return null; |
| | 219 | |
|
| 1 | 220 | | yield break; |
| | 221 | | } |
| | 222 | | } |