Ejemplo n.º 1
0
        public void TestDisableAndSetText()
        {
            InsertableTextBox textBox = null;

            AddStep("add text box", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40),
                    Text = "hello"
                });
            });
            AddAssert("text is hello", () => textBox.Text == "hello");

            AddStep("set new text and disable", () =>
            {
                textBox.Text             = "goodbye";
                textBox.Current.Disabled = true;
            });
            AddAssert("text is goodbye", () => textBox.Text == "goodbye");

            AddStep("attempt to set text", () => textBox.Text = "change!");
            AddAssert("text is unchanged", () => textBox.Text == "goodbye");

            AddStep("attempt to insert text", () => textBox.InsertString("maybe this way?"));
            AddAssert("text is unchanged", () => textBox.Text == "goodbye");
        }
Ejemplo n.º 2
0
        public void TestRemoveAndPrepend()
        {
            InsertableTextBox textBox = null;

            AddStep("add textbox", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40),
                });
            });

            AddStep("focus textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            AddStep("insert word", () => textBox.InsertString("eventext"));
            AddStep("remove 2 letters", () => removeLastCharacters(2));
            AddStep("prepend string", () => prependString(textBox, "xt"));
            AddStep("remove 2 letters", () => removeLastCharacters(2));
            AddStep("prepend string", () => prependString(textBox, "te"));
            AddStep("remove 2 letters", () => removeLastCharacters(2));
            AddStep("prepend string", () => prependString(textBox, "en"));
            AddStep("remove 2 letters", () => removeLastCharacters(2));
            AddStep("prepend string", () => prependString(textBox, "ev"));
            AddAssert("is correct displayed text", () => textBox.FlowingText == "eventext" && textBox.FlowingText == textBox.Text);
        }
Ejemplo n.º 3
0
        public void TestReplaceSelectionWhileLimited()
        {
            InsertableTextBox textBox = null;

            AddStep("add limited textbox", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40),
                    Text = "some text",
                });

                textBox.LengthLimit = textBox.Text.Length;
            });

            AddStep("focus textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            AddStep("select all", () => InputManager.Keys(PlatformAction.SelectAll));
            AddStep("insert string", () => textBox.InsertString("another"));
            AddAssert("text replaced", () => textBox.FlowingText == "another" && textBox.FlowingText == textBox.Text);
        }
Ejemplo n.º 4
0
        public void TestNextWordDeletionWithShortWords()
        {
            InsertableTextBox textBox = null;

            AddStep("add textbox", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40)
                });
            });

            AddStep("click on textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            AddStep("insert three words", () => textBox.InsertString("a b c"));
            AddStep("move caret to start", () => InputManager.Keys(PlatformAction.MoveBackwardLine));
            AddStep("delete first word", () => InputManager.Keys(PlatformAction.DeleteForwardWord));
            AddAssert("two words remain", () => textBox.Text == " b c");
            AddStep("delete first word", () => InputManager.Keys(PlatformAction.DeleteForwardWord));
            AddAssert("one word remains", () => textBox.Text == " c");
            AddStep("delete first word", () => InputManager.Keys(PlatformAction.DeleteForwardWord));
            AddAssert("text is empty", () => textBox.Text.Length == 0);
            AddStep("delete first word", () => InputManager.Keys(PlatformAction.DeleteForwardWord));
            AddAssert("text is empty", () => textBox.Text.Length == 0);
        }
Ejemplo n.º 5
0
        public void TestPreviousWordDeletion()
        {
            InsertableTextBox textBox = null;

            AddStep("add textbox", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40),
                });
            });

            AddStep("click on textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            AddStep("insert three words", () => textBox.InsertString("some long text"));
            AddStep("delete last word", () => InputManager.Keys(PlatformAction.DeleteBackwardWord));
            AddAssert("two words remain", () => textBox.Text == "some long ");
            AddStep("delete last word", () => InputManager.Keys(PlatformAction.DeleteBackwardWord));
            AddAssert("one word remains", () => textBox.Text == "some ");
            AddStep("delete last word", () => InputManager.Keys(PlatformAction.DeleteBackwardWord));
            AddAssert("text is empty", () => textBox.Text.Length == 0);
            AddStep("delete last word", () => InputManager.Keys(PlatformAction.DeleteBackwardWord));
            AddAssert("text is empty", () => textBox.Text.Length == 0);
        }
Ejemplo n.º 6
0
        public void TestNextWordDeletion()
        {
            InsertableTextBox textBox = null;

            AddStep("add textbox", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40)
                });
            });

            AddStep("click on textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            AddStep("insert three words", () => textBox.InsertString("some long text"));
            AddStep("move caret to start", () => textBox.MoveToStart());
            AddStep("delete first word", () => textBox.DeleteNextWord());
            AddAssert("two words remain", () => textBox.Text == " long text");
            AddStep("delete first word", () => textBox.DeleteNextWord());
            AddAssert("one word remains", () => textBox.Text == " text");
            AddStep("delete first word", () => textBox.DeleteNextWord());
            AddAssert("text is empty", () => textBox.Text.Length == 0);
            AddStep("delete first word", () => textBox.DeleteNextWord());
            AddAssert("text is empty", () => textBox.Text.Length == 0);
        }
Ejemplo n.º 7
0
        public void TestValueCorrectionViaCurrent()
        {
            InsertableTextBox textBox = null;

            AddStep("add textbox", () => textBoxes.AddRange(new[]
            {
                textBox = new InsertableTextBox
                {
                    Text = "24",
                    Size = new Vector2(500, 30),
                    TabbableContentContainer = textBoxes
                },
            }));

            AddStep("register current callback", () => textBox.Current.BindValueChanged(text =>
            {
                if (string.IsNullOrEmpty(text.NewValue))
                {
                    return;
                }

                if (!int.TryParse(text.NewValue, out int value) || value > 100)
                {
                    textBox.Current.Value = "0";
                }
            }));

            AddStep("click textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });
            AddStep("insert digit", () => textBox.InsertString("9"));
            AddUntilStep("textbox value is 0", () => textBox.Current.Value == "0");
            AddUntilStep("caret is in correct position", () =>
            {
                var spriteText = textBox.ChildrenOfType <SpriteText>().SingleOrDefault(text => text.Text == "0");
                var caret      = textBox.ChildrenOfType <Caret>().Single();

                return(spriteText != null && Precision.AlmostEquals(
                           spriteText.ScreenSpaceDrawQuad.TopRight.X,
                           caret.ScreenSpaceDrawQuad.TopLeft.X,
                           5f));
            });
        }
Ejemplo n.º 8
0
        public void TestBackspaceWhileShifted()
        {
            InsertableTextBox textBox = null;

            AddStep("add textbox", () =>
            {
                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Size = new Vector2(200, 40),
                });
            });

            AddStep("click on textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            AddStep("type character", () =>
            {
                // tests don't actually send consumable text, but this important part is that we fire the key event to begin consuming.
                InputManager.Key(Key.A);
                textBox.Text += "a";
            });

            AddStep("backspace character", () => InputManager.Key(Key.BackSpace));
            AddAssert("character removed", () => textBox.Text == string.Empty);

            AddStep("shift down", () => InputManager.PressKey(Key.ShiftLeft));

            AddStep("type character", () =>
            {
                InputManager.Key(Key.A);
                textBox.Text += "A";
            });

            AddStep("backspace character", () => InputManager.Key(Key.BackSpace));
            AddAssert("character removed", () => textBox.Text == string.Empty);

            AddStep("shift up", () => InputManager.ReleaseKey(Key.ShiftLeft));
        }
Ejemplo n.º 9
0
        public void TestInputOverride()
        {
            InsertableTextBox overrideInputBox = null;

            AddStep("add override textbox", () =>
            {
                textBoxes.Add(overrideInputBox = new InsertableTextBox
                {
                    Text = @"Override input textbox",
                    Size = new Vector2(500, 30),
                    TabbableContentContainer = textBoxes
                });
                overrideInputBox.Current.BindValueChanged(vce =>
                {
                    if (vce.NewValue != @"Input overridden!")
                    {
                        overrideInputBox.Current.Value = @"Input overridden!";
                    }
                });
            });

            AddStep(@"set some text", () => overrideInputBox.Text = "smth");
            AddAssert(@"verify display state", () => overrideInputBox.FlowingText == "Input overridden!");
        }
Ejemplo n.º 10
0
        private void appendString(InsertableTextBox textBox, string text)
        {
            InputManager.Keys(PlatformAction.MoveForwardLine);

            ScheduleAfterChildren(() => textBox.InsertString(text));
        }
Ejemplo n.º 11
0
        public void CommitOnFocusLost(bool commitOnFocusLost, bool changeText)
        {
            InsertableTextBox textBox = null;

            bool wasNewText  = false;
            int  commitCount = 0;

            AddStep("add commit on unfocus textbox", () =>
            {
                wasNewText  = false;
                commitCount = 0;

                textBoxes.Add(textBox = new InsertableTextBox
                {
                    Text = "Default Text",
                    CommitOnFocusLost = commitOnFocusLost,
                    Size = new Vector2(500, 30),
                });

                textBox.OnCommit += (_, newText) =>
                {
                    commitCount++;
                    wasNewText = newText;
                };
            });

            AddAssert("ensure no commits", () => commitCount == 0);

            AddStep("click on textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            if (changeText)
            {
                AddStep("insert more text", () => textBox.InsertString(" Plus More"));
            }

            AddStep("click away", () =>
            {
                InputManager.MoveMouseTo(Vector2.One);
                InputManager.Click(MouseButton.Left);
            });

            if (commitOnFocusLost)
            {
                AddAssert("ensure one commit", () => commitCount == 1);
                AddAssert("ensure new text", () => wasNewText == changeText);
            }
            else
            {
                AddAssert("ensure no commits", () => commitCount == 0);
            }

            AddStep("click on textbox", () =>
            {
                InputManager.MoveMouseTo(textBox);
                InputManager.Click(MouseButton.Left);
            });

            if (changeText)
            {
                AddStep("insert more text", () => textBox.InsertString(" Plus More"));
            }

            AddStep("commit via enter", () =>
            {
                InputManager.PressKey(Key.Enter);
                InputManager.ReleaseKey(Key.Enter);
            });

            int expectedCount = 1 + (commitOnFocusLost ? 1 : 0);

            AddAssert($"ensure {expectedCount} commit(s)", () => commitCount == expectedCount);
            AddAssert("ensure new text", () => wasNewText == changeText);
        }