From 2aefdfcfcaec3cc9414af295d0f5468a10ab963d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 10 Apr 2025 15:51:17 +0200 Subject: [PATCH] Update Test HostApp to not use TableView --- .../CoreViews/CorePageView.cs | 45 ++++---- .../CoreViews/CoreRootPage.cs | 51 +++++---- .../tests/TestCases.HostApp/TestCases.cs | 105 +++++++++++------- 3 files changed, 117 insertions(+), 84 deletions(-) diff --git a/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs b/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs index 9f2fc6c54f1a..ffde2a5e7984 100644 --- a/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs +++ b/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs @@ -3,7 +3,7 @@ namespace Maui.Controls.Sample { - internal class CorePageView : ListView + internal class CorePageView : CollectionView { internal class GalleryPageFactory { @@ -87,43 +87,40 @@ public CorePageView(Page rootPage) var template = new DataTemplate(() => { - var cell = new TextCell(); - cell.ContextActions.Add(new MenuItem + var cell = new Grid(); + + var label = new Label { - Text = "Select Visual", - Command = new Command(async () => - { - var buttons = typeof(VisualMarker).GetProperties().Select(p => p.Name); - var selection = await rootPage.DisplayActionSheet("Select Visual", "Cancel", null, buttons.ToArray()); - if (cell.BindingContext is GalleryPageFactory pageFactory) - { - var page = pageFactory.Realize(); - if (typeof(VisualMarker).GetProperty(selection)?.GetValue(null) is IVisual visual) - { - page.Visual = visual; - } - await PushPage(page); - } - }) - }); + FontSize = 14, + VerticalOptions = LayoutOptions.Center, + Margin = new Thickness(6) + }; + + label.SetBinding(Label.TextProperty, "Title"); + label.SetBinding(Label.AutomationIdProperty, "TitleAutomationId"); + + cell.Add(label); return cell; }); - template.SetBinding(TextCell.TextProperty, "Title"); - template.SetBinding(TextCell.AutomationIdProperty, "TitleAutomationId"); - ItemTemplate = template; ItemsSource = _pages; + SelectionMode = SelectionMode.Single; - ItemSelected += (sender, args) => + SelectionChanged += (sender, args) => { if (SelectedItem == null) { return; } - var item = args.SelectedItem; + var selection = args.CurrentSelection; + + if (selection.Count == 0) + return; + + var item = args.CurrentSelection[0]; if (item is GalleryPageFactory page) { var realize = page.Realize(); diff --git a/src/Controls/tests/TestCases.HostApp/CoreViews/CoreRootPage.cs b/src/Controls/tests/TestCases.HostApp/CoreViews/CoreRootPage.cs index a1f7d5ec8cc5..a0f7ab44fa17 100644 --- a/src/Controls/tests/TestCases.HostApp/CoreViews/CoreRootPage.cs +++ b/src/Controls/tests/TestCases.HostApp/CoreViews/CoreRootPage.cs @@ -1,14 +1,14 @@ namespace Maui.Controls.Sample { - internal class CoreRootPage : Microsoft.Maui.Controls.ContentPage + internal class CoreRootPage : ContentPage { - public CoreRootPage(Microsoft.Maui.Controls.Page rootPage) + public CoreRootPage(Page rootPage) { Title = "Controls TestCases"; var corePageView = new CorePageView(rootPage); - var searchBar = new Microsoft.Maui.Controls.Entry() + var searchBar = new Entry() { AutomationId = "SearchBar" }; @@ -18,11 +18,11 @@ public CoreRootPage(Microsoft.Maui.Controls.Page rootPage) corePageView.FilterPages(e.NewTextValue); }; - var testCasesButton = new Microsoft.Maui.Controls.Button + var testCasesButton = new Button { Text = "Go to Test Cases", AutomationId = "GoToTestButton", - Command = new Microsoft.Maui.Controls.Command(async () => + Command = new Command(async () => { if (!string.IsNullOrEmpty(searchBar.Text)) { @@ -35,26 +35,37 @@ public CoreRootPage(Microsoft.Maui.Controls.Page rootPage) }) }; - var stackLayout = new Microsoft.Maui.Controls.StackLayout() + var rootLayout = new Grid(); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); + + + rootLayout.Add(testCasesButton); + Grid.SetRow(testCasesButton, 0); + + rootLayout.Add(searchBar); + Grid.SetRow(searchBar, 1); + + var gcButton = new Button { - Children = { - testCasesButton, - searchBar, - new Microsoft.Maui.Controls.Button { - Text = "Click to Force GC", - Command = new Microsoft.Maui.Controls.Command(() => { - GC.Collect (); - GC.WaitForPendingFinalizers (); - GC.Collect (); - }) - }, - corePageView - } + Text = "Click to Force GC", + Command = new Command(() => { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + }) }; + rootLayout.Add(gcButton); + Grid.SetRow(gcButton, 2); + + rootLayout.Add(corePageView); + Grid.SetRow(corePageView, 3); AutomationId = "Gallery"; - Content = stackLayout; + Content = rootLayout; } } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/TestCases.cs b/src/Controls/tests/TestCases.HostApp/TestCases.cs index 91c78f1b75fa..5c51e9fb477e 100644 --- a/src/Controls/tests/TestCases.HostApp/TestCases.cs +++ b/src/Controls/tests/TestCases.HostApp/TestCases.cs @@ -4,7 +4,7 @@ namespace Maui.Controls.Sample { public static class TestCases { - public class TestCaseScreen : TableView + public class TestCaseScreen : CollectionView { public static Dictionary PageToAction = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -44,18 +44,6 @@ void CheckInternetAndLoadPage(Type type) } } - - static TextCell MakeIssueCell(string text, string detail, Action tapped) - { - PageToAction[text] = tapped; - if (detail != null) - PageToAction[detail] = tapped; - - var cell = new TextCell { Text = text, Detail = detail }; - cell.Tapped += (s, e) => tapped(); - return cell; - } - Action ActivatePageAndNavigate(IssueAttribute issueAttribute, Type type) { Action navigationAction = null; @@ -148,7 +136,6 @@ public bool Matches(string filter) } readonly List _issues; - TableSection _section; void VerifyNoDuplicates() { @@ -170,8 +157,6 @@ public TestCaseScreen() { AutomationId = "TestCasesIssueList"; - Intent = TableIntent.Settings; - var assembly = typeof(TestCases).Assembly; #if NATIVE_AOT @@ -245,7 +230,7 @@ public void FilterIssues(string filter = null) PageToAction.Clear(); - var issueCells = Enumerable.Empty(); + var issues = Enumerable.Empty(); if (!_filterBugzilla) { @@ -253,9 +238,9 @@ public void FilterIssues(string filter = null) from issueModel in _issues where issueModel.IssueTracker == IssueTracker.Bugzilla && issueModel.Matches(filter) orderby issueModel.IssueNumber descending - select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action); + select issueModel; - issueCells = issueCells.Concat(bugzillaIssueCells); + issues = issues.Concat(bugzillaIssueCells); } if (!_filterGitHub) @@ -264,9 +249,9 @@ orderby issueModel.IssueNumber descending from issueModel in _issues where issueModel.IssueTracker == IssueTracker.Github && issueModel.Matches(filter) orderby issueModel.IssueNumber descending - select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action); + select issueModel; - issueCells = issueCells.Concat(githubIssueCells); + issues = issues.Concat(githubIssueCells); } if (!_filterManual) @@ -275,9 +260,9 @@ orderby issueModel.IssueNumber descending from issueModel in _issues where issueModel.IssueTracker == IssueTracker.ManualTest && issueModel.Matches(filter) orderby issueModel.IssueNumber descending - select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action); + select issueModel; - issueCells = issueCells.Concat(manualIssueCells); + issues = issues.Concat(manualIssueCells); } if (!_filterNone) @@ -286,24 +271,53 @@ orderby issueModel.IssueNumber descending from issueModel in _issues where issueModel.IssueTracker == IssueTracker.None && issueModel.Matches(filter) orderby issueModel.IssueNumber descending, issueModel.Description - select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action); + select issueModel; - issueCells = issueCells.Concat(untrackedIssueCells); + issues = issues.Concat(untrackedIssueCells); } - if (_section != null) + ItemTemplate = new DataTemplate(() => { - Root.Remove(_section); - } + var grid = new Grid + { + Padding = 10, + RowDefinitions = + { + new RowDefinition { Height = GridLength.Auto }, + new RowDefinition { Height = GridLength.Star } + } + }; - _section = new TableSection("Bug Repro"); + var tapGestureRecognizer = new TapGestureRecognizer(); + tapGestureRecognizer.Tapped += (sender, args) => + { + var issueModel = (IssueModel)grid.BindingContext; + issueModel.Action?.Invoke(); + }; + grid.GestureRecognizers.Add(tapGestureRecognizer); - foreach (var issueCell in issueCells) - { - _section.Add(issueCell); - } + var titleLabel = new Label + { + FontSize = 14, + FontAttributes = FontAttributes.Bold, + }; + titleLabel.SetBinding(Label.TextProperty, "IssueNumber"); + + var descriptionLabel = new Label + { + FontSize = 12, + }; + descriptionLabel.SetBinding(Label.TextProperty, "Description"); - Root.Add(_section); + grid.Add(titleLabel); + Grid.SetRow(titleLabel, 0); + grid.Add(descriptionLabel); + Grid.SetRow(descriptionLabel, 1); + + return grid; + }); + + ItemsSource = issues; } HashSet _exemptNames = new HashSet { }; @@ -316,7 +330,13 @@ from issueModel in _issues public static NavigationPage GetTestCases() { TestCaseScreen testCaseScreen = null; - var rootLayout = new StackLayout(); + var rootLayout = new Grid(); + + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); var testCasesRoot = new ContentPage { @@ -352,7 +372,6 @@ public static NavigationPage GetTestCases() System.Diagnostics.Debug.WriteLine(e.Message); Console.WriteLine(e.Message); } - }) }; @@ -364,14 +383,21 @@ public static NavigationPage GetTestCases() }; rootLayout.Children.Add(leaveTestCasesButton); + Grid.SetRow(leaveTestCasesButton, 0); + rootLayout.Children.Add(searchBar); - rootLayout.Children.Add(searchButton); + Grid.SetRow(searchBar, 1); - testCaseScreen = new TestCaseScreen(); + rootLayout.Children.Add(searchButton); + Grid.SetRow(searchButton, 2); - rootLayout.Children.Add(CreateTrackerFilter(testCaseScreen)); + var trackerFilter = CreateTrackerFilter(testCaseScreen); + rootLayout.Children.Add(trackerFilter); + Grid.SetRow(trackerFilter, 3); + testCaseScreen = new TestCaseScreen(); rootLayout.Children.Add(testCaseScreen); + Grid.SetRow(testCaseScreen, 4); searchBar.TextChanged += (sender, args) => SearchBarOnTextChanged(sender, args, testCaseScreen); @@ -434,5 +460,4 @@ static void SearchBarOnTextChanged(object sender, TextChangedEventArgs textChang cases.FilterIssues(filter); } } - } \ No newline at end of file