Skip to content

Commit

Permalink
Merge pull request #15079 from unoplatform/dev/mazi/togglemenu-margin
Browse files Browse the repository at this point in the history
fix: Ensure `ToggleMenuFlyoutItem` is reported as toggle
  • Loading branch information
MartinZikmund authored Jan 17, 2024
2 parents 34c5837 + 33bc970 commit 7e38d80
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,5 +422,47 @@ public async Task When_MenuFlyout_DataContext_Changes_In_Opening()
}
}
}

#if HAS_UNO
[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();
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 7e38d80

Please sign in to comment.