public async Task When_DefaultButton_Not_Set() { var SUT = new MyContentDialog { Title = "Dialog title", Content = "Dialog content", PrimaryButtonText = "Accept", SecondaryButtonText = "Nope" }; Assert.AreEqual(ContentDialogButton.None, SUT.DefaultButton); try { await ShowDialog(SUT); Assert.IsNotNull(SUT.PrimaryButton); var fg = SUT.PrimaryButton.Foreground as SolidColorBrush; Assert.IsNotNull(fg); Assert.AreEqual(Colors.Black, fg.Color); } finally { SUT.Hide(); } }
public async Task When_FullSizeDesired() { var SUT = new MyContentDialog { Title = "Dialog title", Content = "Dialog content", PrimaryButtonText = "Accept", SecondaryButtonText = "Nope" }; SUT.FullSizeDesired = true; try { await ShowDialog(SUT); Assert.IsNotNull(SUT.BackgroundElement); var actualHeight = SUT.BackgroundElement.ActualHeight; Assert.IsTrue(actualHeight > 0); // Is displayed Assert.IsTrue(actualHeight > 400); // Is stretched to full size } finally { SUT.Hide(); } }
public async Task When_CloseDeferred() { var SUT = new MyContentDialog { Title = "Dialog title", Content = "Dialog content", PrimaryButtonText = "Accept", SecondaryButtonText = "Nope" }; bool triggered = false; bool hideSecondTime = false; async void SUT_Closing(object sender, ContentDialogClosingEventArgs args) { // Closing should only be invoked once. Assert.IsFalse(triggered); triggered = true; var deferral = args.GetDeferral(); await WindowHelper.WaitFor(() => hideSecondTime); deferral.Complete(); triggered = false; }; SUT.Closing += SUT_Closing; try { await ShowDialog(SUT); SUT.Hide(); await WindowHelper.WaitFor(() => triggered); SUT.Hide(); hideSecondTime = true; } finally { SUT.Closing -= SUT_Closing; SUT.Hide(); } }
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(); } } }