1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 19:27:31 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneNewsSideBar.cs

147 lines
4.8 KiB
C#
Raw Normal View History

2021-05-10 14:53:52 +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.
using System;
using System.Collections.Generic;
2021-05-12 01:42:13 +08:00
using System.Linq;
2021-05-10 14:53:52 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
2021-05-12 01:42:13 +08:00
using osu.Framework.Testing;
2021-05-10 14:53:52 +08:00
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.News.Sidebar;
2021-05-17 16:36:53 +08:00
using static osu.Game.Overlays.News.Sidebar.YearsPanel;
2021-05-10 14:53:52 +08:00
namespace osu.Game.Tests.Visual.Online
{
2021-05-17 15:00:36 +08:00
public class TestSceneNewsSidebar : OsuTestScene
2021-05-10 14:53:52 +08:00
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
2021-05-17 16:36:53 +08:00
private TestNewsSidebar sidebar;
2021-05-10 14:53:52 +08:00
2021-05-12 01:42:13 +08:00
[SetUp]
2021-05-17 16:36:53 +08:00
public void SetUp() => Schedule(() => Child = sidebar = new TestNewsSidebar { YearChanged = onYearChanged });
2021-05-10 14:53:52 +08:00
[Test]
public void TestMetadataWithNoPosts()
2021-05-10 14:53:52 +08:00
{
AddStep("Add data with no posts", () => sidebar.Metadata.Value = metadata_with_no_posts);
AddUntilStep("No dropdowns were created", () => !sidebar.ChildrenOfType<MonthSection>().Any());
2021-05-10 14:53:52 +08:00
}
[Test]
public void TestYearsPanelVisibility()
{
AddUntilStep("Years panel is hidden", () => yearsPanel?.Alpha == 0);
2021-05-17 16:36:53 +08:00
AddStep("Add data", () => sidebar.Metadata.Value = getMetadata(2021));
AddUntilStep("Years panel is visible", () => yearsPanel?.Alpha == 1);
}
2021-05-17 16:36:53 +08:00
private void onYearChanged(int year) => sidebar.Metadata.Value = getMetadata(year);
2021-05-12 01:42:13 +08:00
private YearsPanel yearsPanel => sidebar.ChildrenOfType<YearsPanel>().FirstOrDefault();
2021-05-10 14:53:52 +08:00
2021-05-17 16:36:53 +08:00
private APINewsSidebar getMetadata(int year) => new APINewsSidebar
2021-05-10 14:53:52 +08:00
{
2021-05-17 16:36:53 +08:00
CurrentYear = year,
2021-05-10 14:53:52 +08:00
Years = new[]
{
2021,
2020,
2019,
2018,
2017,
2016,
2015,
2014,
2013
},
NewsPosts = new List<APINewsPost>
{
new APINewsPost
{
Title = "(Mar) Short title",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 3, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "(Mar) Oh boy that's a long post title I wonder if it will break anything",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 3, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "(Mar) Medium title, nothing to see here",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 3, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "(Feb) Short title",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 2, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "(Feb) Oh boy that's a long post title I wonder if it will break anything",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 2, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "(Feb) Medium title, nothing to see here",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 2, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "Short title",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 1, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "Oh boy that's a long post title I wonder if it will break anything",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 1, 1)
2021-05-10 14:53:52 +08:00
},
new APINewsPost
{
Title = "Medium title, nothing to see here",
2021-05-17 16:36:53 +08:00
PublishedAt = new DateTime(year, 1, 1)
2021-05-10 14:53:52 +08:00
}
}
};
private static readonly APINewsSidebar metadata_with_no_posts = new APINewsSidebar
{
CurrentYear = 2022,
Years = new[]
{
2022,
2021,
2020,
2019,
2018,
2017,
2016,
2015,
2014,
2013
},
NewsPosts = Array.Empty<APINewsPost>()
};
2021-05-17 16:36:53 +08:00
private class TestNewsSidebar : NewsSidebar
{
public Action<int> YearChanged;
protected override void LoadComplete()
{
base.LoadComplete();
Metadata.BindValueChanged(m =>
{
foreach (var b in this.ChildrenOfType<YearButton>())
b.Action = () => YearChanged?.Invoke(b.Year);
}, true);
}
}
2021-05-10 14:53:52 +08:00
}
}