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

[Windows] Fix for SearchHandler Fails to Display Results. #26572

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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.
Loading