Browse Source

Assert macOS menu conventions in the main-menu UI tests

The first CI run on a macOS runner surfaced that these tests encoded
the Windows/Linux menu shape, while MainMenu.Attach intentionally
diverges on macOS: TranslateGesturesForMacOS rewrites Control to Meta
so shortcuts follow the Cmd-key convention, and PromoteHelpToMacAppMenu
moves the Help items into the application menu and drops the _Help
top-level. The tests now assert the macOS-correct expectations on
macOS, including that the Help content lands in the app menu rather
than vanishing.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/3404/head
Christoph Wille 4 weeks ago
parent
commit
3886892194
  1. 21
      ILSpy.Tests/MainWindow/MainMenuTests.cs

21
ILSpy.Tests/MainWindow/MainMenuTests.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Headless.NUnit;
using Avalonia.Input;
@ -51,8 +52,23 @@ public class MainMenuTests @@ -51,8 +52,23 @@ public class MainMenuTests
?? throw new InvalidOperationException("MainMenu.Attach should have set NativeMenu on the window");
var headers = nativeMenu.Items.OfType<NativeMenuItem>().Select(i => i.Header).ToList();
if (OperatingSystem.IsMacOS())
{
// PromoteHelpToMacAppMenu relocates the Help items into the application menu
// (macOS convention: About lives under the bold app-named menu), so _Help is
// not a window-menu top-level there.
headers.Should().Equal("_File", "_View", "_Window");
var appMenu = NativeMenu.GetMenu(Application.Current!);
appMenu.Should().NotBeNull("App.axaml declares the NativeMenu the Help items move into");
appMenu!.Items.OfType<NativeMenuItem>().Select(i => i.Header)
.Should().Contain(Resources._About, "Help content must move to the app menu, not vanish");
}
else
{
headers.Should().Equal("_File", "_View", "_Window", "_Help");
}
}
[AvaloniaTest]
public void File_Open_Carries_The_Ctrl_O_Gesture()
@ -60,6 +76,8 @@ public class MainMenuTests @@ -60,6 +76,8 @@ public class MainMenuTests
// MEF metadata's InputGestureText="Ctrl+O" on File -> Open must flow through
// MainMenu.Attach into NativeMenuItem.Gesture. On macOS Avalonia projects this
// into the system menu bar; on Windows / Linux NativeMenuBar renders inline.
// On macOS, TranslateGesturesForMacOS additionally rewrites Control to Meta so
// the shortcut follows the Cmd-key convention.
var window = AppComposition.Current.GetExport<MainWindow>();
window.Show();
@ -73,7 +91,8 @@ public class MainMenuTests @@ -73,7 +91,8 @@ public class MainMenuTests
.Single(m => string.Equals(m.Header, Resources._Open, StringComparison.Ordinal));
openItem.Gesture.Should().NotBeNull();
openItem.Gesture!.Should().Be(KeyGesture.Parse("Ctrl+O"));
var expected = OperatingSystem.IsMacOS() ? KeyGesture.Parse("Cmd+O") : KeyGesture.Parse("Ctrl+O");
openItem.Gesture!.Should().Be(expected);
}
// Avalonia's macOS NativeMenu bridge maps NativeMenuItem to NSMenuItem and sets

Loading…
Cancel
Save