1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Add test coverage

This commit is contained in:
Salman Ahmed 2022-10-13 02:40:20 +03:00
parent 964ed01abb
commit 7db7bcc283

View File

@ -10,10 +10,13 @@ using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel;
using osu.Game.Tests.Online;
using osu.Game.Tests.Resources;
using osuTK.Input;
namespace osu.Game.Tests.Visual.SongSelect
{
@ -41,17 +44,7 @@ namespace osu.Game.Tests.Visual.SongSelect
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create carousel", () =>
{
Child = carousel = new BeatmapCarousel
{
RelativeSizeAxes = Axes.Both,
BeatmapSets = new List<BeatmapSetInfo>
{
(testBeatmapSetInfo = TestResources.CreateTestBeatmapSetInfo()),
}
};
});
AddStep("create carousel", () => Child = createCarousel());
AddUntilStep("wait for load", () => carousel.BeatmapSetsLoaded);
@ -152,5 +145,60 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("wait for button enabled", () => getUpdateButton()?.Enabled.Value == true);
}
[Test]
public void TestUpdateLocalBeatmap()
{
DialogOverlay dialogOverlay = null!;
AddStep("create carousel with dialog overlay", () =>
{
dialogOverlay = new DialogOverlay();
Child = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] { (typeof(IDialogOverlay), dialogOverlay), },
Children = new Drawable[]
{
createCarousel(),
dialogOverlay,
},
};
});
AddStep("setup beatmap state", () =>
{
testBeatmapSetInfo.Beatmaps.First().OnlineMD5Hash = "different hash";
testBeatmapSetInfo.Beatmaps.First().LastOnlineUpdate = DateTimeOffset.Now;
testBeatmapSetInfo.Status = BeatmapOnlineStatus.LocallyModified;
carousel.UpdateBeatmapSet(testBeatmapSetInfo);
});
AddStep("click button", () => getUpdateButton()?.TriggerClick());
AddAssert("dialog displayed", () => dialogOverlay.CurrentDialog is UpdateLocalConfirmationDialog);
AddStep("click confirmation", () =>
{
InputManager.MoveMouseTo(dialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().First());
InputManager.PressButton(MouseButton.Left);
});
AddUntilStep("update started", () => beatmapDownloader.GetExistingDownload(testBeatmapSetInfo) != null);
AddStep("release mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
}
private BeatmapCarousel createCarousel()
{
return carousel = new BeatmapCarousel
{
RelativeSizeAxes = Axes.Both,
BeatmapSets = new List<BeatmapSetInfo>
{
(testBeatmapSetInfo = TestResources.CreateTestBeatmapSetInfo()),
}
};
}
}
}