Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding textBox pointer test #18931

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;
using SamplesApp.UITests.Extensions;
using SamplesApp.UITests.TestFramework;
using Uno.UITest;
using Uno.UITest.Helpers;
Expand Down Expand Up @@ -992,5 +993,25 @@ public void TextBox_Selection_IsReadOnly()
// Final verification of SelectedText
Assert.IsNotEmpty(readonlyTextBox.GetDependencyPropertyValue("SelectedText")?.ToString());
}

[Test]
[AutoRetry]
public void When_ClickAndDrag_SelectsDefaultText()
{

Run("UITests.Shared.Windows_UI_Input.PointersTests.TextBox_Pointer");

_app.WaitForElement("TestTextBox");

var textBoxRect = _app.GetPhysicalRect("TestTextBox");

var startPoint = textBoxRect.GetPointInRect(new System.Drawing.PointF(0.1f, 0.5f));
var endPoint = textBoxRect.GetPointInRect(new System.Drawing.PointF(0.9f, 0.5f));

_app.DragCoordinates(startPoint, endPoint);

var resultText = _app.GetText("ResultText");
Assert.AreEqual("Pointer Released - No text selected", resultText, "Dragging should not select text.");
}
}
}
13 changes: 10 additions & 3 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)windows_ui_input\pointerstests\TextBox_Pointer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Input\SetProtectedCursor.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -2381,7 +2385,7 @@
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\PersonPictureTests\PersonPictureLateBindingPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Pivot\Pivot_CustomContent_Automated.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -6185,6 +6189,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Input\PointersTests\ScrollViewer_PointerMoved.xaml.cs">
<DependentUpon>ScrollViewer_PointerMoved.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)windows_ui_input\pointerstests\TextBox_Pointer.xaml.cs">
<DependentUpon>TextBox_Pointer.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Input\SetProtectedCursor.xaml.cs">
<DependentUpon>SetProtectedCursor.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -7192,7 +7199,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\PersonPictureTests\PersonPictureLateBindingPage.xaml.cs">
<DependentUpon>PersonPictureLateBindingPage.xaml</DependentUpon>
</Compile>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Pivot\Pivot_CustomContent_Automated.xaml.cs">
<DependentUpon>Pivot_CustomContent_Automated.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -9898,4 +9905,4 @@
</Compile>
</ItemGroup>
<Import Project="ItemExclusions.props" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Page x:Class="UITests.Shared.Windows_UI_Input.PointersTests.TextBox_Pointer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_UI_Input.PointersTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>
<StackPanel Orientation="Horizontal"
Margin="0,20">
<Border x:Name="TestTextBoxBorder"
Background="LightGray"
Width="300"
Height="50">
<TextBox x:Name="TestTextBox"
Text="Default Text"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Border>

<TextBlock x:Name="ResultText"
Text="No action yet"
Margin="10,0,0,0" />
</StackPanel>
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Uno.UI.Samples.Controls;
using Windows.Foundation;

namespace UITests.Shared.Windows_UI_Input.PointersTests
{
[Sample("Pointers",Description = "This sample tests an issue where dragging on a TextBox selects text incorrectly. To ensures that dragging across the TextBox does not select text unless explicitly selected.")]
public sealed partial class TextBox_Pointer : Page
{
public TextBox_Pointer()
{
this.InitializeComponent();
SetupPointerEvents();
}

private void SetupPointerEvents()
{
TestTextBoxBorder.PointerPressed += OnPointerPressed;
TestTextBoxBorder.PointerMoved += OnPointerMoved;
TestTextBoxBorder.PointerReleased += OnPointerReleased;
}

private bool _isDragging;
private Point? _initialPoint;

private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
_initialPoint = e.GetCurrentPoint(TestTextBoxBorder).Position;
_isDragging = false;
ResultText.Text = "Pointer Pressed";
}

private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
if (_initialPoint is Point initialPoint)
{
var currentPoint = e.GetCurrentPoint(TestTextBoxBorder).Position;

if (Math.Abs(currentPoint.X - initialPoint.X) > 2 || Math.Abs(currentPoint.Y - initialPoint.Y) > 2)
{
_isDragging = true;
ResultText.Text = "Pointer Dragging";
}
}
}

private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{
if (_isDragging)
{
var selectedText = TestTextBox.SelectedText;
ResultText.Text = string.IsNullOrEmpty(selectedText)
? "Pointer Released - No text selected"
: $"Pointer Released - Selected Text: '{selectedText}'";
}
else
{
ResultText.Text = "Pointer Released - No drag detected";
}

_isDragging = false;
_initialPoint = null;
}
}
}
Loading