public void PointerLeave_Doesnt_Deselect_Item_If_Pointer_Over_Submenu() { var target = new DefaultMenuInteractionHandler(false); var menu = Mock.Of <IMenu>(); var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu); var item = Mock.Of <IMenuItem>(x => x.Parent == parentItem && x.HasSubMenu == true && x.IsPointerOverSubMenu == true); var e = CreateArgs(MenuItem.PointerLeaveItemEvent, item); target.PointerLeave(item, e); Mock.Get(parentItem).VerifySet(x => x.SelectedItem = null, Times.Never); Assert.False(e.Handled); }
public void PointerLeave_Deselects_Item_When_Menu_Not_Open() { var target = new DefaultMenuInteractionHandler(false); var menu = new Mock <IMenu>(); var item = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.Parent == menu.Object); var e = CreateArgs(MenuItem.PointerLeaveItemEvent, item); menu.SetupGet(x => x.SelectedItem).Returns(item); target.PointerLeave(item, e); menu.VerifySet(x => x.SelectedItem = null); Assert.False(e.Handled); }
public void PointerLeave_Deselects_Item() { var target = new DefaultMenuInteractionHandler(false); var menu = Mock.Of <IMenu>(); var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu); var item = Mock.Of <IMenuItem>(x => x.Parent == parentItem); var e = CreateArgs(MenuItem.PointerLeaveItemEvent, item); Mock.Get(parentItem).SetupGet(x => x.SelectedItem).Returns(item); target.PointerLeave(item, e); Mock.Get(parentItem).VerifySet(x => x.SelectedItem = null); Assert.False(e.Handled); }
public void PointerLeave_Doesnt_Deselect_Item_When_Menu_Open() { var target = new DefaultMenuInteractionHandler(false); var menu = new Mock <IMenu>(); var item = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.Parent == menu.Object); var e = new PointerEventArgs { RoutedEvent = MenuItem.PointerLeaveItemEvent, Source = item }; menu.SetupGet(x => x.IsOpen).Returns(true); menu.SetupGet(x => x.SelectedItem).Returns(item); target.PointerLeave(item, e); menu.VerifySet(x => x.SelectedItem = null, Times.Never); Assert.False(e.Handled); }
public void PointerLeave_Doesnt_Deselect_Sibling() { var target = new DefaultMenuInteractionHandler(false); var menu = Mock.Of <IMenu>(); var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu); var item = Mock.Of <IMenuItem>(x => x.Parent == parentItem); var sibling = Mock.Of <IMenuItem>(x => x.Parent == parentItem); var e = new PointerEventArgs { RoutedEvent = MenuItem.PointerLeaveItemEvent, Source = item }; Mock.Get(parentItem).SetupGet(x => x.SelectedItem).Returns(sibling); target.PointerLeave(item, e); Mock.Get(parentItem).VerifySet(x => x.SelectedItem = null, Times.Never); Assert.False(e.Handled); }
public void Selection_Is_Correct_When_Pointer_Temporarily_Exits_Item_To_Select_SubItem() { var timer = new TestTimer(); var target = new DefaultMenuInteractionHandler(false, null, timer.RunOnce); var menu = Mock.Of <IMenu>(); var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu); var item = Mock.Of <IMenuItem>(x => x.Parent == parentItem && x.HasSubMenu == true); var childItem = Mock.Of <IMenuItem>(x => x.Parent == item); var enter = new PointerEventArgs { RoutedEvent = MenuItem.PointerEnterItemEvent, Source = item }; var leave = new PointerEventArgs { RoutedEvent = MenuItem.PointerLeaveItemEvent, Source = item }; // Pointer enters item; item is selected. target.PointerEnter(item, enter); Assert.True(timer.ActionIsQueued); Mock.Get(parentItem).VerifySet(x => x.SelectedItem = item); Mock.Get(parentItem).ResetCalls(); // SubMenu shown after a delay. timer.Pulse(); Mock.Get(item).Verify(x => x.Open()); Mock.Get(item).SetupGet(x => x.IsSubMenuOpen).Returns(true); Mock.Get(item).ResetCalls(); // Pointer briefly exits item, but submenu remains open. target.PointerLeave(item, leave); Mock.Get(item).Verify(x => x.Close(), Times.Never); Mock.Get(item).ResetCalls(); // Pointer enters child item; is selected. enter.Source = childItem; target.PointerEnter(childItem, enter); Mock.Get(item).VerifySet(x => x.SelectedItem = childItem); Mock.Get(parentItem).VerifySet(x => x.SelectedItem = item); Mock.Get(item).ResetCalls(); Mock.Get(parentItem).ResetCalls(); }