2019-01-24 16:43:03 +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.
|
2018-12-20 15:50:38 +08:00
|
|
|
|
2018-12-20 17:21:37 +08:00
|
|
|
using osu.Framework.Allocation;
|
2018-12-20 15:50:38 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
2019-10-22 06:37:30 +08:00
|
|
|
using System;
|
2019-10-29 13:32:38 +08:00
|
|
|
using System.Linq;
|
2021-02-01 04:44:27 +08:00
|
|
|
using NUnit.Framework;
|
2019-10-29 13:32:38 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-10-29 14:27:08 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2019-10-29 13:32:38 +08:00
|
|
|
using osu.Game.Overlays.Chat;
|
2018-12-20 15:50:38 +08:00
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Online
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
2019-05-15 03:37:25 +08:00
|
|
|
public class TestSceneStandAloneChatDisplay : OsuTestScene
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
|
|
|
private readonly User admin = new User
|
|
|
|
{
|
|
|
|
Username = "HappyStick",
|
|
|
|
Id = 2,
|
|
|
|
Colour = "f2ca34"
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly User redUser = new User
|
|
|
|
{
|
|
|
|
Username = "BanchoBot",
|
|
|
|
Id = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly User blueUser = new User
|
|
|
|
{
|
|
|
|
Username = "Zallius",
|
|
|
|
Id = 4,
|
|
|
|
};
|
|
|
|
|
2019-10-01 21:47:53 +08:00
|
|
|
private readonly User longUsernameUser = new User
|
|
|
|
{
|
|
|
|
Username = "Very Long Long Username",
|
|
|
|
Id = 5,
|
|
|
|
};
|
|
|
|
|
2018-12-20 17:21:37 +08:00
|
|
|
[Cached]
|
|
|
|
private ChannelManager channelManager = new ChannelManager();
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
private TestStandAloneChatDisplay chatDisplay;
|
|
|
|
private int messageIdSequence;
|
|
|
|
|
|
|
|
private Channel testChannel;
|
2018-12-20 17:21:37 +08:00
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
public TestSceneStandAloneChatDisplay()
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
2018-12-20 17:21:37 +08:00
|
|
|
Add(channelManager);
|
2018-12-20 15:50:38 +08:00
|
|
|
}
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp() => Schedule(() =>
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
2021-02-01 04:44:27 +08:00
|
|
|
messageIdSequence = 0;
|
|
|
|
channelManager.CurrentChannel.Value = testChannel = new Channel();
|
2018-12-20 17:21:37 +08:00
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
chatDisplay = new TestStandAloneChatDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
Size = new Vector2(400, 80),
|
|
|
|
Channel = { Value = testChannel },
|
|
|
|
},
|
2021-02-02 03:38:42 +08:00
|
|
|
new TestStandAloneChatDisplay(true)
|
2021-02-01 04:44:27 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
Size = new Vector2(400, 150),
|
|
|
|
Channel = { Value = testChannel },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2018-12-21 16:54:12 +08:00
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
[Test]
|
|
|
|
public void TestManyMessages()
|
|
|
|
{
|
|
|
|
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
|
|
|
Sender = admin,
|
|
|
|
Content = "I am a wang!"
|
|
|
|
}));
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
|
|
|
Sender = redUser,
|
|
|
|
Content = "I am team red."
|
|
|
|
}));
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
|
|
|
Sender = redUser,
|
|
|
|
Content = "I plan to win!"
|
|
|
|
}));
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
|
|
|
Sender = blueUser,
|
|
|
|
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
|
|
|
}));
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2018-12-20 15:50:38 +08:00
|
|
|
{
|
|
|
|
Sender = admin,
|
|
|
|
Content = "Okay okay, calm down guys. Let's do this!"
|
|
|
|
}));
|
2019-10-01 21:47:53 +08:00
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
AddStep("message from long username", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2019-10-01 21:47:53 +08:00
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Hi guys, my new username is lit!"
|
|
|
|
}));
|
2019-10-22 06:37:30 +08:00
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
AddStep("message with new date", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2019-10-22 06:37:30 +08:00
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Message from the future!",
|
|
|
|
Timestamp = DateTimeOffset.Now
|
|
|
|
}));
|
2019-10-29 13:32:38 +08:00
|
|
|
|
|
|
|
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
|
|
|
|
const int messages_per_call = 10;
|
|
|
|
AddRepeatStep("add many messages", () =>
|
2020-02-15 10:54:29 +08:00
|
|
|
{
|
|
|
|
for (int i = 0; i < messages_per_call; i++)
|
2019-10-29 13:32:38 +08:00
|
|
|
{
|
2021-02-01 04:44:27 +08:00
|
|
|
testChannel.AddNewMessages(new Message(messageIdSequence++)
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2020-02-15 10:54:29 +08:00
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Many messages! " + Guid.NewGuid(),
|
|
|
|
Timestamp = DateTimeOffset.Now
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, Channel.MAX_HISTORY / messages_per_call + 5);
|
2019-10-29 13:32:38 +08:00
|
|
|
|
2019-10-29 14:27:08 +08:00
|
|
|
AddAssert("Ensure no adjacent day separators", () =>
|
|
|
|
{
|
|
|
|
var indices = chatDisplay.FillFlow.OfType<DrawableChannel.DaySeparator>().Select(ds => chatDisplay.FillFlow.IndexOf(ds));
|
|
|
|
|
|
|
|
foreach (var i in indices)
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2019-10-29 14:27:08 +08:00
|
|
|
if (i < chatDisplay.FillFlow.Count && chatDisplay.FillFlow[i + 1] is DrawableChannel.DaySeparator)
|
|
|
|
return false;
|
2019-11-11 19:53:22 +08:00
|
|
|
}
|
2019-10-29 14:27:08 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2019-10-29 13:32:38 +08:00
|
|
|
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
}
|
|
|
|
|
2021-02-01 04:44:27 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Tests that when a message gets wrapped by the chat display getting contracted while scrolled to bottom, the chat will still keep scrolling down.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestMessageWrappingKeepsAutoScrolling()
|
|
|
|
{
|
|
|
|
AddStep("fill chat", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
testChannel.AddNewMessages(new Message(messageIdSequence++)
|
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = $"some stuff {Guid.NewGuid()}",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("ensure scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
|
|
|
|
// send message with short words for text wrapping to occur when contracting chat.
|
|
|
|
AddStep("send lorem ipsum", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et bibendum velit.",
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddStep("contract chat", () => chatDisplay.Width -= 100);
|
|
|
|
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
|
|
|
|
AddStep("send another message", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
|
|
|
|
{
|
|
|
|
Sender = admin,
|
|
|
|
Content = "As we were saying...",
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
}
|
|
|
|
|
2019-10-29 13:32:38 +08:00
|
|
|
private class TestStandAloneChatDisplay : StandAloneChatDisplay
|
|
|
|
{
|
|
|
|
public TestStandAloneChatDisplay(bool textbox = false)
|
|
|
|
: base(textbox)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:27:08 +08:00
|
|
|
protected DrawableChannel DrawableChannel => InternalChildren.OfType<DrawableChannel>().First();
|
|
|
|
|
2021-02-02 14:16:10 +08:00
|
|
|
protected UserTrackingScrollContainer ScrollContainer => (UserTrackingScrollContainer)((Container)DrawableChannel.Child).Child;
|
2019-10-29 14:27:08 +08:00
|
|
|
|
|
|
|
public FillFlowContainer FillFlow => (FillFlowContainer)ScrollContainer.Child;
|
|
|
|
|
|
|
|
public bool ScrolledToBottom => ScrollContainer.IsScrolledToEnd(1);
|
2018-12-20 15:50:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|