1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Move resizing width and background logic to SongSelectComponentsTestScene

This commit is contained in:
Joseph Madamba 2024-08-13 22:15:10 -07:00
parent 2b41f71fd0
commit f8796e3192
2 changed files with 47 additions and 49 deletions

View File

@ -3,6 +3,9 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -11,6 +14,11 @@ namespace osu.Game.Tests.Visual.SongSelectV2
{ {
public abstract partial class SongSelectComponentsTestScene : OsuTestScene public abstract partial class SongSelectComponentsTestScene : OsuTestScene
{ {
protected Container ComponentContainer = null!;
private Container? resizeContainer;
private float relativeWidth;
[Cached] [Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine); protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
@ -20,6 +28,18 @@ namespace osu.Game.Tests.Visual.SongSelectV2
[Cached(typeof(IBindable<IBeatmapInfo?>))] [Cached(typeof(IBindable<IBeatmapInfo?>))]
protected readonly Bindable<IBeatmapInfo?> BeatmapInfo = new Bindable<IBeatmapInfo?>(); protected readonly Bindable<IBeatmapInfo?> BeatmapInfo = new Bindable<IBeatmapInfo?>();
[BackgroundDependencyLoader]
private void load()
{
AddSliderStep("change relative width", 0, 1f, 0.5f, v =>
{
if (resizeContainer != null)
resizeContainer.Width = v;
relativeWidth = v;
});
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -40,6 +60,31 @@ namespace osu.Game.Tests.Visual.SongSelectV2
SelectedMods.SetDefault(); SelectedMods.SetDefault();
BeatmapInfo.Value = null; BeatmapInfo.Value = null;
}); });
AddStep("set content", () =>
{
Child = resizeContainer = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(10),
Width = relativeWidth,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background5,
},
ComponentContainer = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(10),
}
}
};
});
} }
} }
} }

View File

@ -3,10 +3,6 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -18,56 +14,13 @@ namespace osu.Game.Tests.Visual.SongSelectV2
{ {
public partial class TestSceneDifficultyNameContent : SongSelectComponentsTestScene public partial class TestSceneDifficultyNameContent : SongSelectComponentsTestScene
{ {
private Container? content;
private DifficultyNameContent? difficultyNameContent; private DifficultyNameContent? difficultyNameContent;
private float relativeWidth;
[BackgroundDependencyLoader]
private void load()
{
AddSliderStep("change relative width", 0, 1f, 0.5f, v =>
{
if (content != null)
content.Width = v;
relativeWidth = v;
});
}
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("set content", () =>
{
Child = content = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(10),
Width = relativeWidth,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background5,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(10),
Child = difficultyNameContent = new DifficultyNameContent(),
}
}
};
});
}
[Test] [Test]
public void TestLocalBeatmap() public void TestLocalBeatmap()
{ {
AddStep("set component", () => ComponentContainer.Child = difficultyNameContent = new DifficultyNameContent());
AddAssert("difficulty name is not set", () => LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<TruncatingSpriteText>().Single().Text)); AddAssert("difficulty name is not set", () => LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<TruncatingSpriteText>().Single().Text));
AddAssert("author is not set", () => LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<OsuHoverContainer>().Single().ChildrenOfType<OsuSpriteText>().Single().Text)); AddAssert("author is not set", () => LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<OsuHoverContainer>().Single().ChildrenOfType<OsuSpriteText>().Single().Text));