mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Use test scenes
This commit is contained in:
99
osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs
Normal file
99
osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using NUnit.Framework;
|
||||
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 privateMesssageChannel;
|
||||
private TestContainer testContainer;
|
||||
|
||||
private int messageIdCounter;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
friend = new User() { Id = 0, Username = "Friend" };
|
||||
publicChannel = new Channel() { Id = 1, Name = "osu" };
|
||||
privateMesssageChannel = new Channel(friend) { Id = 2, Name = friend.Username, Type = ChannelType.PM };
|
||||
|
||||
Child = testContainer = new TestContainer(new Channel[] { publicChannel, privateMesssageChannel })
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
|
||||
testContainer.ChatOverlay.Show();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPublicChannelMention()
|
||||
{
|
||||
AddStep("Switch to PMs", () => testContainer.ChannelManager.CurrentChannel.Value = privateMesssageChannel);
|
||||
|
||||
AddStep("Send regular message", () => publicChannel.AddNewMessages(new Message(messageIdCounter++) {
|
||||
Content = "Hello everyone!",
|
||||
Sender = friend,
|
||||
ChannelId = publicChannel.Id
|
||||
}));
|
||||
AddAssert("Expect no notifications", () => testContainer.NotificationOverlay.UnreadCount.Value == 0);
|
||||
|
||||
AddStep("Send message containing mention", () => publicChannel.AddNewMessages(new Message(messageIdCounter++) {
|
||||
Content = $"Hello {API.LocalUser.Value.Username.ToLowerInvariant()}!",
|
||||
Sender = friend,
|
||||
ChannelId = publicChannel.Id
|
||||
}));
|
||||
AddAssert("Expect 1 notification", () => testContainer.NotificationOverlay.UnreadCount.Value == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrivateMessageNotification()
|
||||
{
|
||||
AddStep("Send PM", () => privateMesssageChannel.AddNewMessages(new Message(messageIdCounter++)
|
||||
{
|
||||
Content = $"Hello {API.LocalUser.Value.Username}!",
|
||||
Sender = friend,
|
||||
ChannelId = privateMesssageChannel.Id
|
||||
}));
|
||||
AddAssert("Expect 1 notification", () => testContainer.NotificationOverlay.UnreadCount.Value == 1);
|
||||
}
|
||||
|
||||
private class TestContainer : Container
|
||||
{
|
||||
private Channel[] channels;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user