mirror of
https://github.com/osukey/osukey.git
synced 2025-05-16 11:07:35 +09:00
Add extra coverage to tests
Also fixes a potential failure due to test beatmap having two difficulties with same name.
This commit is contained in:
parent
4f18105e9d
commit
dc02b59a05
@ -41,27 +41,42 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDifficultyDelete()
|
public void TestDeleteDifficulties()
|
||||||
{
|
{
|
||||||
string lastDiff = null!;
|
Guid deletedDifficultyID = Guid.Empty;
|
||||||
AddStep("remember selected difficulty", () => lastDiff = EditorBeatmap.BeatmapInfo.DifficultyName);
|
int countBeforeDeletion = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
// Will be reloaded after each deletion.
|
||||||
|
AddUntilStep("wait for editor to load", () => Editor?.ReadyForUse == true);
|
||||||
|
|
||||||
|
AddStep("store selected difficulty", () =>
|
||||||
|
{
|
||||||
|
deletedDifficultyID = EditorBeatmap.BeatmapInfo.ID;
|
||||||
|
countBeforeDeletion = Beatmap.Value.BeatmapSetInfo.Beatmaps.Count;
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("click File", () => this.ChildrenOfType<DrawableOsuMenuItem>().First().TriggerClick());
|
AddStep("click File", () => this.ChildrenOfType<DrawableOsuMenuItem>().First().TriggerClick());
|
||||||
AddStep("click Delete", () => this.ChildrenOfType<DrawableOsuMenuItem>().Single(deleteMenuItemPredicate).TriggerClick());
|
|
||||||
AddStep("confirm", () => InputManager.Key(Key.Number2));
|
|
||||||
|
|
||||||
AddAssert("difficulty is deleted", () =>
|
if (i == 11)
|
||||||
{
|
{
|
||||||
if (lastDiff == null!) throw new NullReferenceException();
|
// last difficulty shouldn't be able to be deleted.
|
||||||
|
AddAssert("Delete menu item disabled", () => getDeleteMenuItem().Item.Action.Disabled);
|
||||||
var newSet = beatmaps.GetWorkingBeatmap(importedBeatmapSet.Beatmaps.First(), true).BeatmapSetInfo;
|
|
||||||
return newSet.Beatmaps.All(x => x.DifficultyName != lastDiff);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
private bool deleteMenuItemPredicate(DrawableOsuMenuItem item)
|
|
||||||
{
|
{
|
||||||
return item.ChildrenOfType<SpriteText>().Any(text => text.Text.ToString().StartsWith("Delete", StringComparison.Ordinal));
|
AddStep("click delete", () => getDeleteMenuItem().TriggerClick());
|
||||||
|
AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog != null);
|
||||||
|
AddStep("confirm", () => InputManager.Key(Key.Number1));
|
||||||
|
|
||||||
|
AddAssert($"difficulty {i} is deleted", () => Beatmap.Value.BeatmapSetInfo.Beatmaps.Select(b => b.ID), () => Does.Not.Contain(deletedDifficultyID));
|
||||||
|
AddAssert("count decreased by one", () => Beatmap.Value.BeatmapSetInfo.Beatmaps.Count, () => Is.EqualTo(countBeforeDeletion - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DrawableOsuMenuItem getDeleteMenuItem() => this.ChildrenOfType<DrawableOsuMenuItem>()
|
||||||
|
.Single(item => item.ChildrenOfType<SpriteText>().Any(text => text.Text.ToString().StartsWith("Delete", StringComparison.Ordinal)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user