From 2dace742a3b62011a31372eb49622350695b5122 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 26 Jul 2023 15:21:41 +0900 Subject: [PATCH] Add test coverage of score arriving on disk when exporting from results screen after play --- .../TestScenePlayerLocalScoreImport.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs index b0b9d48cbe..0a372d74e7 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs @@ -21,9 +21,11 @@ using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; +using osu.Game.Screens; using osu.Game.Screens.Play; using osu.Game.Screens.Ranking; using osu.Game.Tests.Resources; +using osuTK.Input; namespace osu.Game.Tests.Visual.Gameplay { @@ -147,6 +149,37 @@ namespace osu.Game.Tests.Visual.Gameplay AddUntilStep("score in database", () => Realm.Run(r => r.Find(Player.Score.ScoreInfo.ID) != null)); } + [Test] + public void TestReplayExport() + { + CreateTest(); + + AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning); + + AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime())); + + AddUntilStep("results displayed", () => (Player.GetChildScreen() as ResultsScreen)?.IsLoaded == true); + AddUntilStep("score in database", () => Realm.Run(r => r.Find(Player.Score.ScoreInfo.ID) != null)); + + AddUntilStep("wait for button clickable", () => ((OsuScreen)Player.GetChildScreen()) + .ChildrenOfType().FirstOrDefault()? + .ChildrenOfType()?.FirstOrDefault()? + .Enabled.Value == true); + + AddAssert("no export files", () => !LocalStorage.GetFiles("exports").Any()); + + AddStep("Export replay", () => InputManager.PressKey(Key.F2)); + + string? filePath = null; + + AddUntilStep("wait for export file", () => filePath = LocalStorage.GetFiles("exports").SingleOrDefault(), () => Is.Not.Null); + AddAssert("filesize is non-zero", () => + { + using (var stream = LocalStorage.GetStream(filePath)) + return stream.Length; + }, () => Is.Not.Zero); + } + [Test] public void TestScoreStoredLocallyCustomRuleset() {