Merge branch 'master' into move-overlay-ruleset-selectors

This commit is contained in:
Bartłomiej Dach
2023-01-14 15:22:14 +01:00
committed by GitHub
50 changed files with 319 additions and 410 deletions

View File

@ -1,13 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Overlays.Comments;
using osuTK;
@ -20,8 +23,8 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private TestCommentEditor commentEditor;
private TestCancellableCommentEditor cancellableCommentEditor;
private TestCommentEditor commentEditor = null!;
private TestCancellableCommentEditor cancellableCommentEditor = null!;
[SetUp]
public void SetUp() => Schedule(() =>
@ -45,15 +48,16 @@ namespace osu.Game.Tests.Visual.UserInterface
{
AddStep("click on text box", () =>
{
InputManager.MoveMouseTo(commentEditor);
InputManager.MoveMouseTo(commentEditor.ChildrenOfType<TextBox>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("enter text", () => commentEditor.Current.Value = "text");
AddStep("press Enter", () => InputManager.Key(Key.Enter));
AddUntilStep("button is loading", () => commentEditor.IsSpinnerShown);
AddAssert("text committed", () => commentEditor.CommittedText == "text");
AddAssert("button is loading", () => commentEditor.IsLoading);
AddUntilStep("button is not loading", () => !commentEditor.IsSpinnerShown);
}
[Test]
@ -61,14 +65,14 @@ namespace osu.Game.Tests.Visual.UserInterface
{
AddStep("click on text box", () =>
{
InputManager.MoveMouseTo(commentEditor);
InputManager.MoveMouseTo(commentEditor.ChildrenOfType<TextBox>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("press Enter", () => InputManager.Key(Key.Enter));
AddAssert("no text committed", () => commentEditor.CommittedText == null);
AddAssert("button is not loading", () => !commentEditor.IsLoading);
AddAssert("button is not loading", () => !commentEditor.IsSpinnerShown);
AddAssert("no text committed", () => commentEditor.CommittedText.Length == 0);
}
[Test]
@ -76,7 +80,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
AddStep("click on text box", () =>
{
InputManager.MoveMouseTo(commentEditor);
InputManager.MoveMouseTo(commentEditor.ChildrenOfType<TextBox>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("enter text", () => commentEditor.Current.Value = "some other text");
@ -87,8 +91,9 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.Click(MouseButton.Left);
});
AddUntilStep("button is loading", () => commentEditor.IsSpinnerShown);
AddAssert("text committed", () => commentEditor.CommittedText == "some other text");
AddAssert("button is loading", () => commentEditor.IsLoading);
AddUntilStep("button is not loading", () => !commentEditor.IsSpinnerShown);
}
[Test]
@ -96,7 +101,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
AddStep("click cancel button", () =>
{
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer);
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer[1]);
InputManager.Click(MouseButton.Left);
});
@ -108,28 +113,27 @@ namespace osu.Game.Tests.Visual.UserInterface
public new Bindable<string> Current => base.Current;
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
public string CommittedText { get; private set; }
public string CommittedText { get; private set; } = string.Empty;
public TestCommentEditor()
{
OnCommit = onCommit;
}
public bool IsSpinnerShown => this.ChildrenOfType<LoadingSpinner>().Single().IsPresent;
private void onCommit(string value)
protected override void OnCommit(string value)
{
ShowLoadingSpinner = true;
CommittedText = value;
Scheduler.AddDelayed(() => IsLoading = false, 1000);
Scheduler.AddDelayed(() => ShowLoadingSpinner = false, 1000);
}
protected override string FooterText => @"Footer text. And it is pretty long. Cool.";
protected override string CommitButtonText => @"Commit";
protected override string TextBoxPlaceholder => @"This text box is empty";
protected override LocalisableString FooterText => @"Footer text. And it is pretty long. Cool.";
protected override LocalisableString CommitButtonText => @"Commit";
protected override LocalisableString TextBoxPlaceholder => @"This text box is empty";
}
private partial class TestCancellableCommentEditor : CancellableCommentEditor
{
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
protected override string FooterText => @"Wow, another one. Sicc";
protected override LocalisableString FooterText => @"Wow, another one. Sicc";
public bool Cancelled { get; private set; }
@ -138,8 +142,12 @@ namespace osu.Game.Tests.Visual.UserInterface
OnCancel = () => Cancelled = true;
}
protected override string CommitButtonText => @"Save";
protected override string TextBoxPlaceholder => @"Multiline textboxes soon";
protected override void OnCommit(string text)
{
}
protected override LocalisableString CommitButtonText => @"Save";
protected override LocalisableString TextBoxPlaceholder => @"Multiline textboxes soon";
}
}
}