1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 23:27:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs

118 lines
5.0 KiB
C#
Raw Normal View History

2020-01-29 09:18:46 +08:00
// 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.
using System.Linq;
2020-01-29 09:18:46 +08:00
using NUnit.Framework;
2020-01-29 09:06:10 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
2020-01-29 09:06:10 +08:00
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
2020-01-29 09:06:10 +08:00
using osu.Game.Users;
using osuTK.Input;
2020-01-29 09:06:10 +08:00
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneMessageNotifier : ManualInputManagerTestScene
2020-01-29 09:06:10 +08:00
{
private User friend;
private Channel publicChannel;
private Channel privateMessageChannel;
2020-01-29 09:06:10 +08:00
private TestContainer testContainer;
private int messageIdCounter;
[SetUp]
public void Setup()
{
2020-01-30 10:41:21 +08:00
friend = new User { Id = 0, Username = "Friend" };
publicChannel = new Channel { Id = 1, Name = "osu" };
2020-02-04 05:19:55 +08:00
privateMessageChannel = new Channel(friend) { Id = 2, Name = friend.Username, Type = ChannelType.PM };
2020-01-29 09:06:10 +08:00
2020-01-30 12:24:26 +08:00
Schedule(() =>
2020-01-29 09:06:10 +08:00
{
2020-02-04 05:19:55 +08:00
Child = testContainer = new TestContainer(new[] { publicChannel, privateMessageChannel })
2020-01-30 12:24:26 +08:00
{
RelativeSizeAxes = Axes.Both,
};
2020-01-29 09:06:10 +08:00
2020-01-30 12:24:26 +08:00
testContainer.ChatOverlay.Show();
});
2020-01-29 09:06:10 +08:00
}
[Test]
public void TestPublicChannelMention()
{
2020-02-04 05:19:55 +08:00
AddStep("Switch to PMs", () => testContainer.ChannelManager.CurrentChannel.Value = privateMessageChannel);
2020-01-29 09:06:10 +08:00
2020-01-29 09:13:32 +08:00
AddStep("Send regular message", () => publicChannel.AddNewMessages(new Message(messageIdCounter++) { Content = "Hello everyone!", Sender = friend, ChannelId = publicChannel.Id }));
2020-01-29 09:06:10 +08:00
AddAssert("Expect no notifications", () => testContainer.NotificationOverlay.UnreadCount.Value == 0);
2020-01-29 09:13:32 +08:00
AddStep("Send message containing mention", () => publicChannel.AddNewMessages(new Message(messageIdCounter++) { Content = $"Hello {API.LocalUser.Value.Username.ToLowerInvariant()}!", Sender = friend, ChannelId = publicChannel.Id }));
2020-01-29 09:06:10 +08:00
AddAssert("Expect 1 notification", () => testContainer.NotificationOverlay.UnreadCount.Value == 1);
AddStep("Open notification overlay", () => testContainer.NotificationOverlay.Show());
AddStep("Click notification", clickNotification<MessageNotifier.MentionNotification>);
AddAssert("Expect ChatOverlay is open", () => testContainer.ChatOverlay.State.Value == Visibility.Visible);
AddAssert("Expect the public channel to be selected", () => testContainer.ChannelManager.CurrentChannel.Value == publicChannel);
2020-01-29 09:06:10 +08:00
}
[Test]
public void TestPrivateMessageNotification()
{
AddStep("Switch to public channel", () => testContainer.ChannelManager.CurrentChannel.Value = publicChannel);
2020-02-04 05:19:55 +08:00
AddStep("Send PM", () => privateMessageChannel.AddNewMessages(new Message(messageIdCounter++) { Content = $"Hello {API.LocalUser.Value.Username}!", Sender = friend, ChannelId = privateMessageChannel.Id }));
2020-01-29 09:06:10 +08:00
AddAssert("Expect 1 notification", () => testContainer.NotificationOverlay.UnreadCount.Value == 1);
AddStep("Open notification overlay", () => testContainer.NotificationOverlay.Show());
AddStep("Click notification", clickNotification<MessageNotifier.PrivateMessageNotification>);
AddAssert("Expect ChatOverlay is open", () => testContainer.ChatOverlay.State.Value == Visibility.Visible);
AddAssert("Expect the PM channel to be selected", () => testContainer.ChannelManager.CurrentChannel.Value == privateMessageChannel);
}
private void clickNotification<T>() where T : Notification
{
var notification = testContainer.NotificationOverlay.ChildrenOfType<T>().Single();
InputManager.MoveMouseTo(notification);
InputManager.Click(MouseButton.Left);
2020-01-29 09:06:10 +08:00
}
private class TestContainer : Container
{
2020-01-30 10:41:21 +08:00
private readonly Channel[] channels;
2020-01-29 09:06:10 +08:00
public TestContainer(Channel[] channels) => this.channels = channels;
[Cached]
public ChannelManager ChannelManager { get; } = new ChannelManager();
[Cached]
public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay();
[Cached]
public MessageNotifier MessageNotifier { get; } = new MessageNotifier();
[Cached]
public ChatOverlay ChatOverlay { get; } = new ChatOverlay();
[BackgroundDependencyLoader]
private void load()
{
2020-02-04 06:00:29 +08:00
AddRange(new Drawable[] { ChannelManager, ChatOverlay, NotificationOverlay, MessageNotifier });
2020-01-29 09:06:10 +08:00
((BindableList<Channel>)ChannelManager.AvailableChannels).AddRange(channels);
2020-02-04 06:05:46 +08:00
foreach (var channel in channels)
ChannelManager.JoinChannel(channel);
2020-01-29 09:06:10 +08:00
}
}
}
}