1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 19:07:25 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneDrawableChannel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

151 lines
5.5 KiB
C#
Raw Normal View History

// 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.
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat;
namespace osu.Game.Tests.Visual.Online
{
[TestFixture]
public partial class TestSceneDrawableChannel : OsuTestScene
{
private Channel channel = null!;
private DrawableChannel drawableChannel = null!;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create channel", () => channel = new Channel
{
Id = 1,
Name = "Test channel"
});
AddStep("create drawable channel", () => Child = drawableChannel = new DrawableChannel(channel)
{
RelativeSizeAxes = Axes.Both
});
}
2024-08-07 00:33:54 +08:00
[Test]
public void TestMention()
{
AddStep("add normal message", () => channel.AddNewMessages(
new Message(1)
{
Sender = new APIUser
{
Id = 2,
Username = "TestUser2"
},
Content = "Hello how are you today?",
Timestamp = new DateTimeOffset(2021, 12, 11, 13, 33, 24, TimeSpan.Zero)
}));
AddStep("add mention", () => channel.AddNewMessages(
new Message(2)
{
Sender = new APIUser
{
Id = 2,
Username = "TestUser2"
},
Content = $"Hello {API.LocalUser.Value.Username} how are you today?",
Timestamp = new DateTimeOffset(2021, 12, 11, 13, 33, 25, TimeSpan.Zero)
}));
}
[Test]
public void TestDaySeparators()
{
var localUser = new APIUser
{
Id = 3,
Username = "LocalUser"
};
2024-07-27 18:48:45 +08:00
string uuid = Guid.NewGuid().ToString();
AddStep("add local echo message", () => channel.AddLocalEcho(new LocalEchoMessage
{
Sender = localUser,
Content = "Hi there all!",
Timestamp = new DateTimeOffset(2022, 11, 21, 20, 11, 13, TimeSpan.Zero),
Uuid = uuid
}));
AddUntilStep("one day separator present", () => drawableChannel.ChildrenOfType<DaySeparator>().Count() == 1);
AddStep("add two prior messages to channel", () => channel.AddNewMessages(
new Message(1)
{
Sender = new APIUser
{
Id = 1,
Username = "TestUser"
},
Content = "This is a message",
Timestamp = new DateTimeOffset(2021, 10, 10, 13, 33, 23, TimeSpan.Zero),
},
new Message(2)
{
Sender = new APIUser
{
Id = 2,
Username = "TestUser2"
},
Content = "This is another message",
Timestamp = new DateTimeOffset(2021, 10, 11, 13, 33, 23, TimeSpan.Zero)
}));
AddUntilStep("three day separators present", () => drawableChannel.ChildrenOfType<DaySeparator>().Count() == 3);
AddStep("resolve pending message", () => channel.ReplaceMessage(channel.Messages.OfType<LocalEchoMessage>().Single(), new Message(3)
{
Sender = localUser,
Content = "Hi there all!",
Timestamp = new DateTimeOffset(2022, 11, 22, 20, 11, 16, TimeSpan.Zero),
Uuid = uuid
}));
AddUntilStep("three day separators present", () => drawableChannel.ChildrenOfType<DaySeparator>().Count() == 3);
AddAssert("last day separator is from correct day", () => drawableChannel.ChildrenOfType<DaySeparator>().Last().Date.Date == new DateTime(2022, 11, 22));
}
2024-07-27 18:24:32 +08:00
[Test]
2024-07-29 21:19:38 +08:00
public void TestBackgroundAlternating()
2024-07-27 18:24:32 +08:00
{
int messageCount = 1;
2024-07-27 18:48:45 +08:00
AddRepeatStep("add messages", () =>
2024-07-27 18:24:32 +08:00
{
channel.AddNewMessages(new Message(messageCount)
{
Sender = new APIUser
{
Id = 3,
Username = "LocalUser " + RNG.Next(0, int.MaxValue - 100).ToString("N")
},
2024-07-27 18:24:32 +08:00
Content = "Hi there all!",
2024-07-28 15:08:36 +08:00
Timestamp = new DateTimeOffset(2022, 11, 21, 20, messageCount, 13, TimeSpan.Zero),
Uuid = Guid.NewGuid().ToString(),
2024-07-27 18:24:32 +08:00
});
messageCount++;
}, 10);
AddUntilStep("10 message present", () => drawableChannel.ChildrenOfType<ChatLine>().Count() == 10);
int checkCount = 0;
AddRepeatStep("check background", () =>
{
// +1 because the day separator take one index
2024-07-29 19:16:41 +08:00
Assert.AreEqual((checkCount + 1) % 2 == 0, drawableChannel.ChildrenOfType<ChatLine>().ToList()[checkCount].AlternatingBackground);
2024-07-27 18:24:32 +08:00
checkCount++;
}, 10);
}
}
}