Skip to content

Commit 6cc7f66

Browse files
RedthCopilot
andcommitted
Cover the bare MenuItem template branch
Adds the remaining flyout item shape an external backend can be handed: the bare MenuItem whose template is set on its (internal) MenuShellItem wrapper, reachable publicly as MenuItem.Parent, plus the no-template fallback for the same shape. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 37f4a9c commit 6cc7f66

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/Controls/tests/Core.UnitTests/ShellExternalFlyoutBackendTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,42 @@ public void MenuItemTemplateSetOnParentIsFoundThroughMenuItem()
193193
Assert.Equal("OnParent", ((Label)backend.CreateFlyoutItemView(menuItem)).Text);
194194
}
195195

196+
[Fact]
197+
public void BareMenuItemResolvesTemplateSetOnItsWrapper()
198+
{
199+
var shell = new Shell();
200+
shell.Items.Add(CreateShellItem());
201+
202+
var menuItem = new MenuItem { Text = "Menu" };
203+
AddMenuShellItem(shell, menuItem);
204+
205+
// The wrapper is internal, but it is reachable as the MenuItem's parent, and a template set there
206+
// has to be found when the backend is handed the bare MenuItem.
207+
var template = new DataTemplate(() => new Label { Text = "OnWrapper" });
208+
Shell.SetMenuItemTemplate(menuItem.Parent, template);
209+
210+
var backend = new FakeExternalShellFlyoutBackend(shell);
211+
212+
Assert.False(menuItem.IsSet(Shell.MenuItemTemplateProperty));
213+
Assert.Same(template, Shell.ResolveFlyoutItemTemplate(shell, menuItem));
214+
Assert.Equal("OnWrapper", ((Label)backend.CreateFlyoutItemView(menuItem)).Text);
215+
}
216+
217+
[Fact]
218+
public void BareMenuItemWithoutTemplateResolvesToNull()
219+
{
220+
var shell = new Shell();
221+
shell.Items.Add(CreateShellItem());
222+
223+
var menuItem = new MenuItem { Text = "Menu" };
224+
AddMenuShellItem(shell, menuItem);
225+
226+
var backend = new FakeExternalShellFlyoutBackend(shell);
227+
228+
Assert.Null(Shell.ResolveFlyoutItemTemplate(shell, menuItem));
229+
Assert.Equal(FakeExternalShellFlyoutBackend.PlatformDefaultText, ((Label)backend.CreateFlyoutItemView(menuItem)).Text);
230+
}
231+
196232
[Fact]
197233
public void MenuItemTemplateBindsTextAndCommandForShellContentMenuItems()
198234
{

0 commit comments

Comments
 (0)