1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 04:22:54 +08:00

Move CarouselBeatmap access to private, test using indices

This commit is contained in:
voidedWarranties 2020-02-15 17:51:55 -08:00
parent 8e1ecddb1d
commit 8c81f1e684
2 changed files with 38 additions and 12 deletions

View File

@ -466,36 +466,53 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestDifficultyIconSelecting() public void TestDifficultyIconSelecting()
{ {
int? previousID = null;
addRulesetImportStep(0); addRulesetImportStep(0);
createSongSelect(); createSongSelect();
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID); DrawableCarouselBeatmapSet set = null;
AddStep("Find the DrawableCarouselBeatmapSet", () =>
{
set = songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().First();
});
DrawableCarouselBeatmapSet.FilterableDifficultyIcon difficultyIcon = null;
AddStep("Find an icon", () =>
{
difficultyIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>()
.First(icon => getDifficultyIconIndex(set, icon) != getCurrentBeatmapIndex());
});
AddStep("Click on a difficulty", () => AddStep("Click on a difficulty", () =>
{ {
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>() InputManager.MoveMouseTo(difficultyIcon);
.First(icon => icon.Item.Beatmap != songSelect.Carousel.SelectedBeatmap));
InputManager.PressButton(MouseButton.Left); InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left); InputManager.ReleaseButton(MouseButton.Left);
}); });
AddAssert("Selected beatmap changed", () => songSelect.Carousel.SelectedBeatmap.ID != previousID); AddAssert("Selected beatmap correct", () => getCurrentBeatmapIndex() == getDifficultyIconIndex(set, difficultyIcon));
double? maxBPM = null;
AddStep("Filter some difficulties", () => songSelect.Carousel.Filter(new FilterCriteria AddStep("Filter some difficulties", () => songSelect.Carousel.Filter(new FilterCriteria
{ {
BPM = new FilterCriteria.OptionalRange<double> BPM = new FilterCriteria.OptionalRange<double>
{ {
Min = songSelect.Carousel.SelectedBeatmapSet.MaxBPM, Min = maxBPM = songSelect.Carousel.SelectedBeatmapSet.MaxBPM,
IsLowerInclusive = true IsLowerInclusive = true
} }
})); }));
AddUntilStep("Wait for filter", () => songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().Any(icon => icon.Item.Filtered.Value));
DrawableCarouselBeatmapSet.FilterableDifficultyIcon filteredIcon = null;
AddStep("Get filtered icon", () =>
{
var filteredBeatmap = songSelect.Carousel.SelectedBeatmapSet.Beatmaps.Find(b => b.BPM < maxBPM);
int filteredBeatmapIndex = getBeatmapIndex(filteredBeatmap.BeatmapSet, filteredBeatmap);
filteredIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().ElementAt(filteredBeatmapIndex);
});
int? previousID = null;
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID); AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID);
AddStep("Click on a filtered difficulty", () => AddStep("Click on a filtered difficulty", () =>
{ {
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>() InputManager.MoveMouseTo(filteredIcon);
.First(icon => icon.Item.Filtered.Value));
InputManager.PressButton(MouseButton.Left); InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left); InputManager.ReleaseButton(MouseButton.Left);
@ -503,6 +520,15 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmap.ID == previousID); AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmap.ID == previousID);
} }
private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.FindIndex(b => b == info);
private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmap);
private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, DrawableCarouselBeatmapSet.FilterableDifficultyIcon icon)
{
return set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().ToList().FindIndex(i => i == icon);
}
private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id)); private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id));
private void importForRuleset(int id) => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray())).Wait(); private void importForRuleset(int id) => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray())).Wait();

View File

@ -211,7 +211,7 @@ namespace osu.Game.Screens.Select.Carousel
{ {
private readonly BindableBool filtered = new BindableBool(); private readonly BindableBool filtered = new BindableBool();
public readonly CarouselBeatmap Item; private readonly CarouselBeatmap item;
public FilterableDifficultyIcon(CarouselBeatmap item) public FilterableDifficultyIcon(CarouselBeatmap item)
: base(item.Beatmap) : base(item.Beatmap)
@ -220,13 +220,13 @@ namespace osu.Game.Screens.Select.Carousel
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100)); filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
filtered.TriggerChange(); filtered.TriggerChange();
Item = item; this.item = item;
} }
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (!filtered.Value) if (!filtered.Value)
Item.State.Value = CarouselItemState.Selected; item.State.Value = CarouselItemState.Selected;
return true; return true;
} }