1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 16:37:26 +08:00

add tests for /chat command

This commit is contained in:
Davran Dilshat 2021-09-11 16:22:35 +01:00
parent 1b264a2dd0
commit 7924a990a3

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
@ -85,6 +86,21 @@ namespace osu.Game.Tests.Visual.Online
case JoinChannelRequest joinChannel: case JoinChannelRequest joinChannel:
joinChannel.TriggerSuccess(); joinChannel.TriggerSuccess();
return true; return true;
case GetUserRequest getUser:
if (getUser.Lookup.Equals("some body", StringComparison.OrdinalIgnoreCase))
{
getUser.TriggerSuccess(new User()
{
Username = "some body",
Id = 1,
});
}
else
{
getUser.TriggerFailure(new Exception());
}
return true;
} }
return false; return false;
@ -322,6 +338,27 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("Current channel is channel 1", () => currentChannel == channel1); AddAssert("Current channel is channel 1", () => currentChannel == channel1);
} }
[Test]
public void TestChatCommand()
{
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
AddStep("Open chat with user.", () => channelManager.PostCommand("chat some body"));
AddAssert("PM channel is selected", () =>
channelManager.CurrentChannel.Value.Type == ChannelType.PM && channelManager.CurrentChannel.Value.Users.Single().Username == "some body");
AddStep("Open chat with non-existant user", () => channelManager.PostCommand("chat nobody"));
AddAssert("Last message is error", () => channelManager.CurrentChannel.Value.Messages.Last().GetType() == typeof(ErrorMessage));
// Make sure no unnecessary requests are made when the PM chanenl is already open.
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
AddStep("Unregister request handling", () => ((DummyAPIAccess)API).HandleRequest = null);
AddStep("Open chat with user.", () => channelManager.PostCommand("chat some body"));
AddAssert("PM channel is selected", () =>
channelManager.CurrentChannel.Value.Type == ChannelType.PM && channelManager.CurrentChannel.Value.Users.Single().Username == "some body");
}
private void pressChannelHotkey(int number) private void pressChannelHotkey(int number)
{ {
var channelKey = Key.Number0 + number; var channelKey = Key.Number0 + number;