1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 01:47:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs

93 lines
3.6 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 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.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneMessageNotifier : OsuTestScene
{
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);
}
[Test]
public void TestPrivateMessageNotification()
{
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);
}
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()
{
AddRange(new Drawable[] { ChannelManager, NotificationOverlay });
((BindableList<Channel>)ChannelManager.AvailableChannels).AddRange(channels);
AddRange(new Drawable[] { ChatOverlay, MessageNotifier });
((BindableList<Channel>)ChannelManager.JoinedChannels).AddRange(channels);
}
}
}
}