public async Task OnTextCleared_MultilineTextBox()
        {
            await using var recorder = new TestRecorder(App);

            //Arrange
            IVisualElement grid = await LoadXaml(@"
<Grid>
    <TextBox Style=""{StaticResource MaterialDesignFilledTextBox}""
             materialDesign:HintAssist.Hint=""Floating hint in a box""
             VerticalAlignment=""Top""/>
</Grid>");

            IVisualElement textBox = await grid.GetElement("/TextBox");

            Rect initialRect = await textBox.GetCoordinates();

            double initialHeight = await textBox.GetActualHeight();

            await textBox.SetText($"Line 1{Environment.NewLine}Line 2");

            double twoLineHeight = await textBox.GetActualHeight();

            //Act
            await textBox.SetText("");

            //Assert
            await Wait.For(async() => Assert.Equal(initialHeight, await textBox.GetActualHeight()));

            Rect rect = await textBox.GetCoordinates();

            Assert.Equal(initialRect, rect);
            recorder.Success();
        }
Ejemplo n.º 2
0
        public async Task OnGetCoordinate_ReturnsFractionalCoordinatesOfElement()
        {
            await Window.SetXamlContent(@"<Border x:Name=""MyBorder"" 
Width=""30"" Height=""40"" VerticalAlignment=""Top"" HorizontalAlignment=""Left""/>");

            IVisualElement <Border> element = await Window.GetElement <Border>("MyBorder");

            Rect initialCoordinates = await element.GetCoordinates();

            await element.SetWidth(30.7);

            await element.SetHeight(40.3);

            await element.SetMargin(new Thickness(0.1));

            Rect newCoordinates = await element.GetCoordinates();

            Assert.AreEqual(30.7, Math.Round(newCoordinates.Width, 5));
            Assert.AreEqual(40.3, Math.Round(newCoordinates.Height, 5));
            Assert.AreEqual(0.1, Math.Round(newCoordinates.Left - initialCoordinates.Left, 5));
            Assert.AreEqual(0.1, Math.Round(newCoordinates.Top - initialCoordinates.Top, 5));
        }
Ejemplo n.º 3
0
        public async Task OnGetCoordinate_ReturnsScreenCoordinatesOfElement()
        {
            await Window.SetXamlContent(@"<Border x:Name=""MyBorder"" 
Width=""30"" Height=""40"" VerticalAlignment=""Top"" HorizontalAlignment=""Left""/>");

            IVisualElement <Border> element = await Window.GetElement <Border>("MyBorder");

            Rect initialCoordinates = await element.GetCoordinates();

            await element.SetWidth(90);

            await element.SetHeight(80);

            await element.SetMargin(new Thickness(30));

            Rect newCoordinates = await element.GetCoordinates();

            Assert.AreEqual(3.0, Math.Round(newCoordinates.Width / initialCoordinates.Width));
            Assert.AreEqual(2.0, Math.Round(newCoordinates.Height / initialCoordinates.Height));
            Assert.AreEqual(initialCoordinates.Width, Math.Round(newCoordinates.Left - initialCoordinates.Left));
            Assert.AreEqual(initialCoordinates.Width, Math.Round(newCoordinates.Top - initialCoordinates.Top));
        }
Ejemplo n.º 4
0
        public async Task OnGetCoordinate_ReturnsRotatedElementLocation()
        {
            await Window.SetXamlContent(@"
<Border x:Name=""MyBorder"" Width=""30"" Height=""40"" VerticalAlignment=""Top"" HorizontalAlignment=""Left"">
    <Border.LayoutTransform>
        <RotateTransform Angle=""90"" />
    </Border.LayoutTransform>
</Border>
");

            IVisualElement <Border> element = await Window.GetElement <Border>("MyBorder");

            Rect coordinates = await element.GetCoordinates();

            Assert.AreEqual(40, Math.Round(coordinates.Width, 5));
            Assert.AreEqual(30, Math.Round(coordinates.Height, 5));
        }
Ejemplo n.º 5
0
        public static async Task MoveCursorToElement(
            this IVisualElement element, Position position = Position.Center)
        {
            if (element is null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            Rect coordinates = await element.GetCoordinates();

            Point location = position switch
            {
                Position.TopLeft => coordinates.TopLeft,
                _ => coordinates.Center()
            };

            MouseInput.MoveCursor(location);
        }