2022-04-15 14:38:47 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2022-04-15 14:38:47 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Chat.ChannelList;
|
2022-05-19 10:26:14 +00:00
|
|
|
using osu.Game.Overlays.Chat.Listing;
|
2022-04-15 14:38:47 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public partial class TestSceneChannelList : OsuTestScene
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Pink);
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
private readonly Bindable<Channel> selected = new Bindable<Channel>();
|
|
|
|
|
|
|
|
private OsuSpriteText selectedText;
|
|
|
|
private OsuSpriteText leaveText;
|
|
|
|
private ChannelList channelList;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
Child = new GridContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Height = 0.7f,
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20),
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20),
|
|
|
|
new Dimension(),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
selectedText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
leaveText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
channelList = new ChannelList
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 190,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
channelList.OnRequestSelect += channel =>
|
|
|
|
{
|
|
|
|
selected.Value = channel;
|
|
|
|
};
|
|
|
|
|
|
|
|
channelList.OnRequestLeave += channel =>
|
|
|
|
{
|
|
|
|
leaveText.Text = $"OnRequestLeave: {channel.Name}";
|
|
|
|
leaveText.FadeOutFromOne(1000, Easing.InQuint);
|
2022-05-27 15:06:23 +00:00
|
|
|
selected.Value = channelList.ChannelListingChannel;
|
2022-04-15 14:38:47 +00:00
|
|
|
channelList.RemoveChannel(channel);
|
|
|
|
};
|
|
|
|
|
|
|
|
selected.BindValueChanged(change =>
|
|
|
|
{
|
|
|
|
selectedText.Text = $"Selected Channel: {change.NewValue?.Name ?? "[null]"}";
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("Add Public Channels", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
channelList.AddChannel(createRandomPublicChannel());
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("Add Private Channels", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
channelList.AddChannel(createRandomPrivateChannel());
|
|
|
|
});
|
2022-05-27 15:06:23 +00:00
|
|
|
|
|
|
|
AddStep("Add Announce Channels", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
channelList.AddChannel(createRandomAnnounceChannel());
|
|
|
|
});
|
2022-04-15 14:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestVisual()
|
|
|
|
{
|
|
|
|
AddStep("Unread Selected", () =>
|
|
|
|
{
|
2022-05-15 18:38:37 +00:00
|
|
|
if (validItem)
|
2022-04-15 14:38:47 +00:00
|
|
|
channelList.GetItem(selected.Value).Unread.Value = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("Read Selected", () =>
|
|
|
|
{
|
2022-05-15 18:38:37 +00:00
|
|
|
if (validItem)
|
2022-04-15 14:38:47 +00:00
|
|
|
channelList.GetItem(selected.Value).Unread.Value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("Add Mention Selected", () =>
|
|
|
|
{
|
2022-05-15 18:38:37 +00:00
|
|
|
if (validItem)
|
2022-04-15 14:38:47 +00:00
|
|
|
channelList.GetItem(selected.Value).Mentions.Value++;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("Add 98 Mentions Selected", () =>
|
|
|
|
{
|
2022-05-15 18:38:37 +00:00
|
|
|
if (validItem)
|
2022-04-15 14:38:47 +00:00
|
|
|
channelList.GetItem(selected.Value).Mentions.Value += 98;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("Clear Mentions Selected", () =>
|
|
|
|
{
|
2022-05-15 18:38:37 +00:00
|
|
|
if (validItem)
|
2022-04-15 14:38:47 +00:00
|
|
|
channelList.GetItem(selected.Value).Mentions.Value = 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-19 10:26:14 +00:00
|
|
|
private bool validItem => selected.Value != null && !(selected.Value is ChannelListing.ChannelListingChannel);
|
2022-05-15 18:38:37 +00:00
|
|
|
|
2022-04-15 14:38:47 +00:00
|
|
|
private Channel createRandomPublicChannel()
|
|
|
|
{
|
|
|
|
int id = RNG.Next(0, 10000);
|
|
|
|
return new Channel
|
|
|
|
{
|
|
|
|
Name = $"#channel-{id}",
|
|
|
|
Type = ChannelType.Public,
|
|
|
|
Id = id,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private Channel createRandomPrivateChannel()
|
|
|
|
{
|
|
|
|
int id = RNG.Next(0, 10000);
|
|
|
|
return new Channel(new APIUser
|
|
|
|
{
|
|
|
|
Id = id,
|
|
|
|
Username = $"test user {id}",
|
|
|
|
});
|
|
|
|
}
|
2022-05-27 15:06:23 +00:00
|
|
|
|
|
|
|
private Channel createRandomAnnounceChannel()
|
|
|
|
{
|
|
|
|
int id = RNG.Next(0, 10000);
|
|
|
|
return new Channel
|
|
|
|
{
|
|
|
|
Name = $"Announce {id}",
|
|
|
|
Type = ChannelType.Announce,
|
|
|
|
Id = id,
|
|
|
|
};
|
|
|
|
}
|
2022-04-15 14:38:47 +00:00
|
|
|
}
|
|
|
|
}
|