mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 15:33:05 +08:00
Add test for ChannelManager.MarkChannelAsRead
This commit is contained in:
parent
7d6f7ac75e
commit
2f9f1ba862
@ -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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -19,6 +20,7 @@ namespace osu.Game.Tests.Chat
|
|||||||
{
|
{
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
private int currentMessageId;
|
private int currentMessageId;
|
||||||
|
List<Message> sentMessages;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup() => Schedule(() =>
|
public void Setup() => Schedule(() =>
|
||||||
@ -34,6 +36,7 @@ namespace osu.Game.Tests.Chat
|
|||||||
AddStep("register request handling", () =>
|
AddStep("register request handling", () =>
|
||||||
{
|
{
|
||||||
currentMessageId = 0;
|
currentMessageId = 0;
|
||||||
|
sentMessages = new List<Message>();
|
||||||
|
|
||||||
((DummyAPIAccess)API).HandleRequest = req =>
|
((DummyAPIAccess)API).HandleRequest = req =>
|
||||||
{
|
{
|
||||||
@ -44,7 +47,7 @@ namespace osu.Game.Tests.Chat
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case PostMessageRequest postMessage:
|
case PostMessageRequest postMessage:
|
||||||
postMessage.TriggerSuccess(new Message(++currentMessageId)
|
var message = new Message(++currentMessageId)
|
||||||
{
|
{
|
||||||
IsAction = postMessage.Message.IsAction,
|
IsAction = postMessage.Message.IsAction,
|
||||||
ChannelId = postMessage.Message.ChannelId,
|
ChannelId = postMessage.Message.ChannelId,
|
||||||
@ -52,7 +55,10 @@ namespace osu.Game.Tests.Chat
|
|||||||
Links = postMessage.Message.Links,
|
Links = postMessage.Message.Links,
|
||||||
Timestamp = postMessage.Message.Timestamp,
|
Timestamp = postMessage.Message.Timestamp,
|
||||||
Sender = postMessage.Message.Sender
|
Sender = postMessage.Message.Sender
|
||||||
});
|
};
|
||||||
|
|
||||||
|
sentMessages.Add(message);
|
||||||
|
postMessage.TriggerSuccess(message);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -83,12 +89,59 @@ namespace osu.Game.Tests.Chat
|
|||||||
AddAssert("/np command received by channel 2", () => channel2.Messages.Last().Content.Contains("is listening to"));
|
AddAssert("/np command received by channel 2", () => channel2.Messages.Last().Content.Contains("is listening to"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMarkAsReadIgnoringLocalMessages() {
|
||||||
|
Channel channel = null;
|
||||||
|
|
||||||
|
AddStep("join channel and select it", () =>
|
||||||
|
{
|
||||||
|
channelManager.JoinChannel(channel = createChannel(1, ChannelType.Public));
|
||||||
|
|
||||||
|
channelManager.CurrentChannel.Value = channel;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("post message", () => channelManager.PostMessage("Something interesting"));
|
||||||
|
AddUntilStep("wait until the message is posted", () => channel.Messages.Count == sentMessages.Count);
|
||||||
|
|
||||||
|
AddStep("post /help command", () => channelManager.PostCommand("help", channel));
|
||||||
|
AddStep("post /me command with no action", () => channelManager.PostCommand("me", channel));
|
||||||
|
AddStep("post /join command with no channel", () => channelManager.PostCommand("join", channel));
|
||||||
|
AddStep("post /join command with non-existent channel", () => channelManager.PostCommand("join i-dont-exist", channel));
|
||||||
|
AddStep("post non-existent command", () => channelManager.PostCommand("non-existent-cmd arg", channel));
|
||||||
|
|
||||||
|
AddStep("register mark channel as read request handler", () => {
|
||||||
|
((DummyAPIAccess)API).HandleRequest = req =>
|
||||||
|
{
|
||||||
|
switch (req)
|
||||||
|
{
|
||||||
|
case MarkChannelAsReadRequest markRead:
|
||||||
|
var isSentMessage = sentMessages.Contains(markRead.Message);
|
||||||
|
|
||||||
|
AddAssert("mark channel as read called with a real message", () => isSentMessage);
|
||||||
|
|
||||||
|
if(isSentMessage) {
|
||||||
|
markRead.TriggerSuccess();
|
||||||
|
} else {
|
||||||
|
markRead.TriggerFailure(new APIException("unknown message!", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("mark channel as read", () => channelManager.MarkChannelAsRead(channel));
|
||||||
|
}
|
||||||
|
|
||||||
private Channel createChannel(int id, ChannelType type) => new Channel(new User())
|
private Channel createChannel(int id, ChannelType type) => new Channel(new User())
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = $"Channel {id}",
|
Name = $"Channel {id}",
|
||||||
Topic = $"Topic of channel {id} with type {type}",
|
Topic = $"Topic of channel {id} with type {type}",
|
||||||
Type = type,
|
Type = type,
|
||||||
|
LastMessageId = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
private class ChannelManagerContainer : CompositeDrawable
|
private class ChannelManagerContainer : CompositeDrawable
|
||||||
|
@ -9,16 +9,16 @@ namespace osu.Game.Online.API.Requests
|
|||||||
{
|
{
|
||||||
public class MarkChannelAsReadRequest : APIRequest
|
public class MarkChannelAsReadRequest : APIRequest
|
||||||
{
|
{
|
||||||
private readonly Channel channel;
|
public readonly Channel Channel;
|
||||||
private readonly Message message;
|
public readonly Message Message;
|
||||||
|
|
||||||
public MarkChannelAsReadRequest(Channel channel, Message message)
|
public MarkChannelAsReadRequest(Channel channel, Message message)
|
||||||
{
|
{
|
||||||
this.channel = channel;
|
this.Channel = channel;
|
||||||
this.message = message;
|
this.Message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => $"chat/channels/{channel.Id}/mark-as-read/{message.Id}";
|
protected override string Target => $"chat/channels/{Channel.Id}/mark-as-read/{Message.Id}";
|
||||||
|
|
||||||
protected override WebRequest CreateWebRequest()
|
protected override WebRequest CreateWebRequest()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user