From df039bfcbf262d539d512160dbe937a2d66e6cf7 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 16 Jan 2024 17:30:53 +0100 Subject: [PATCH 1/3] fix: Ensure ToggleMenuFlyoutItem is reported as Toggle --- src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs b/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs index 93afca5269b9..f2f082c15d89 100644 --- a/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs +++ b/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/ToggleMenuFlyoutItem.cs @@ -168,5 +168,7 @@ private void OnIsCheckedChanged(bool oldValue, bool newValue) // Create ToggleMenuFlyoutItemAutomationPeer to represent the protected override AutomationPeer OnCreateAutomationPeer() => new ToggleMenuFlyoutItemAutomationPeer(this); + + internal override bool HasToggle() => true; } } From eb7fe0f40038f7ccc0f954338ae25d4fdcf3b872 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 16 Jan 2024 17:42:54 +0100 Subject: [PATCH 2/3] test: Validate MenuFlyout toggle items --- .../Given_MenuFlyout.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs index 57f07379b8d9..db871305f460 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs @@ -422,5 +422,45 @@ public async Task When_MenuFlyout_DataContext_Changes_In_Opening() } } } + + [TestMethod] + public async Task When_Toggle_Item_HasToggle() + { + var toggleItem = new ToggleMenuFlyoutItem(); + Assert.IsTrue(toggleItem.HasToggle()); + } + + [TestMethod] + public async Task When_Menu_Contains_Toggle() + { + var menu = new MenuFlyout(); + menu.Items.Add(new MenuFlyoutItem() { Text = "Text" }); + + var trigger = new Button(); + TestServices.WindowHelper.WindowContent = trigger; + await TestServices.WindowHelper.WaitForLoaded(trigger); + + await ValidateToggleAsync(false); + + var toggleItem = new ToggleMenuFlyoutItem() { Text = "Toggle!" }; + menu.Items.Add(toggleItem); + await ValidateToggleAsync(true); + + menu.Items.Remove(toggleItem); + await ValidateToggleAsync(false); + + async Task ValidateToggleAsync(bool expected) + { + menu.ShowAt(trigger); + await TestServices.WindowHelper.WaitForIdle(); + var popups = VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot); + var popup = popups[0]; + Assert.IsInstanceOfType(popup.Child, typeof(MenuFlyoutPresenter)); + var presenter = (MenuFlyoutPresenter)popup.Child; + Assert.AreEqual(expected, presenter.GetContainsToggleItems()); + popup.IsOpen = false; + await TestServices.WindowHelper.WaitForIdle(); + } + } } } From 33bc9705a17c5ad40cb266d77aa08ee3c747343e Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 16 Jan 2024 21:10:51 +0100 Subject: [PATCH 3/3] chore: Make tests Uno-specific --- .../Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs index db871305f460..40f2a7b25d87 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_MenuFlyout.cs @@ -423,6 +423,7 @@ public async Task When_MenuFlyout_DataContext_Changes_In_Opening() } } +#if HAS_UNO [TestMethod] public async Task When_Toggle_Item_HasToggle() { @@ -462,5 +463,6 @@ async Task ValidateToggleAsync(bool expected) await TestServices.WindowHelper.WaitForIdle(); } } +#endif } }