Skip to content

Commit

Permalink
Clarify test (#13363)
Browse files Browse the repository at this point in the history
* Clarify test

* - fix spelling
  • Loading branch information
PureWeen committed Feb 16, 2023
1 parent 8de6896 commit 1182230
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(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();
Expand All @@ -42,10 +44,10 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(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)
{
Expand All @@ -58,7 +60,10 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(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();
Expand All @@ -68,6 +73,7 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(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;
Expand All @@ -76,14 +82,14 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(window,
var originalDiff = Math.Abs(rootPageOffsetY - modalOffsetY);
var openDiff = Math.Abs(keyboardOpenRootPageOffsetY - keyboardOpenModalOffsetY);
return Math.Abs(originalDiff - openDiff) <= 0.2;
});
Assert.True(offsetMatchesWhenKeyboardOpened, "Modal page has an invalid offset when open");
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;
Expand All @@ -95,6 +101,7 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(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);
}
Expand Down

0 comments on commit 1182230

Please sign in to comment.