public async Task When_Child_Added_Measure_And_Visible_Arrange() { // This test emulates the layout sequence associated with DataGridColumnHeadersPresenter in the WCT var gridAdder = new GridAdder() { MinWidth = 5, MinHeight = 5 }; TestServices.WindowHelper.WindowContent = gridAdder; await TestServices.WindowHelper.WaitForLoaded(gridAdder); await TestServices.WindowHelper.WaitFor(() => gridAdder.WasArranged); // Needed for iOS where measurement is async if (gridAdder.Exception != null) { throw new AssertFailedException("Exception occurred", gridAdder.Exception); } var SUT = gridAdder.AddedGrid; Assert.IsNotNull(SUT); Assert.AreEqual(Visibility.Visible, SUT.Visibility); #if !__ANDROID__ && !__IOS__ // The Grid contents doesn't seem to actually display properly when added this way, but at least it should not throw an exception. Assert.AreEqual(27, SUT.ActualHeight); NumberAssert.Greater(SUT.ActualWidth, 0); #endif }
private static void VerifyRelativeContentPosition(HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, FrameworkElement content, double minimumTargetOffset, Border target) { var contentScreenBounds = content.GetOnScreenBounds(); var contentCenter = contentScreenBounds.GetCenter(); var targetScreenBounds = target.GetOnScreenBounds(); var targetCenter = targetScreenBounds.GetCenter(); Assert.IsTrue(targetCenter.X > minimumTargetOffset); Assert.IsTrue(targetCenter.Y > minimumTargetOffset); switch (horizontalPosition) { case HorizontalPosition.BeyondLeft: NumberAssert.Less(contentScreenBounds.Right, targetScreenBounds.Left); break; case HorizontalPosition.LeftFlush: Assert.AreEqual(targetScreenBounds.Left, contentScreenBounds.Left, delta: 2); break; case HorizontalPosition.Center: Assert.AreEqual(targetCenter.X, contentCenter.X, delta: 2); break; case HorizontalPosition.RightFlush: Assert.AreEqual(targetScreenBounds.Right, contentScreenBounds.Right, delta: 2); break; case HorizontalPosition.BeyondRight: NumberAssert.Greater(contentScreenBounds.Left, targetScreenBounds.Right); break; } switch (verticalPosition) { case VerticalPosition.BeyondTop: NumberAssert.Less(contentScreenBounds.Bottom, targetScreenBounds.Top); break; case VerticalPosition.TopFlush: Assert.AreEqual(targetScreenBounds.Top, contentScreenBounds.Top, delta: 2); break; case VerticalPosition.Center: Assert.AreEqual(targetCenter.Y, contentCenter.Y, delta: 2); break; case VerticalPosition.BottomFlush: Assert.AreEqual(targetScreenBounds.Bottom, contentScreenBounds.Bottom, delta: 2); break; case VerticalPosition.BeyondBottom: NumberAssert.Greater(contentScreenBounds.Top, targetScreenBounds.Bottom); break; } }
public async Task Check_Dropdown_Measure_Count() { var source = Enumerable.Range(0, 500).ToArray(); var SUT = new ComboBox { ItemsSource = source, ItemsPanel = MeasureCountCarouselPanelTemplate }; try { WindowHelper.WindowContent = SUT; await WindowHelper.WaitForLoaded(SUT); Assert.AreEqual(0, MeasureCountCarouselPanel.MeasureCount); Assert.AreEqual(0, MeasureCountCarouselPanel.ArrangeCount); SUT.IsDropDownOpen = true; ComboBoxItem cbi = null; await WindowHelper.WaitFor(() => source.Any(i => (cbi = SUT.ContainerFromItem(i) as ComboBoxItem) != null)); // Windows loads up CarouselPanel with no selected item around the middle, other platforms may not await WindowHelper.WaitForLoaded(cbi); // Required on Android NumberAssert.Greater(MeasureCountCarouselPanel.MeasureCount, 0); NumberAssert.Greater(MeasureCountCarouselPanel.ArrangeCount, 0); #if __IOS__ const int MaxAllowedCount = 15; // TODO: figure out why iOS measures more times #else const int MaxAllowedCount = 5; #endif NumberAssert.Less(MeasureCountCarouselPanel.MeasureCount, MaxAllowedCount); NumberAssert.Less(MeasureCountCarouselPanel.ArrangeCount, MaxAllowedCount); } finally { SUT.IsDropDownOpen = false; WindowHelper.WindowContent = null; } }
public async Task When_Definitions_Cleared_And_Empty() { var SUT = new Grid(); var tb = new TextBlock { Text = "Text" }; AddChild(SUT, new Border { Width = 50, Height = 20 }, 0, 0); AddChild(SUT, tb, 0, 0); TestServices.WindowHelper.WindowContent = SUT; SUT.ColumnDefinitions.Clear(); await TestServices.WindowHelper.WaitForLoaded(SUT); await TestServices.WindowHelper.WaitForLoaded(tb); // Needed for iOS where measurement is async NumberAssert.Greater(tb.ActualWidth, 0); NumberAssert.Greater(tb.ActualHeight, 0); }
public async Task When_Soft_Keyboard_And_VisibleBounds() { var nativeUnsafeArea = ScreenHelper.GetUnsafeArea(); using (ScreenHelper.OverrideVisibleBounds(new Thickness(0, 38, 0, 72), skipIfHasNativeUnsafeArea: (nativeUnsafeArea.Top + nativeUnsafeArea.Bottom) > 50)) { var tb = new TextBox { Height = 1200 }; var dummyButton = new Button { Content = "Dummy" }; var SUT = new MyContentDialog { Title = "Dialog title", Content = new ScrollViewer { Content = new StackPanel { Children = { dummyButton, tb } } }, PrimaryButtonText = "Accept", SecondaryButtonText = "Nope" }; try { await ShowDialog(SUT); dummyButton.Focus(FocusState.Pointer); // Ensure keyboard is dismissed in case it is initially visible var inputPane = InputPane.GetForCurrentView(); await WindowHelper.WaitFor(() => inputPane.OccludedRect.Height == 0); var originalButtonBounds = SUT.PrimaryButton.GetOnScreenBounds(); var originalBackgroundBounds = SUT.BackgroundElement.GetOnScreenBounds(); var visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds; RectAssert.Contains(visibleBounds, originalButtonBounds); await FocusTextBoxWithSoftKeyboard(tb); var occludedRect = inputPane.OccludedRect; var shiftedButtonBounds = SUT.PrimaryButton.GetOnScreenBounds(); var shiftedBackgroundBounds = SUT.BackgroundElement.GetOnScreenBounds(); NumberAssert.Greater(originalButtonBounds.Bottom, occludedRect.Top); // Button's original position should be occluded, otherwise test is pointless NumberAssert.Greater(originalBackgroundBounds.Bottom, occludedRect.Top); // ditto background NumberAssert.Less(shiftedButtonBounds.Bottom, occludedRect.Top); // Button should be shifted to be visible (along with rest of dialog) while keyboard is open NumberAssert.Less(shiftedBackgroundBounds.Bottom, occludedRect.Top); // ditto background ; } finally { SUT.Hide(); } } }