From 1182230553b00c41f1a1bbdbcafba20ea981285b Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 16 Feb 2023 10:21:10 -0600 Subject: [PATCH] Clarify test (#13363) * Clarify test * - fix spelling --- .../Elements/Modal/ModalTests.Android.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Android.cs index 7c9f28ac6e73..e62a0dd7ce05 100644 --- a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Android.cs @@ -34,6 +34,8 @@ await CreateHandlerAndAddToWindow(window, Content = layout }; + // Add enough entries into the stack layout so that we can + // guarantee we'll have entries that would be covered by the keyboard for (int i = 0; i < 30; i++) { var entry = new Entry(); @@ -42,10 +44,10 @@ await CreateHandlerAndAddToWindow(window, } await navPage.CurrentPage.Navigation.PushModalAsync(modalPage); - await OnLoadedAsync(entries[0]); + await OnNavigatedToAsync(modalPage); + // Locate the lowest visible entry var pageBoundingBox = modalPage.GetBoundingBox(); - Entry testEntry = entries[0]; foreach (var entry in entries) { @@ -58,7 +60,10 @@ await CreateHandlerAndAddToWindow(window, testEntry = entry; } + // Ensure that the keyboard is closed before we start await AssertionExtensions.HideKeyboardForView(testEntry); + + // determine the screen dimensions with no keyboard open var rootPageOffsetY = navPage.CurrentPage.GetLocationOnScreen().Value.Y; var modalOffsetY = modalPage.GetLocationOnScreen().Value.Y; var originalModalPageSize = modalPage.GetBoundingBox(); @@ -68,6 +73,7 @@ await CreateHandlerAndAddToWindow(window, // Type text into the entries testEntry.Text = "Typing"; + // Wait for the size of the screen to settle after the keyboard has opened bool offsetMatchesWhenKeyboardOpened = await AssertionExtensions.Wait(() => { var keyboardOpenRootPageOffsetY = navPage.CurrentPage.GetLocationOnScreen().Value.Y; @@ -76,7 +82,6 @@ await CreateHandlerAndAddToWindow(window, var originalDiff = Math.Abs(rootPageOffsetY - modalOffsetY); var openDiff = Math.Abs(keyboardOpenRootPageOffsetY - keyboardOpenModalOffsetY); - return Math.Abs(originalDiff - openDiff) <= 0.2; }); @@ -84,6 +89,7 @@ await CreateHandlerAndAddToWindow(window, await AssertionExtensions.HideKeyboardForView(testEntry); + // Wait for the size of the screen to settle after the keyboard has closed bool offsetMatchesWhenKeyboardClosed = await AssertionExtensions.Wait(() => { var keyboardClosedRootPageOffsetY = navPage.CurrentPage.GetLocationOnScreen().Value.Y; @@ -95,6 +101,7 @@ await CreateHandlerAndAddToWindow(window, Assert.True(offsetMatchesWhenKeyboardClosed, "Modal page failed to return to expected offset"); + // Make sure that everything has returned to the initial size once the keyboard has closed var finalModalPageSize = modalPage.GetBoundingBox(); Assert.Equal(originalModalPageSize, finalModalPageSize); }