Skip to content
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
79 changes: 79 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20685.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 20685, "MenuBarItem Commands not working on Mac Catalyst",
PlatformAffected.All)]
public class Issue20685 : TestShell
{
protected override void Init()
{
var resultLabel = new Label
{
Text = "No action performed yet",
FontSize = 18,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "ResultLabel"
};

var menuItems = new MenuBarItem { Text = "MenuItems" };


// 1. Menu item using Clicked event
var clickedItem = new MenuFlyoutItem
{
Text = "Test Clicked Event",
AutomationId = "ClickedEventItem"
};
clickedItem.Clicked += (s, e) => resultLabel.Text = "Clicked event handler executed";
menuItems.Add(clickedItem);

// 2. Menu item using Command
var commandItem = new MenuFlyoutItem
{
Text = "Test Command",
AutomationId = "CommandItem",
Command = new Command(() => resultLabel.Text = "Command executed")
};
menuItems.Add(commandItem);

// 3. Menu item using Command with parameter
var parameterItem = new MenuFlyoutItem
{
Text = "Test Command Parameter",
AutomationId = "CommandWithParamItem",
Command = new Command<string>(param => resultLabel.Text = $"Command executed with parameter: {param}"),
CommandParameter = "Test Parameter"
};
menuItems.Add(parameterItem);

MenuBarItems.Add(menuItems);

var contentPage = new ContentPage
{
Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Spacing = 20,
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Center,
Children =
{
new Label
{
Text = "MenuFlyoutItem Test",
FontSize = 24,
HorizontalOptions = LayoutOptions.Center
},
resultLabel,
new Label
{
Text = "Use the menu bar at the top to test the commands",
HorizontalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.Center
}
}
}
};

AddContentPage(contentPage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#if MACCATALYST || WINDOWS // MenuBarItems are only supported on desktop platforms
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

[Category(UITestCategories.Shell)]
public class Issue20685 : _IssuesUITest
{

public const string ResultLabel = "ResultLabel";
public const string MenuItems = "MenuItems";
public const string ClickedEventItem = "Test Clicked Event";
public const string CommandItem = "Test Command";
public const string CommandWithParamItem = "Test Command Parameter";

public Issue20685(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "MenuBarItem Commands not working on Mac Catalyst";

private void OpenMenuAndTapItem(string menuItem)
{
App.WaitForElement(MenuItems);
App.Tap(MenuItems);
App.WaitForElement(menuItem);
App.Tap(menuItem);
}

[Test]
public void MenuFlyoutItem_ClickedEventWorks()
{
OpenMenuAndTapItem(ClickedEventItem);
Assert.That(App.WaitForElement(ResultLabel)?.GetText(), Is.EqualTo("Clicked event handler executed"));
}

[Test]
public void MenuFlyoutItem_CommandWorks()
{
OpenMenuAndTapItem(CommandItem);
Assert.That(App.WaitForElement(ResultLabel)?.GetText(), Is.EqualTo("Command executed"));
}

[Test]
public void MenuFlyoutItem_CommandWithParameterWorks()
{
OpenMenuAndTapItem(CommandWithParamItem);
Assert.That(App.WaitForElement(ResultLabel)?.GetText(), Is.EqualTo("Command executed with parameter: Test Parameter"));
}
}

#endif
Loading