< Summary

Class:WorldChatWindowHUDShould
Assembly:WorldChatWindowHUDTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/Tests/WorldChatWindowHUDShould.cs
Covered lines:91
Uncovered lines:0
Coverable lines:91
Total lines:222
Line coverage:100% (91 of 91)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
TearDown()0%330100%
HandlePrivateMessagesProperly()0%110100%
HandleChatControllerProperly()0%110100%
HandleMouseCatcherProperly()0%110100%
SendChatMessageProperly()0%550100%
CloseWhenButtonPressed()0%110100%
KeepWhisperCommandAfterUsage()0%660100%
WhisperLastPrivateMessageSenderOnReply()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/Tests/WorldChatWindowHUDShould.cs

#LineLine coverage
 1using DCL.Interface;
 2using NUnit.Framework;
 3using System.Collections;
 4using UnityEngine;
 5using UnityEngine.TestTools;
 6
 7public 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
 717    protected override bool justSceneSetUp => true;
 18
 19    protected override IEnumerator SetUp()
 20    {
 721        yield return base.SetUp();
 22
 723        UserProfileController.i.ClearProfilesCatalog();
 24
 725        var ownProfile = UserProfile.GetOwnUserProfile();
 26
 727        ownProfileModel = new UserProfileModel();
 728        ownProfileModel.userId = "my-user-id";
 729        ownProfileModel.name = "NO_USER";
 730        ownProfile.UpdateData(ownProfileModel, false);
 31
 732        testProfileModel = new UserProfileModel();
 733        testProfileModel.userId = "my-user-id-2";
 734        testProfileModel.name = "TEST_USER";
 735        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.
 739        UserProfileController.i.AddUserProfileToCatalog(ownProfileModel);
 40
 741        controller = new WorldChatWindowHUDController();
 742        chatController = new ChatController_Mock();
 743        mouseCatcher = new MouseCatcher_Mock();
 44
 745        controller.Initialize(chatController, mouseCatcher);
 746        this.view = controller.view;
 47
 748        Assert.IsTrue(view != null, "World chat hud view is null?");
 749        Assert.IsTrue(controller != null, "World chat hud controller is null?");
 750    }
 51
 52    protected override IEnumerator TearDown()
 53    {
 754        controller.Dispose();
 755        yield return base.TearDown();
 756    }
 57
 58    [Test]
 59    public void HandlePrivateMessagesProperly()
 60    {
 161        var sentPM = new ChatMessage()
 62        {
 63            messageType = ChatMessage.Type.PRIVATE,
 64            body = "test message",
 65            sender = ownProfileModel.userId,
 66            recipient = testProfileModel.userId
 67        };
 68
 169        chatController.RaiseAddMessage(sentPM);
 70
 171        Assert.AreEqual(1, controller.view.chatHudView.entries.Count);
 72
 173        ChatEntry entry = controller.view.chatHudView.entries[0];
 74
 175        Assert.AreEqual("<b>To TEST_USER:</b>", entry.username.text);
 176        Assert.AreEqual("<b>To TEST_USER:</b> test message", entry.body.text);
 77
 178        var receivedPM = new ChatMessage()
 79        {
 80            messageType = ChatMessage.Type.PRIVATE,
 81            body = "test message",
 82            sender = testProfileModel.userId,
 83            recipient = ownProfileModel.userId
 84        };
 85
 186        chatController.RaiseAddMessage(receivedPM);
 87
 188        ChatEntry entry2 = controller.view.chatHudView.entries[1];
 89
 190        Assert.AreEqual("<b>From TEST_USER:</b>", entry2.username.text);
 191        Assert.AreEqual("<b>From TEST_USER:</b> test message", entry2.body.text);
 192    }
 93
 94    [Test]
 95    public void HandleChatControllerProperly()
 96    {
 197        var chatMessage = new ChatMessage()
 98        {
 99            messageType = ChatMessage.Type.PUBLIC,
 100            body = "test message",
 101            sender = testProfileModel.userId
 102        };
 103
 1104        chatController.RaiseAddMessage(chatMessage);
 105
 1106        Assert.AreEqual(1, controller.view.chatHudView.entries.Count);
 107
 1108        var entry = controller.view.chatHudView.entries[0];
 109
 1110        var chatEntryModel = ChatHUDController.ChatMessageToChatEntry(chatMessage);
 111
 1112        Assert.AreEqual(entry.model, chatEntryModel);
 1113    }
 114
 115    [Test]
 116    public void HandleMouseCatcherProperly()
 117    {
 1118        mouseCatcher.RaiseMouseLock();
 1119        Assert.AreEqual(0, view.group.alpha);
 1120    }
 121
 122    [UnityTest]
 123    public IEnumerator SendChatMessageProperly()
 124    {
 1125        bool messageWasSent = false;
 126
 1127        System.Action<string, string> messageCallback =
 128            (type, msg) =>
 129            {
 1130                if (type == "SendChatMessage" && msg.Contains("test message"))
 131                {
 1132                    messageWasSent = true;
 133                }
 1134            };
 135
 1136        WebInterface.OnMessageFromEngine += messageCallback;
 1137        controller.resetInputFieldOnSubmit = false;
 1138        controller.SendChatMessage(new ChatMessage() { body = "test message" });
 1139        Assert.IsTrue(messageWasSent);
 1140        WebInterface.OnMessageFromEngine -= messageCallback;
 1141        yield return null;
 1142        yield return null;
 1143        yield return null;
 1144        yield break;
 145    }
 146
 147    [Test]
 148    public void CloseWhenButtonPressed()
 149    {
 1150        controller.SetVisibility(true);
 1151        Assert.AreEqual(true, controller.view.gameObject.activeSelf);
 1152        controller.view.closeButton.onClick.Invoke();
 1153        Assert.AreEqual(false, controller.view.gameObject.activeSelf);
 1154    }
 155
 156    [UnityTest]
 157    public IEnumerator KeepWhisperCommandAfterUsage()
 158    {
 1159        string baseCommand = "/w testUser ";
 160
 1161        controller.resetInputFieldOnSubmit = false;
 162
 1163        controller.view.chatHudView.inputField.text = baseCommand + "testMessage";
 1164        yield return null;
 165
 1166        controller.view.chatHudView.inputField.onSubmit.Invoke(controller.view.chatHudView.inputField.text);
 167
 1168        yield return null;
 169
 1170        Assert.AreEqual(baseCommand, controller.view.chatHudView.inputField.text);
 171
 1172        baseCommand = "/w testUser ";
 173
 1174        controller.view.chatHudView.inputField.text = baseCommand + "testMessage";
 1175        yield return null;
 176
 1177        controller.view.chatHudView.inputField.onSubmit.Invoke(controller.view.chatHudView.inputField.text);
 178
 1179        yield return null;
 180
 1181        Assert.AreEqual(baseCommand, controller.view.chatHudView.inputField.text);
 1182        yield break;
 183    }
 184
 185    [UnityTest]
 186    public IEnumerator WhisperLastPrivateMessageSenderOnReply()
 187    {
 1188        UserProfile ownProfile = UserProfile.GetOwnUserProfile();
 189
 1190        var model = new UserProfileModel()
 191        {
 192            userId = "testUserId",
 193            name = "testUserName",
 194        };
 195
 1196        UserProfileController.i.AddUserProfileToCatalog(model);
 197
 1198        var msg = new ChatMessage()
 199        {
 200            body = "test message",
 201            sender = model.userId,
 202            recipient = ownProfile.userId,
 203            messageType = ChatMessage.Type.PRIVATE
 204        };
 205
 1206        yield return null;
 207
 1208        chatController.AddMessageToChatWindow(JsonUtility.ToJson(msg));
 209
 1210        yield return null;
 211
 1212        Assert.AreEqual(controller.lastPrivateMessageReceivedSender, model.name);
 213
 1214        controller.view.chatHudView.inputField.text = "/r ";
 215
 1216        Assert.AreEqual($"/w {model.name} ", controller.view.chatHudView.inputField.text);
 217
 1218        yield return null;
 219
 1220        yield break;
 221    }
 222}