1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 01:23:24 +08:00

Move tests to TestSceneRankingsOverlay due to refactoring

This commit is contained in:
Andrei Zavatski 2019-12-05 09:53:25 +03:00
parent 22863da360
commit 33737d3d89
4 changed files with 46 additions and 26 deletions

View File

@ -68,9 +68,7 @@ namespace osu.Game.Tests.Visual.Online
}; };
AddStep("Set country", () => countryBindable.Value = country); AddStep("Set country", () => countryBindable.Value = country);
AddAssert("Check scope is Performance", () => scope.Value == RankingsScope.Performance);
AddStep("Set scope to Score", () => scope.Value = RankingsScope.Score); AddStep("Set scope to Score", () => scope.Value = RankingsScope.Score);
AddAssert("Check country is Null", () => countryBindable.Value == null);
AddStep("Set country with no flag", () => countryBindable.Value = unknownCountry); AddStep("Set country with no flag", () => countryBindable.Value = unknownCountry);
} }
} }

View File

@ -43,11 +43,6 @@ namespace osu.Game.Tests.Visual.Online
FullName = "United States" FullName = "United States"
}; };
AddStep("Set country", () => countryBindable.Value = countryA);
AddAssert("Check scope is Performance", () => scope.Value == RankingsScope.Performance);
AddStep("Set scope to Score", () => scope.Value = RankingsScope.Score);
AddAssert("Check country is Null", () => countryBindable.Value == null);
AddStep("Set country 1", () => countryBindable.Value = countryA); AddStep("Set country 1", () => countryBindable.Value = countryA);
AddStep("Set country 2", () => countryBindable.Value = countryB); AddStep("Set country 2", () => countryBindable.Value = countryB);
AddStep("Set null country", () => countryBindable.Value = null); AddStep("Set null country", () => countryBindable.Value = null);

View File

@ -8,6 +8,8 @@ using osu.Framework.Allocation;
using osu.Game.Overlays; using osu.Game.Overlays;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Users; using osu.Game.Users;
using osu.Framework.Bindables;
using osu.Game.Overlays.Rankings;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -29,9 +31,16 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
private RankingsOverlay rankingsOverlay; private RankingsOverlay rankingsOverlay;
private readonly Bindable<Country> countryBindable = new Bindable<Country>();
private readonly Bindable<RankingsScope> scope = new Bindable<RankingsScope>();
public TestSceneRankingsOverlay() public TestSceneRankingsOverlay()
{ {
Add(rankingsOverlay = new RankingsOverlay()); Add(rankingsOverlay = new TestRankingsOverlay
{
Country = { BindTarget = countryBindable },
Scope = { BindTarget = scope },
});
} }
[Test] [Test]
@ -40,14 +49,19 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Show", rankingsOverlay.Show); AddStep("Show", rankingsOverlay.Show);
} }
[Test]
public void TestFlagScopeDependency()
{
AddStep("Set scope to Score", () => scope.Value = RankingsScope.Score);
AddAssert("Check country is Null", () => countryBindable.Value == null);
AddStep("Set country", () => countryBindable.Value = us_country);
AddAssert("Check scope is Performance", () => scope.Value == RankingsScope.Performance);
}
[Test] [Test]
public void TestShowCountry() public void TestShowCountry()
{ {
AddStep("Show US", () => rankingsOverlay.ShowCountry(new Country AddStep("Show US", () => rankingsOverlay.ShowCountry(us_country));
{
FlagName = "US",
FullName = "United States"
}));
} }
[Test] [Test]
@ -55,5 +69,18 @@ namespace osu.Game.Tests.Visual.Online
{ {
AddStep("Hide", rankingsOverlay.Hide); AddStep("Hide", rankingsOverlay.Hide);
} }
private static Country us_country = new Country
{
FlagName = "US",
FullName = "United States"
};
private class TestRankingsOverlay : RankingsOverlay
{
public new Bindable<Country> Country => base.Country;
public new Bindable<RankingsScope> Scope => base.Scope;
}
} }
} }

View File

@ -20,8 +20,8 @@ namespace osu.Game.Overlays
{ {
public class RankingsOverlay : FullscreenOverlay public class RankingsOverlay : FullscreenOverlay
{ {
private readonly Bindable<Country> country = new Bindable<Country>(); protected readonly Bindable<Country> Country = new Bindable<Country>();
private readonly Bindable<RankingsScope> scope = new Bindable<RankingsScope>(); protected readonly Bindable<RankingsScope> Scope = new Bindable<RankingsScope>();
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>(); private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
private readonly BasicScrollContainer scrollFlow; private readonly BasicScrollContainer scrollFlow;
@ -58,8 +58,8 @@ namespace osu.Game.Overlays
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Country = { BindTarget = country }, Country = { BindTarget = Country },
Scope = { BindTarget = scope }, Scope = { BindTarget = Scope },
Ruleset = { BindTarget = ruleset } Ruleset = { BindTarget = ruleset }
}, },
new Container new Container
@ -98,19 +98,19 @@ namespace osu.Game.Overlays
protected override void LoadComplete() protected override void LoadComplete()
{ {
country.BindValueChanged(_ => Country.BindValueChanged(_ =>
{ {
// if a country is requested, force performance scope. // if a country is requested, force performance scope.
if (country.Value != null) if (Country.Value != null)
scope.Value = RankingsScope.Performance; Scope.Value = RankingsScope.Performance;
Scheduler.AddOnce(loadNewContent); Scheduler.AddOnce(loadNewContent);
}, true); }, true);
scope.BindValueChanged(_ => Scope.BindValueChanged(_ =>
{ {
// country filtering is only valid for performance scope. // country filtering is only valid for performance scope.
if (scope.Value != RankingsScope.Performance) if (Scope.Value != RankingsScope.Performance)
country.Value = null; Country.Value = null;
Scheduler.AddOnce(loadNewContent); Scheduler.AddOnce(loadNewContent);
}, true); }, true);
@ -127,7 +127,7 @@ namespace osu.Game.Overlays
Show(); Show();
country.Value = requested; Country.Value = requested;
} }
private void loadNewContent() private void loadNewContent()
@ -154,10 +154,10 @@ namespace osu.Game.Overlays
private APIRequest createScopedRequest() private APIRequest createScopedRequest()
{ {
switch (scope.Value) switch (Scope.Value)
{ {
case RankingsScope.Performance: case RankingsScope.Performance:
return new GetUserRankingsRequest(ruleset.Value, country: country.Value?.FlagName); return new GetUserRankingsRequest(ruleset.Value, country: Country.Value?.FlagName);
case RankingsScope.Country: case RankingsScope.Country:
return new GetCountryRankingsRequest(ruleset.Value); return new GetCountryRankingsRequest(ruleset.Value);