Add test for scroll to end when max history is exceeded

This commit is contained in:
Dean Herbert 2019-10-29 14:32:38 +09:00
parent 34aa0b14a4
commit d1c6e3f620
3 changed files with 38 additions and 11 deletions

View File

@ -7,6 +7,9 @@ using osu.Game.Online.Chat;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
using System; using System;
using System.Linq;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays.Chat;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -42,14 +45,14 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
private ChannelManager channelManager = new ChannelManager(); private ChannelManager channelManager = new ChannelManager();
private readonly StandAloneChatDisplay chatDisplay; private readonly TestStandAloneChatDisplay chatDisplay;
private readonly StandAloneChatDisplay chatDisplay2; private readonly TestStandAloneChatDisplay chatDisplay2;
public TestSceneStandAloneChatDisplay() public TestSceneStandAloneChatDisplay()
{ {
Add(channelManager); Add(channelManager);
Add(chatDisplay = new StandAloneChatDisplay Add(chatDisplay = new TestStandAloneChatDisplay
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
@ -57,7 +60,7 @@ namespace osu.Game.Tests.Visual.Online
Size = new Vector2(400, 80) Size = new Vector2(400, 80)
}); });
Add(chatDisplay2 = new StandAloneChatDisplay(true) Add(chatDisplay2 = new TestStandAloneChatDisplay(true)
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
@ -119,6 +122,32 @@ namespace osu.Game.Tests.Visual.Online
Content = "Message from the future!", Content = "Message from the future!",
Timestamp = DateTimeOffset.Now Timestamp = DateTimeOffset.Now
})); }));
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
const int messages_per_call = 10;
AddRepeatStep("add many messages", () =>
{
for (int i = 0; i < messages_per_call; i++)
testChannel.AddNewMessages(new Message(sequence++)
{
Sender = longUsernameUser,
Content = "Many messages! " + Guid.NewGuid(),
Timestamp = DateTimeOffset.Now
});
}, Channel.MAX_HISTORY / messages_per_call + 5);
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
}
private class TestStandAloneChatDisplay : StandAloneChatDisplay
{
public TestStandAloneChatDisplay(bool textbox = false)
: base(textbox)
{
}
public bool ScrolledToBottom => ((ScrollContainer<Drawable>)((Container)InternalChildren.OfType<DrawableChannel>().First().Child).Child).IsScrolledToEnd(1);
} }
} }
} }

View File

@ -14,7 +14,7 @@ namespace osu.Game.Online.Chat
{ {
public class Channel public class Channel
{ {
public readonly int MaxHistory = 300; public const int MAX_HISTORY = 300;
/// <summary> /// <summary>
/// Contains every joined user except the current logged in user. Currently only returned for PM channels. /// Contains every joined user except the current logged in user. Currently only returned for PM channels.
@ -80,8 +80,6 @@ namespace osu.Game.Online.Chat
/// </summary> /// </summary>
public Bindable<bool> Joined = new Bindable<bool>(); public Bindable<bool> Joined = new Bindable<bool>();
public const int MAX_HISTORY = 300;
[JsonConstructor] [JsonConstructor]
public Channel() public Channel()
{ {
@ -162,8 +160,8 @@ namespace osu.Game.Online.Chat
{ {
// never purge local echos // never purge local echos
int messageCount = Messages.Count - pendingMessages.Count; int messageCount = Messages.Count - pendingMessages.Count;
if (messageCount > MaxHistory) if (messageCount > MAX_HISTORY)
Messages.RemoveRange(0, messageCount - MaxHistory); Messages.RemoveRange(0, messageCount - MAX_HISTORY);
} }
} }
} }

View File

@ -1,4 +1,4 @@
// 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; using System;
@ -107,7 +107,7 @@ namespace osu.Game.Overlays.Chat
scrollToEnd(); scrollToEnd();
var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray();
int count = staleMessages.Length - Channel.MaxHistory; int count = staleMessages.Length - Channel.MAX_HISTORY;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {