mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Add test coverage
This commit is contained in:
parent
efebe55d22
commit
9824d09d49
@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.BeatmapListing;
|
using osu.Game.Overlays.BeatmapListing;
|
||||||
@ -15,12 +19,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
public class TestSceneBeatmapListingSortTabControl : OsuTestScene
|
public class TestSceneBeatmapListingSortTabControl : OsuTestScene
|
||||||
{
|
{
|
||||||
|
private readonly BeatmapListingSortTabControl control;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||||
|
|
||||||
public TestSceneBeatmapListingSortTabControl()
|
public TestSceneBeatmapListingSortTabControl()
|
||||||
{
|
{
|
||||||
BeatmapListingSortTabControl control;
|
|
||||||
OsuSpriteText current;
|
OsuSpriteText current;
|
||||||
OsuSpriteText direction;
|
OsuSpriteText direction;
|
||||||
|
|
||||||
@ -45,5 +50,83 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
control.SortDirection.BindValueChanged(sortDirection => direction.Text = $"Sort direction: {sortDirection.NewValue}", true);
|
control.SortDirection.BindValueChanged(sortDirection => direction.Text = $"Sort direction: {sortDirection.NewValue}", true);
|
||||||
control.Current.BindValueChanged(criteria => current.Text = $"Criteria: {criteria.NewValue}", true);
|
control.Current.BindValueChanged(criteria => current.Text = $"Criteria: {criteria.NewValue}", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRankedSort()
|
||||||
|
{
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Any);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Leaderboard);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Ranked);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Qualified);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Loved);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Favourites);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Ranked, SearchCategory.Pending);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Ranked, SearchCategory.Wip);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Ranked, SearchCategory.Graveyard);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Ranked, SearchCategory.Mine);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestUpdatedSort()
|
||||||
|
{
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Updated, SearchCategory.Any);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Updated, SearchCategory.Leaderboard);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Updated, SearchCategory.Ranked);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Updated, SearchCategory.Qualified);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Updated, SearchCategory.Loved);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Updated, SearchCategory.Favourites);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Updated, SearchCategory.Pending);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Updated, SearchCategory.Wip);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Updated, SearchCategory.Graveyard);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Updated, SearchCategory.Mine);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNominationsSort()
|
||||||
|
{
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Any);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Leaderboard);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Ranked);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Qualified);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Loved);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Favourites);
|
||||||
|
criteriaShowsOnCategory(true, SortCriteria.Nominations, SearchCategory.Pending);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Wip);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Graveyard);
|
||||||
|
criteriaShowsOnCategory(false, SortCriteria.Nominations, SearchCategory.Mine);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestResetNoQuery()
|
||||||
|
{
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Ranked, SearchCategory.Any);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Ranked, SearchCategory.Leaderboard);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Ranked, SearchCategory.Ranked);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Ranked, SearchCategory.Qualified);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Ranked, SearchCategory.Loved);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Ranked, SearchCategory.Favourites);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Updated, SearchCategory.Pending);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Updated, SearchCategory.Wip);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Updated, SearchCategory.Graveyard);
|
||||||
|
resetUsesCriteriaOnCategory(SortCriteria.Updated, SearchCategory.Mine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void criteriaShowsOnCategory(bool expected, SortCriteria criteria, SearchCategory category)
|
||||||
|
{
|
||||||
|
AddAssert($"{criteria.ToString().ToLowerInvariant()} {(expected ? "shown" : "not shown")} on {category.ToString().ToLowerInvariant()}", () =>
|
||||||
|
{
|
||||||
|
control.Reset(category, false);
|
||||||
|
return control.ChildrenOfType<TabControl<SortCriteria>>().Single().Items.Contains(criteria) == expected;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetUsesCriteriaOnCategory(SortCriteria criteria, SearchCategory category)
|
||||||
|
{
|
||||||
|
AddAssert($"reset uses {criteria.ToString().ToLowerInvariant()} on {category.ToString().ToLowerInvariant()}", () =>
|
||||||
|
{
|
||||||
|
control.Reset(category, false);
|
||||||
|
return control.Current.Value == criteria;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user