mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add tests
This commit is contained in:
@ -3,18 +3,19 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Comments;
|
using osu.Game.Overlays.Comments;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneCommentEditor : OsuTestScene
|
public class TestSceneCommentEditor : ManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
@ -25,20 +26,76 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||||
|
|
||||||
private readonly OsuSpriteText text;
|
private TestCommentEditor commentEditor;
|
||||||
private readonly TestCommentEditor commentEditor;
|
private TestCancellableCommentEditor cancellableCommentEditor;
|
||||||
private readonly TestCancellableCommentEditor cancellableCommentEditor;
|
private string commitText;
|
||||||
|
private bool cancelActionFired;
|
||||||
|
|
||||||
public TestSceneCommentEditor()
|
[Test]
|
||||||
|
public void TestCommitViaKeyboard()
|
||||||
{
|
{
|
||||||
Add(new Container
|
AddStep("Create", createEditors);
|
||||||
|
AddStep("Click on textbox", () =>
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
InputManager.MoveMouseTo(commentEditor);
|
||||||
Child = text = new OsuSpriteText
|
InputManager.Click(MouseButton.Left);
|
||||||
{
|
|
||||||
Font = OsuFont.GetFont()
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
AddStep("Write something", () => commentEditor.Current.Value = "text");
|
||||||
|
AddStep("Click Enter", () => press(Key.Enter));
|
||||||
|
AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText));
|
||||||
|
AddAssert("Button is loading", () => commentEditor.IsLoading);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCommitViaKeyboardWhenEmpty()
|
||||||
|
{
|
||||||
|
AddStep("Create", createEditors);
|
||||||
|
AddStep("Click on textbox", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(commentEditor);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddStep("Click Enter", () => press(Key.Enter));
|
||||||
|
AddAssert("Text not invoked", () => string.IsNullOrEmpty(commitText));
|
||||||
|
AddAssert("Button is not loading", () => !commentEditor.IsLoading);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCommitViaButton()
|
||||||
|
{
|
||||||
|
AddStep("Create", createEditors);
|
||||||
|
AddStep("Click on textbox", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(commentEditor);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddStep("Write something", () => commentEditor.Current.Value = "text");
|
||||||
|
AddStep("Click on button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(commentEditor.ButtonsContainer);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText));
|
||||||
|
AddAssert("Button is loading", () => commentEditor.IsLoading);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCancelAction()
|
||||||
|
{
|
||||||
|
AddStep("Create", createEditors);
|
||||||
|
AddStep("Click on cancel button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("Cancel action is fired", () => cancelActionFired);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createEditors()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
commitText = string.Empty;
|
||||||
|
cancelActionFired = false;
|
||||||
|
|
||||||
Add(new FillFlowContainer
|
Add(new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -52,11 +109,12 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
commentEditor = new TestCommentEditor
|
commentEditor = new TestCommentEditor
|
||||||
{
|
{
|
||||||
OnCommit = onCommit
|
OnCommit = onCommit,
|
||||||
},
|
},
|
||||||
cancellableCommentEditor = new TestCancellableCommentEditor
|
cancellableCommentEditor = new TestCancellableCommentEditor
|
||||||
{
|
{
|
||||||
OnCommit = onCommit
|
OnCommit = onCommit,
|
||||||
|
OnCancel = onCancel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -64,17 +122,29 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
private void onCommit(string value)
|
private void onCommit(string value)
|
||||||
{
|
{
|
||||||
text.Text = $@"Invoked text: {value}";
|
commitText = value;
|
||||||
|
|
||||||
Scheduler.AddDelayed(() =>
|
Scheduler.AddDelayed(() =>
|
||||||
{
|
{
|
||||||
commentEditor.IsLoading = false;
|
commentEditor.IsLoading = false;
|
||||||
cancellableCommentEditor.IsLoading = false;
|
cancellableCommentEditor.IsLoading = false;
|
||||||
}, 500);
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCancel() => cancelActionFired = true;
|
||||||
|
|
||||||
|
private void press(Key key)
|
||||||
|
{
|
||||||
|
InputManager.PressKey(key);
|
||||||
|
InputManager.ReleaseKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestCommentEditor : CommentEditor
|
private class TestCommentEditor : CommentEditor
|
||||||
{
|
{
|
||||||
|
public new Bindable<string> Current => base.Current;
|
||||||
|
|
||||||
|
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
|
||||||
|
|
||||||
protected override string FooterText => @"Footer text. And it is pretty long. Cool.";
|
protected override string FooterText => @"Footer text. And it is pretty long. Cool.";
|
||||||
|
|
||||||
protected override string CommitButtonText => @"Commit";
|
protected override string CommitButtonText => @"Commit";
|
||||||
@ -84,6 +154,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
private class TestCancellableCommentEditor : CancellableCommentEditor
|
private class TestCancellableCommentEditor : CancellableCommentEditor
|
||||||
{
|
{
|
||||||
|
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
|
||||||
|
|
||||||
protected override string FooterText => @"Wow, another one. Sicc";
|
protected override string FooterText => @"Wow, another one. Sicc";
|
||||||
|
|
||||||
protected override string CommitButtonText => @"Save";
|
protected override string CommitButtonText => @"Save";
|
||||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
protected FillFlowContainer ButtonsContainer;
|
protected FillFlowContainer ButtonsContainer;
|
||||||
|
|
||||||
private readonly Bindable<string> current = new Bindable<string>();
|
protected readonly Bindable<string> Current = new Bindable<string>();
|
||||||
|
|
||||||
private CommitButton commitButton;
|
private CommitButton commitButton;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Height = 40,
|
Height = 40,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
PlaceholderText = TextboxPlaceholderText,
|
PlaceholderText = TextboxPlaceholderText,
|
||||||
Current = current
|
Current = Current
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
@ -104,8 +104,8 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
OnCommit?.Invoke(current.Value);
|
OnCommit?.Invoke(Current.Value);
|
||||||
current.Value = string.Empty;
|
Current.Value = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true);
|
Current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EditorTextbox : BasicTextBox
|
private class EditorTextbox : BasicTextBox
|
||||||
@ -219,7 +219,8 @@ namespace osu.Game.Overlays.Comments
|
|||||||
},
|
},
|
||||||
background = new Box
|
background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Alpha = 0
|
||||||
},
|
},
|
||||||
drawableText = new OsuSpriteText
|
drawableText = new OsuSpriteText
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user