Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix beatmap listing sort direction not resetting when changing criteria #22926

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
using osuTK;
using osuTK.Input;

namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneBeatmapListingSortTabControl : OsuTestScene
public partial class TestSceneBeatmapListingSortTabControl : OsuManualInputManagerTestScene
{
private readonly BeatmapListingSortTabControl control;

Expand Down Expand Up @@ -111,6 +112,29 @@ public void TestResetNoQuery()
resetUsesCriteriaOnCategory(SortCriteria.Updated, SearchCategory.Mine);
}

[Test]
public void TestSortDirectionOnCriteriaChange()
{
AddStep("set category to leaderboard", () => control.Reset(SearchCategory.Leaderboard, false));
AddAssert("sort direction is descending", () => control.SortDirection.Value == SortDirection.Descending);

AddStep("click ranked sort button", () =>
{
InputManager.MoveMouseTo(control.TabControl.ChildrenOfType<BeatmapListingSortTabControl.BeatmapTabButton>().Single(s => s.Active.Value));
InputManager.Click(MouseButton.Left);
});

AddAssert("sort direction is ascending", () => control.SortDirection.Value == SortDirection.Ascending);

AddStep("click first inactive sort button", () =>
{
InputManager.MoveMouseTo(control.TabControl.ChildrenOfType<BeatmapListingSortTabControl.BeatmapTabButton>().First(s => !s.Active.Value));
InputManager.Click(MouseButton.Left);
});

AddAssert("sort direction is descending", () => control.SortDirection.Value == SortDirection.Descending);
}

private void criteriaShowsOnCategory(bool expected, SortCriteria criteria, SearchCategory category)
{
AddAssert($"{criteria.ToString().ToLowerInvariant()} {(expected ? "shown" : "not shown")} on {category.ToString().ToLowerInvariant()}", () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ protected override void LoadComplete()

if (currentParameters == null)
Reset(SearchCategory.Leaderboard, false);

Current.BindValueChanged(_ => SortDirection.Value = Overlays.SortDirection.Descending);
}

public void Reset(SearchCategory category, bool hasQuery)
Expand Down Expand Up @@ -102,7 +104,7 @@ public BeatmapSortTabItem(SortCriteria value)
};
}

private partial class BeatmapTabButton : TabButton
public partial class BeatmapTabButton : TabButton
{
public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>();

Expand Down Expand Up @@ -136,7 +138,7 @@ protected override void LoadComplete()

SortDirection.BindValueChanged(direction =>
{
icon.Icon = direction.NewValue == Overlays.SortDirection.Ascending ? FontAwesome.Solid.CaretUp : FontAwesome.Solid.CaretDown;
icon.Icon = direction.NewValue == Overlays.SortDirection.Ascending && Active.Value ? FontAwesome.Solid.CaretUp : FontAwesome.Solid.CaretDown;
}, true);
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/OverlaySortTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected override void OnDeactivated()
}
}

protected partial class TabButton : HeaderButton
public partial class TabButton : HeaderButton
{
public readonly BindableBool Active = new BindableBool();

Expand Down