Skip to content

Commit

Permalink
Remove unused case and clean-up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 2, 2020
1 parent faecef9 commit fdbcf80
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TestKaraokeScoreInfo()

User = new User
{
Id = 11111,
Id = 1030492,
Username = "andy840119",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
};
Expand Down
210 changes: 4 additions & 206 deletions osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
Expand All @@ -20,9 +18,7 @@
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Input;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
Expand All @@ -32,126 +28,10 @@ public class TestSceneResultsScreen : OsuManualInputManagerTestScene
{
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestKaraokeBeatmap(ruleset);

private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo));

private UnrankedSoloResultsScreen createUnrankedSoloResultsScreen() => new UnrankedSoloResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo));

[Test]
public void TestResultsWithoutPlayer()
{
TestResultsScreen screen = null;
OsuScreenStack stack;

AddStep("load results", () =>
{
Child = stack = new OsuScreenStack
{
RelativeSizeAxes = Axes.Both
};

stack.Push(screen = createResultsScreen());
});
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddAssert("retry overlay not present", () => screen.RetryOverlay == null);
}

[Test]
public void TestResultsWithPlayer()
{
TestResultsScreen screen = null;

AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen()));
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddAssert("retry overlay present", () => screen.RetryOverlay != null);
}

[Test]
public void TestResultsForUnranked()
private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestKaraokeScoreInfo
{
UnrankedSoloResultsScreen screen = null;

AddStep("load results", () => Child = new TestResultsContainer(screen = createUnrankedSoloResultsScreen()));
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddAssert("retry overlay present", () => screen.RetryOverlay != null);
}

[Test]
public void TestShowHideStatisticsViaOutsideClick()
{
TestResultsScreen screen = null;

AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen()));
AddUntilStep("wait for loaded", () => screen.IsLoaded);

AddStep("click expanded panel", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
InputManager.MoveMouseTo(expandedPanel);
InputManager.Click(MouseButton.Left);
});

AddAssert("statistics shown", () => this.ChildrenOfType<StatisticsPanel>().Single().State.Value == Visibility.Visible);

AddUntilStep("expanded panel at the left of the screen", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
return expandedPanel.ScreenSpaceDrawQuad.TopLeft.X - screen.ScreenSpaceDrawQuad.TopLeft.X < 150;
});

AddStep("click to right of panel", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
InputManager.MoveMouseTo(expandedPanel.ScreenSpaceDrawQuad.TopRight + new Vector2(100, 0));
InputManager.Click(MouseButton.Left);
});

AddAssert("statistics hidden", () => this.ChildrenOfType<StatisticsPanel>().Single().State.Value == Visibility.Hidden);

AddUntilStep("expanded panel in centre of screen", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
return Precision.AlmostEquals(expandedPanel.ScreenSpaceDrawQuad.Centre.X, screen.ScreenSpaceDrawQuad.Centre.X, 1);
});
}

[Test]
public void TestShowHideStatistics()
{
TestResultsScreen screen = null;

AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen()));
AddUntilStep("wait for loaded", () => screen.IsLoaded);

AddStep("click expanded panel", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
InputManager.MoveMouseTo(expandedPanel);
InputManager.Click(MouseButton.Left);
});

AddAssert("statistics shown", () => this.ChildrenOfType<StatisticsPanel>().Single().State.Value == Visibility.Visible);

AddUntilStep("expanded panel at the left of the screen", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
return expandedPanel.ScreenSpaceDrawQuad.TopLeft.X - screen.ScreenSpaceDrawQuad.TopLeft.X < 150;
});

AddStep("click expanded panel", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
InputManager.MoveMouseTo(expandedPanel);
InputManager.Click(MouseButton.Left);
});

AddAssert("statistics hidden", () => this.ChildrenOfType<StatisticsPanel>().Single().State.Value == Visibility.Hidden);

AddUntilStep("expanded panel in centre of screen", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
return Precision.AlmostEquals(expandedPanel.ScreenSpaceDrawQuad.Centre.X, screen.ScreenSpaceDrawQuad.Centre.X, 1);
});
}
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents()
});

[Test]
public void TestShowStatisticsAndClickOtherPanel()
Expand Down Expand Up @@ -181,24 +61,6 @@ public void TestShowStatisticsAndClickOtherPanel()
AddAssert("expanded panel still expanded", () => expandedPanel.State == PanelState.Expanded);
}

[Test]
public void TestFetchScoresAfterShowingStatistics()
{
DelayedFetchResultsScreen screen = null;

AddStep("load results", () => Child = new TestResultsContainer(screen = new DelayedFetchResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo), 3000)));
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddStep("click expanded panel", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
InputManager.MoveMouseTo(expandedPanel);
InputManager.Click(MouseButton.Left);
});

AddUntilStep("wait for fetch", () => screen.FetchCompleted);
AddAssert("expanded panel still on screen", () => this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded).ScreenSpaceDrawQuad.TopLeft.X > 0);
}

private class TestResultsContainer : Container
{
[Cached(typeof(Player))]
Expand All @@ -220,27 +82,18 @@ public TestResultsContainer(IScreen screen)

private class TestResultsScreen : ResultsScreen
{
public HotkeyRetryOverlay RetryOverlay;

public TestResultsScreen(ScoreInfo score)
: base(score)
{
}

protected override void LoadComplete()
{
base.LoadComplete();

RetryOverlay = InternalChildren.OfType<HotkeyRetryOverlay>().SingleOrDefault();
}

protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
var scores = new List<ScoreInfo>();

for (int i = 0; i < 20; i++)
{
var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo);
var score = new TestKaraokeScoreInfo();
score.TotalScore += 10 - i;
scores.Add(score);
}
Expand All @@ -250,60 +103,5 @@ protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresC
return null;
}
}

private class DelayedFetchResultsScreen : TestResultsScreen
{
public bool FetchCompleted { get; private set; }

private readonly double delay;

public DelayedFetchResultsScreen(ScoreInfo score, double delay)
: base(score)
{
this.delay = delay;
}

protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(delay));

var scores = new List<ScoreInfo>();

for (int i = 0; i < 20; i++)
{
var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo);
score.TotalScore += 10 - i;
scores.Add(score);
}

scoresCallback?.Invoke(scores);

Schedule(() => FetchCompleted = true);
});

return null;
}
}

private class UnrankedSoloResultsScreen : SoloResultsScreen
{
public HotkeyRetryOverlay RetryOverlay;

public UnrankedSoloResultsScreen(ScoreInfo score)
: base(score)
{
Score.Beatmap.OnlineBeatmapID = 0;
Score.Beatmap.Status = BeatmapSetOnlineStatus.Pending;
}

protected override void LoadComplete()
{
base.LoadComplete();

RetryOverlay = InternalChildren.OfType<HotkeyRetryOverlay>().SingleOrDefault();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests.Visual;
using System.Collections.Generic;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
Expand All @@ -17,7 +15,7 @@ public class TestSceneStatisticsPanel : OsuTestScene
[Test]
public void TestScoreWithStatistics()
{
var score = new TestKaraokeScoreInfo()
var score = new TestKaraokeScoreInfo
{
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents()
};
Expand Down

0 comments on commit fdbcf80

Please sign in to comment.