mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Rewrite test scene to be automated
This commit is contained in:
@ -3,20 +3,26 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.MathUtils;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Graphics.Cursor;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.Leaderboards;
|
using osu.Game.Online.Leaderboards;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Dialog;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.Select.Leaderboards;
|
using osu.Game.Screens.Select.Leaderboards;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
@ -32,19 +38,27 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
typeof(LeaderboardScore),
|
typeof(LeaderboardScore),
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly FailableLeaderboard leaderboard;
|
private readonly ContextMenuContainer contextMenuContainer;
|
||||||
|
private readonly BeatmapLeaderboard leaderboard;
|
||||||
|
|
||||||
|
private RulesetStore rulesetStore;
|
||||||
|
private BeatmapManager beatmapManager;
|
||||||
|
private ScoreManager scoreManager;
|
||||||
|
|
||||||
|
private readonly List<ScoreInfo> scores = new List<ScoreInfo>();
|
||||||
|
private BeatmapInfo beatmap;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly DialogOverlay dialogOverlay;
|
private readonly DialogOverlay dialogOverlay;
|
||||||
|
|
||||||
public TestSceneDeleteLocalScore()
|
public TestSceneDeleteLocalScore()
|
||||||
{
|
{
|
||||||
Add(dialogOverlay = new DialogOverlay
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
Depth = -1
|
contextMenuContainer = new OsuContextMenuContainer
|
||||||
});
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
Add(leaderboard = new FailableLeaderboard
|
Child = leaderboard = new BeatmapLeaderboard
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -65,121 +79,92 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
},
|
},
|
||||||
Version = "Insane"
|
Version = "Insane"
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
},
|
||||||
AddStep("Insert Local Scores", reset);
|
dialogOverlay = new DialogOverlay()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reset()
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
{
|
{
|
||||||
leaderboard.InitialLoad = true;
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||||
leaderboard.RefreshScores();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FailableLeaderboard : BeatmapLeaderboard
|
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
|
||||||
|
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, Audio, dependencies.Get<GameHost>(), Beatmap.Default));
|
||||||
|
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory));
|
||||||
|
|
||||||
|
beatmap = beatmapManager.Import(TestResources.GetTestBeatmapForImport()).Result.Beatmaps[0];
|
||||||
|
|
||||||
|
for (int i = 0; i < 50; i++)
|
||||||
{
|
{
|
||||||
private List<ScoreInfo> scoreList;
|
var score = new ScoreInfo
|
||||||
|
|
||||||
private Random rnd;
|
|
||||||
|
|
||||||
public bool InitialLoad;
|
|
||||||
|
|
||||||
public void DeleteScore(ScoreInfo score)
|
|
||||||
{
|
{
|
||||||
scoreList.Remove(score);
|
OnlineScoreID = i,
|
||||||
RefreshScores();
|
Beatmap = beatmap,
|
||||||
}
|
BeatmapInfoID = beatmap.ID,
|
||||||
|
Accuracy = RNG.NextDouble(),
|
||||||
public FailableLeaderboard()
|
TotalScore = RNG.Next(1, 1000000),
|
||||||
{
|
MaxCombo = RNG.Next(1, 1000),
|
||||||
InitialLoad = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetRetrievalState(PlaceholderState state)
|
|
||||||
{
|
|
||||||
PlaceholderState = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
|
||||||
{
|
|
||||||
if (InitialLoad)
|
|
||||||
{
|
|
||||||
rnd = new Random();
|
|
||||||
|
|
||||||
scoreList = Enumerable.Range(1, 50).Select(createScore).ToList();
|
|
||||||
Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray();
|
|
||||||
|
|
||||||
InitialLoad = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ScoreInfo createScore(int id) => new ScoreInfo
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
Accuracy = rnd.NextDouble(),
|
|
||||||
PP = rnd.Next(1, 1000000),
|
|
||||||
TotalScore = rnd.Next(1, 1000000),
|
|
||||||
MaxCombo = rnd.Next(1, 1000),
|
|
||||||
Rank = ScoreRank.XH,
|
Rank = ScoreRank.XH,
|
||||||
User = new User { Username = "TestUser" },
|
User = new User { Username = "TestUser" },
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index)
|
scores.Add(scoreManager.Import(score).Result);
|
||||||
{
|
|
||||||
model.Beatmap = Beatmap;
|
|
||||||
return new TestLeaderboardScore(model, index, this, IsOnlineScope);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestLeaderboardScore : LeaderboardScore
|
scores.Sort(Comparer<ScoreInfo>.Create((s1, s2) => s2.TotalScore.CompareTo(s1.TotalScore)));
|
||||||
{
|
|
||||||
[Resolved]
|
|
||||||
private DialogOverlay dialogOverlay { get; set; }
|
|
||||||
|
|
||||||
private readonly FailableLeaderboard leaderboard;
|
return dependencies;
|
||||||
|
|
||||||
public TestLeaderboardScore(ScoreInfo score, int rank, FailableLeaderboard leaderboard, bool allowHighlight = true)
|
|
||||||
: base(score, rank, allowHighlight)
|
|
||||||
{
|
|
||||||
this.leaderboard = leaderboard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeleteLocalScore(ScoreInfo score)
|
[SetUp]
|
||||||
|
public void Setup() => Schedule(() =>
|
||||||
{
|
{
|
||||||
dialogOverlay?.Push(new TestLocalScoreDeleteDialog(score, leaderboard));
|
// Due to soft deletions, we can re-use deleted scores between test runs
|
||||||
}
|
scoreManager.Undelete(scoreManager.QueryScores(s => s.DeletePending).ToList());
|
||||||
|
|
||||||
|
leaderboard.Beatmap = beatmap;
|
||||||
|
leaderboard.RefreshScores();
|
||||||
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDeleteViaRightClick()
|
||||||
|
{
|
||||||
|
// Ensure the leaderboard items have finished showing up
|
||||||
|
AddStep("finish transforms", () => leaderboard.FinishTransforms(true));
|
||||||
|
|
||||||
|
AddStep("open menu for top score", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(leaderboard.ChildrenOfType<LeaderboardScore>().First());
|
||||||
|
InputManager.Click(MouseButton.Right);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure the context menu has finished showing
|
||||||
|
AddStep("finish transforms", () => contextMenuContainer.FinishTransforms(true));
|
||||||
|
|
||||||
|
AddStep("click delete option", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => i.Item.Text.Value.ToLowerInvariant() == "delete"));
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure the dialog has finished showing
|
||||||
|
AddStep("finish transforms", () => dialogOverlay.FinishTransforms(true));
|
||||||
|
|
||||||
|
AddStep("click delete button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(dialogOverlay.ChildrenOfType<DialogButton>().First());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scores[0].OnlineScoreID));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestLocalScoreDeleteDialog : PopupDialog
|
[Test]
|
||||||
|
public void TestDeleteViaDatabase()
|
||||||
{
|
{
|
||||||
public TestLocalScoreDeleteDialog(ScoreInfo score, FailableLeaderboard leaderboard)
|
AddStep("delete top score", () => scoreManager.Delete(scores[0]));
|
||||||
{
|
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scores[0].OnlineScoreID));
|
||||||
Debug.Assert(score != null);
|
|
||||||
|
|
||||||
string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy);
|
|
||||||
|
|
||||||
BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {score.Beatmap}";
|
|
||||||
Icon = FontAwesome.Solid.Eraser;
|
|
||||||
HeaderText = @"Deleting this local score. Are you sure?";
|
|
||||||
Buttons = new PopupDialogButton[]
|
|
||||||
{
|
|
||||||
new PopupDialogOkButton
|
|
||||||
{
|
|
||||||
Text = @"Yes. Please.",
|
|
||||||
Action = () => leaderboard.DeleteScore(score)
|
|
||||||
},
|
|
||||||
new PopupDialogCancelButton
|
|
||||||
{
|
|
||||||
Text = @"No, I'm still attached.",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user