1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 20:53:04 +08:00

Encapsulate test editors

This commit is contained in:
Bartłomiej Dach 2020-02-13 20:56:34 +01:00
parent cc625e3b89
commit 09b2e7beed

View File

@ -28,16 +28,10 @@ namespace osu.Game.Tests.Visual.UserInterface
private TestCommentEditor commentEditor; private TestCommentEditor commentEditor;
private TestCancellableCommentEditor cancellableCommentEditor; private TestCancellableCommentEditor cancellableCommentEditor;
private string commitText;
private bool cancelActionFired;
[SetUp] [SetUp]
public void SetUp() public void SetUp() => Schedule(() =>
{ Add(new FillFlowContainer
commitText = string.Empty;
cancelActionFired = false;
Schedule(() => Add(new FillFlowContainer
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -47,18 +41,10 @@ namespace osu.Game.Tests.Visual.UserInterface
Spacing = new Vector2(0, 20), Spacing = new Vector2(0, 20),
Children = new Drawable[] Children = new Drawable[]
{ {
commentEditor = new TestCommentEditor commentEditor = new TestCommentEditor(),
{ cancellableCommentEditor = new TestCancellableCommentEditor()
OnCommit = onCommit,
},
cancellableCommentEditor = new TestCancellableCommentEditor
{
OnCommit = onCommit,
OnCancel = onCancel
}
} }
})); }));
}
[Test] [Test]
public void TestCommitViaKeyboard() public void TestCommitViaKeyboard()
@ -70,7 +56,7 @@ namespace osu.Game.Tests.Visual.UserInterface
}); });
AddStep("Write something", () => commentEditor.Current.Value = "text"); AddStep("Write something", () => commentEditor.Current.Value = "text");
AddStep("Click Enter", () => press(Key.Enter)); AddStep("Click Enter", () => press(Key.Enter));
AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText));
AddAssert("Button is loading", () => commentEditor.IsLoading); AddAssert("Button is loading", () => commentEditor.IsLoading);
} }
@ -83,7 +69,7 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
AddStep("Click Enter", () => press(Key.Enter)); AddStep("Click Enter", () => press(Key.Enter));
AddAssert("Text not invoked", () => string.IsNullOrEmpty(commitText)); AddAssert("Text not invoked", () => string.IsNullOrEmpty(commentEditor.CommittedText));
AddAssert("Button is not loading", () => !commentEditor.IsLoading); AddAssert("Button is not loading", () => !commentEditor.IsLoading);
} }
@ -101,7 +87,7 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.MoveMouseTo(commentEditor.ButtonsContainer); InputManager.MoveMouseTo(commentEditor.ButtonsContainer);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText));
AddAssert("Button is loading", () => commentEditor.IsLoading); AddAssert("Button is loading", () => commentEditor.IsLoading);
} }
@ -113,22 +99,9 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer); InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
AddAssert("Cancel action is fired", () => cancelActionFired); AddAssert("Cancel action is fired", () => cancellableCommentEditor.Cancelled);
} }
private void onCommit(string value)
{
commitText = value;
Scheduler.AddDelayed(() =>
{
commentEditor.IsLoading = false;
cancellableCommentEditor.IsLoading = false;
}, 1000);
}
private void onCancel() => cancelActionFired = true;
private void press(Key key) private void press(Key key)
{ {
InputManager.PressKey(key); InputManager.PressKey(key);
@ -138,24 +111,39 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestCommentEditor : CommentEditor private class TestCommentEditor : CommentEditor
{ {
public new Bindable<string> Current => base.Current; public new Bindable<string> Current => base.Current;
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer; public new FillFlowContainer ButtonsContainer => base.ButtonsContainer;
public string CommittedText { get; private set; }
public TestCommentEditor()
{
OnCommit = onCommit;
}
private void onCommit(string value)
{
CommittedText = value;
Scheduler.AddDelayed(() => IsLoading = false, 1000);
}
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";
protected override string TextboxPlaceholderText => @"This textbox is empty"; protected override string TextboxPlaceholderText => @"This textbox is empty";
} }
private class TestCancellableCommentEditor : CancellableCommentEditor private class TestCancellableCommentEditor : CancellableCommentEditor
{ {
public new FillFlowContainer ButtonsContainer => base.ButtonsContainer; 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"; public bool Cancelled { get; private set; }
public TestCancellableCommentEditor()
{
OnCancel = () => Cancelled = true;
}
protected override string CommitButtonText => @"Save";
protected override string TextboxPlaceholderText => @"Miltiline textboxes soon"; protected override string TextboxPlaceholderText => @"Miltiline textboxes soon";
} }
} }