1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +08:00

Changed tests.

This commit is contained in:
Terochi 2022-11-16 13:12:43 +01:00 committed by Terochi
parent 5253f5309e
commit 19dc31c7ae

View File

@ -6,6 +6,7 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -19,6 +20,8 @@ namespace osu.Game.Tests.Visual.Online
private HistoryTextBox box;
private OsuSpriteText text;
private int messageCounter;
[SetUp]
public void SetUp()
{
@ -52,6 +55,8 @@ namespace osu.Game.Tests.Visual.Online
text.FadeOutFromOne(1000, Easing.InQuint);
};
messageCounter = 0;
box.TakeFocus();
});
}
@ -97,8 +102,8 @@ namespace osu.Game.Tests.Visual.Online
public void TestFullHistory()
{
addMessages(5);
AddAssert("History saved as <1-5>", () =>
Enumerable.Range(1, 5).Select(number => $"Message {number}").SequenceEqual(box.MessageHistory));
AddAssert("History saved as <5-1>", () =>
Enumerable.Range(0, 5).Select(number => $"Message {5 - number}").SequenceEqual(box.MessageHistory));
const string temp = "Temp message";
AddStep("Set text", () => box.Text = temp);
@ -107,8 +112,8 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("Text is the same", () => box.Text == temp);
addMessages(2);
AddAssert("Overwrote history to <3-7>", () =>
Enumerable.Range(3, 5).Select(number => $"Message {number}").SequenceEqual(box.MessageHistory));
AddAssert("Overrode history to <7-3>", () =>
Enumerable.Range(0, 5).Select(number => $"Message {7 - number}").SequenceEqual(box.MessageHistory));
AddStep("Set text", () => box.Text = temp);
@ -126,63 +131,41 @@ namespace osu.Game.Tests.Visual.Online
}
[Test]
public void TestStayOnLastIndex()
public void TestOverrideFullHistory()
{
addMessages(2);
AddRepeatStep("Move to last", () => InputManager.Key(Key.Up), 2);
addMessages(5);
AddAssert("History saved as <5-1>", () =>
Enumerable.Range(0, 5).Select(number => $"Message {5 - number}").SequenceEqual(box.MessageHistory));
string lastText = string.Empty;
AddStep("Move up", () =>
{
lastText = box.Text;
InputManager.Key(Key.Up);
});
AddAssert("Text hasn't changed", () => lastText == box.Text);
addMessages(6);
AddAssert("Overrode history to <11-7>", () =>
Enumerable.Range(0, 5).Select(number => $"Message {11 - number}").SequenceEqual(box.MessageHistory));
}
[Test]
public void TestKeepOriginalMessage()
{
addMessages(1);
AddStep("Start writing", () => box.Text = "A random 文, ...");
AddStep("Move up", () => InputManager.Key(Key.Up));
AddStep("Rewrite old message", () => box.Text = "Old Message");
AddStep("Move back down", () => InputManager.Key(Key.Down));
AddAssert("Text back to previous", () => box.Text == "A random 文, ...");
}
[Test]
public void TestResetIndexOnEmpty()
public void TestResetIndex()
{
addMessages(2);
AddRepeatStep("Move up", () => InputManager.Key(Key.Up), 2);
AddRepeatStep("Move Up", () => InputManager.Key(Key.Up), 2);
AddAssert("Same as 1st message", () => box.Text == "Message 1");
AddStep("Remove text", () => box.Text = string.Empty);
AddStep("Move Up", () => InputManager.Key(Key.Up));
AddAssert("Same as previous message", () => box.Text == "Message 2");
AddStep("Move up again", () => InputManager.Key(Key.Up));
AddAssert("Back to first message", () => box.Text == "Message 2");
}
[Test]
public void TestReachingLimitOfMessages()
{
addMessages(100);
AddAssert("List is full of <100-1>", () =>
Enumerable.Range(0, 100).Select(number => $"Message {100 - number}").SequenceEqual(box.MessageHistory));
addMessages(2);
AddAssert("List is full of <102-3>", () =>
Enumerable.Range(0, 100).Select(number => $"Message {102 - number}").SequenceEqual(box.MessageHistory));
AddStep("Move Up", () => InputManager.Key(Key.Up));
AddStep("Select text", () => InputManager.Keys(PlatformAction.SelectAll));
AddStep("Replace text", () => box.Text = "New text");
AddStep("Move Up", () => InputManager.Key(Key.Up));
AddAssert("Same as previous message", () => box.Text == "Message 2");
}
private void addMessages(int count)
{
int iterations = 0;
AddRepeatStep("Add messages", () =>
{
box.Text = $"Message {++iterations}";
box.Text = $"Message {++messageCounter}";
InputManager.Key(Key.Enter);
}, count);
}