1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +08:00

Add test coverage for news sidebar showing wrong headers

This commit is contained in:
Bartłomiej Dach 2022-01-19 23:12:35 +01:00
parent 4b127d5029
commit 4cad5890c6
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 83 additions and 2 deletions

View File

@ -38,6 +38,14 @@ namespace osu.Game.Tests.Visual.Online
AddUntilStep("No month sections were created", () => !sidebar.ChildrenOfType<MonthSection>().Any());
}
[Test]
public void TestMetadataWithMultipleYears()
{
AddStep("Add data spanning multiple years", () => sidebar.Metadata.Value = metadata_with_multiple_years);
AddUntilStep("2022 month sections exist", () => sidebar.ChildrenOfType<MonthSection>().Any(s => s.Year == 2022));
AddUntilStep("2021 month sections exist", () => sidebar.ChildrenOfType<MonthSection>().Any(s => s.Year == 2021));
}
[Test]
public void TestYearsPanelVisibility()
{
@ -133,6 +141,74 @@ namespace osu.Game.Tests.Visual.Online
NewsPosts = Array.Empty<APINewsPost>()
};
// see https://osu.ppy.sh/docs/index.html#get-news-listing:
// "NewsPost collections queried by year will also include posts published in November and December of the previous year if the current date is the same year and before April."
private static readonly APINewsSidebar metadata_with_multiple_years = new APINewsSidebar
{
CurrentYear = 2022,
Years = new[]
{
2022,
2021,
2020,
2019,
2018,
2017,
2016,
2015,
2014,
2013
},
NewsPosts = new List<APINewsPost>
{
new APINewsPost
{
Title = "(Mar 2022) Short title",
PublishedAt = new DateTime(2022, 3, 1)
},
new APINewsPost
{
Title = "(Mar 2022) Oh boy that's a long post title I wonder if it will break anything",
PublishedAt = new DateTime(2022, 3, 1)
},
new APINewsPost
{
Title = "(Feb 2022) Medium title, nothing to see here",
PublishedAt = new DateTime(2022, 2, 1)
},
new APINewsPost
{
Title = "(Feb 2022) Short title",
PublishedAt = new DateTime(2022, 2, 1)
},
new APINewsPost
{
Title = "(Jan 2022) Oh boy that's a long post title I wonder if it will break anything",
PublishedAt = new DateTime(2022, 1, 1)
},
new APINewsPost
{
Title = "(Jan 2022) Medium title, nothing to see here",
PublishedAt = new DateTime(2022, 1, 1)
},
new APINewsPost
{
Title = "(Jan 2022) Short title",
PublishedAt = new DateTime(2022, 1, 1)
},
new APINewsPost
{
Title = "(Dec 2021) Surprise, the last year's not gone yet",
PublishedAt = new DateTime(2021, 12, 1)
},
new APINewsPost
{
Title = "(Nov 2021) Same goes for November",
PublishedAt = new DateTime(2021, 11, 1)
}
}
};
private class TestNewsSidebar : NewsSidebar
{
public Action<int> YearChanged;

View File

@ -24,16 +24,21 @@ namespace osu.Game.Overlays.News.Sidebar
{
public class MonthSection : CompositeDrawable
{
public int Year { get; private set; }
public int Month { get; private set; }
public readonly BindableBool Expanded = new BindableBool();
private const int animation_duration = 250;
private Sample sampleOpen;
private Sample sampleClose;
public readonly BindableBool Expanded = new BindableBool();
public MonthSection(int month, int year, IEnumerable<APINewsPost> posts)
{
Debug.Assert(posts.All(p => p.PublishedAt.Month == month && p.PublishedAt.Year == year));
Year = year;
Month = month;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Masking = true;