mirror of https://github.com/ppy/osu
Add test for removing chat messages
This commit is contained in:
parent
695104a666
commit
f688ed12d0
|
@ -40,6 +40,7 @@ public class TestSceneChatOverlay : OsuManualInputManagerTestScene
|
|||
private ChannelManager channelManager;
|
||||
|
||||
private readonly APIUser testUser = new APIUser { Username = "test user", Id = 5071479 };
|
||||
private readonly APIUser testUser1 = new APIUser { Username = "test user", Id = 5071480 };
|
||||
|
||||
private Channel[] testChannels;
|
||||
private Message[] initialMessages;
|
||||
|
@ -500,6 +501,35 @@ public void TestKeyboardNextChannel()
|
|||
waitForChannel1Visible();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRemoveMessages()
|
||||
{
|
||||
AddStep("Show overlay with channel", () =>
|
||||
{
|
||||
chatOverlay.Show();
|
||||
channelManager.CurrentChannel.Value = channelManager.JoinChannel(testChannel1);
|
||||
});
|
||||
|
||||
AddAssert("Overlay is visible", () => chatOverlay.State.Value == Visibility.Visible);
|
||||
waitForChannel1Visible();
|
||||
|
||||
AddStep("Send message from another user", () =>
|
||||
{
|
||||
testChannel1.AddNewMessages(new Message
|
||||
{
|
||||
ChannelId = testChannel1.Id,
|
||||
Content = "Message from another user",
|
||||
Timestamp = DateTimeOffset.Now,
|
||||
Sender = testUser1,
|
||||
});
|
||||
});
|
||||
|
||||
AddStep("Remove messages from other user", () =>
|
||||
{
|
||||
testChannel1.RemoveMessagesFromUser(testUser.Id);
|
||||
});
|
||||
}
|
||||
|
||||
private void joinTestChannel(int i)
|
||||
{
|
||||
AddStep($"Join test channel {i}", () => channelManager.JoinChannel(testChannels[i]));
|
||||
|
|
|
@ -149,6 +149,20 @@ public void AddNewMessages(params Message[] messages)
|
|||
NewMessagesArrived?.Invoke(messages);
|
||||
}
|
||||
|
||||
public void RemoveMessagesFromUser(int userId)
|
||||
{
|
||||
for (int i = 0; i < Messages.Count; i++)
|
||||
{
|
||||
var message = Messages[i];
|
||||
|
||||
if (message.SenderId == userId)
|
||||
{
|
||||
Messages.RemoveAt(i--);
|
||||
MessageRemoved?.Invoke(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace or remove a message from the channel.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue