Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify test #13363

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Entry's that would be covered by the keyboard
Redth marked this conversation as resolved.
Show resolved Hide resolved
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