Skip to content

Commit

Permalink
[Windows] Fix for SearchHandler Fails to Display Results. (#26572)
Browse files Browse the repository at this point in the history
* SearchHandler fix

* Removed the test case.

* Removed snapshots

* Test sample changes

* Added snapshot for Windows
  • Loading branch information
Tamilarasan-Paranthaman authored Jan 10, 2025
1 parent bff4ab0 commit 06cccd4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
15 changes: 11 additions & 4 deletions src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void UpdateSearchHandler()
autoSuggestBox.PlaceholderText = _currentSearchHandler.Placeholder;
autoSuggestBox.IsEnabled = _currentSearchHandler.IsSearchEnabled;
autoSuggestBox.ItemsSource = CreateSearchHandlerItemsSource();
autoSuggestBox.ItemTemplate = (UI.Xaml.DataTemplate)WApp.Current.Resources["SearchHandlerItemTemplate"];
autoSuggestBox.ItemTemplate = _currentSearchHandler.ItemTemplate is null ? null : (UI.Xaml.DataTemplate)WApp.Current.Resources["SearchHandlerItemTemplate"];
autoSuggestBox.Text = _currentSearchHandler.Query;
autoSuggestBox.UpdateTextOnSelect = false;

Expand Down Expand Up @@ -338,11 +338,18 @@ void OnSearchBoxQuerySubmitted(Microsoft.UI.Xaml.Controls.AutoSuggestBox sender,
if (_currentSearchHandler == null)
return null;

if (_currentSearchHandler.ItemsSource == null)
return _currentSearchHandler.ItemsSource;
var itemsSource = _currentSearchHandler.ItemsSource;
var itemTemplate = _currentSearchHandler.ItemTemplate;

return TemplatedItemSourceFactory.Create(_currentSearchHandler.ItemsSource, _currentSearchHandler.ItemTemplate, _currentSearchHandler,
if (itemTemplate is not null && itemsSource is not null)
{
return TemplatedItemSourceFactory.Create(itemsSource, itemTemplate, _currentSearchHandler,
null, null, null, MauiContext);
}
else
{
return itemsSource;
}
}

void OnCurrentSearchHandlerPropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_CATALYST // In Android and Catalyst AutomationId is not working for SearchHandler, in Windows searchresults was not shown More Information: https://github.com/dotnet/maui/issues/26477
using UITest.Appium;
using NUnit.Framework;
using UITest.Appium;
using NUnit.Framework;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
Expand All @@ -13,15 +12,32 @@ public ShellSearchHandlerItemSizing(TestDevice testDevice) : base(testDevice)

public override string Issue => "Shell Search Handler Item Sizing";

#if IOS || MACCATALYST
[Test]
[Category(UITestCategories.Shell)]
public void SearchHandlerSizesCorrectly()
{
App.WaitForElement("Instructions");
App.EnterText(AppiumQuery.ByXPath("//XCUIElementTypeSearchField"),"Hello");
App.EnterText(AppiumQuery.ByXPath("//XCUIElementTypeSearchField"), "Hello");
var contentSize = App.WaitForElement("searchresult").GetRect();
Assert.That(contentSize.Height, Is.LessThan(100));
}
#endif

// For Windows and Android, the test is failing because it cannot retrieve the search result.
// Therefore, verify it using VerifyScreenshot.
#if ANDROID || WINDOWS
[Test]
[Category(UITestCategories.Shell)]
public void VerifySearchHandlerItemsAreVisible()
{
App.WaitForElement("Instructions");
#if WINDOWS
App.EnterText("TextBox", "Hello");
#else
App.EnterText(AppiumQuery.ByXPath("//android.widget.EditText"), "Hello");
#endif
VerifyScreenshot();
}
}
#endif
#endif
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06cccd4

Please sign in to comment.