public async Task FlyoutHeaderAdaptsToMinimumHeight() { await RunShellTest(shell => { var layout = new VerticalStackLayout() { new Label() { Text = "Flyout Header" } }; layout.MinimumHeightRequest = 30; shell.FlyoutHeader = layout; shell.FlyoutHeaderBehavior = FlyoutHeaderBehavior.CollapseOnScroll; }, async (shell, handler) => { await OpenFlyout(handler); var flyoutFrame = GetFrameRelativeToFlyout(handler, shell.FlyoutHeader as IView); AssertionExtensions.CloseEnough(flyoutFrame.Height, 30); }); }
public async Task FlyoutCustomContentMargin(Func <Shell, object, string> shellPart) { var baselineContent = new VerticalStackLayout() { new Label() { Text = "Flyout Layout Part" } }; Rect frameWithoutMargin = Rect.Zero; // determine the location of the templated content on the screen without a margin await RunShellTest(shell => { _ = shellPart(shell, baselineContent); }, async (shell, handler) => { await OpenFlyout(handler); frameWithoutMargin = GetFrameRelativeToFlyout(handler, baselineContent); }); var content = new VerticalStackLayout() { new Label() { Text = "Flyout Layout Part" } }; string partTesting = string.Empty; await RunShellTest(shell => { content.Margin = new Thickness(20, 30, 0, 30); partTesting = shellPart(shell, content); }, async (shell, handler) => { await OpenFlyout(handler); var frameWithMargin = GetFrameRelativeToFlyout(handler, content); var leftDiff = Math.Abs(Math.Abs(frameWithMargin.Left - frameWithoutMargin.Left) - 20); var verticalDiff = Math.Abs(Math.Abs(frameWithMargin.Top - frameWithoutMargin.Top) - 30); AssertionExtensions.AssertWithMessage(() => Assert.True(leftDiff < 0.2), $"{partTesting} Left Margin Incorrect. Frame w/ margin: {frameWithMargin}. Frame w/o marin : {frameWithoutMargin}" ); AssertionExtensions.AssertWithMessage(() => Assert.True(verticalDiff < 0.2), $"{partTesting} Top Margin Incorrect. Frame w/ margin: {frameWithMargin}. Frame w/o marin : {frameWithoutMargin}" ); }); }
public async Task GetVisualTreeElements() { SetupBuilder(); var label = new Label() { Text = "Find Me" }; var page = new ContentPage() { Title = "Title Page" }; page.Content = new VerticalStackLayout() { label }; var rootPage = await InvokeOnMainThreadAsync(() => new NavigationPage(page) ); await CreateHandlerAndAddToWindow <IWindowHandler>(rootPage, async handler => { await OnFrameSetToNotEmpty(label); var locationOnScreen = label.GetLocationOnScreen().Value; var labelFrame = label.Frame; var window = rootPage.Window; // Find label at the top left corner var topLeft = new Graphics.Point(locationOnScreen.X + 1, locationOnScreen.Y + 1); AssertionExtensions.AssertWithMessage( () => Assert.Contains(label, window.GetVisualTreeElements(topLeft)), $"Unable to find label using top left coordinate: {topLeft} with label location: {label.GetBoundingBox()}"); // find label at the bottom right corner var bottomRight = new Graphics.Point( locationOnScreen.X + labelFrame.Width - 1, locationOnScreen.Y + labelFrame.Height - 1); AssertionExtensions.AssertWithMessage( () => Assert.Contains(label, window.GetVisualTreeElements(bottomRight)), $"Unable to find label using bottom right coordinate: {bottomRight} with label location: {label.GetBoundingBox()}"); // Ensure that the point directly outside the bounds of the label doesn't // return the label Assert.DoesNotContain(label, window.GetVisualTreeElements( locationOnScreen.X + labelFrame.Width + 1, locationOnScreen.Y + labelFrame.Height + 1 )); }); }
public async Task FlyoutHeaderContentAndFooterAllMeasureCorrectly(FlyoutHeaderBehavior behavior) { await RunShellTest(shell => { shell.FlyoutHeader = new Label() { Text = "Flyout Header" }; shell.FlyoutFooter = new Label() { Text = "Flyout Footer" }; shell.FlyoutContent = new VerticalStackLayout() { new Label() { Text = "Flyout Content" } }; shell.FlyoutHeaderBehavior = behavior; }, async (shell, handler) => { await OpenFlyout(handler); var flyoutFrame = GetFlyoutFrame(handler); var headerFrame = GetFrameRelativeToFlyout(handler, (IView)shell.FlyoutHeader); var contentFrame = GetFrameRelativeToFlyout(handler, (IView)shell.FlyoutContent); var footerFrame = GetFrameRelativeToFlyout(handler, (IView)shell.FlyoutFooter); // validate header position AssertionExtensions.CloseEnough(0, headerFrame.X, message: "Header X"); AssertionExtensions.CloseEnough(0, headerFrame.Y, message: "Header Y"); AssertionExtensions.CloseEnough(flyoutFrame.Width, headerFrame.Width, message: "Header Width"); // validate content position AssertionExtensions.CloseEnough(0, contentFrame.X, message: "Content X"); AssertionExtensions.CloseEnough(headerFrame.Height, contentFrame.Y, epsilon: 0.5, message: "Content Y"); AssertionExtensions.CloseEnough(flyoutFrame.Width, contentFrame.Width, message: "Content Width"); // validate footer position AssertionExtensions.CloseEnough(0, footerFrame.X, message: "Footer X"); AssertionExtensions.CloseEnough(headerFrame.Height + contentFrame.Height, footerFrame.Y, epsilon: 0.5, message: "Footer Y"); AssertionExtensions.CloseEnough(flyoutFrame.Width, footerFrame.Width, message: "Footer Width"); //All three views should measure to the height of the flyout AssertionExtensions.CloseEnough(headerFrame.Height + contentFrame.Height + footerFrame.Height, flyoutFrame.Height, epsilon: 0.5, message: "Total Height"); }); }
public async Task FlyoutHeaderCollapsesOnScroll() { await RunShellTest(shell => { Enumerable.Range(0, 100) .ForEach(i => { shell.FlyoutHeaderBehavior = FlyoutHeaderBehavior.CollapseOnScroll; shell.Items.Add(new FlyoutItem() { Title = $"FlyoutItem {i}", Items = { new ContentPage() } }); }); var layout = new VerticalStackLayout() { new Label() { Text = "Header Content" } }; layout.HeightRequest = 250; shell.FlyoutHeader = new ScrollView() { MinimumHeightRequest = 100, Content = layout }; }, async (shell, handler) => { await OpenFlyout(handler); await Task.Delay(10); var initialBox = (shell.FlyoutHeader as IView).GetBoundingBox(); AssertionExtensions.CloseEnough(250, initialBox.Height, 0.3); await ScrollFlyoutToBottom(handler); var scrolledBox = (shell.FlyoutHeader as IView).GetBoundingBox(); AssertionExtensions.CloseEnough(100, scrolledBox.Height, 0.3); }); }
public async Task FlyoutContentSetsCorrectBottomPaddingWhenMinHeightIsSetForFlyoutHeader() { await RunShellTest(shell => { var layout = new VerticalStackLayout() { new Label() { Text = "Flyout Header" } }; layout.MinimumHeightRequest = 30; shell.FlyoutHeader = layout; shell.FlyoutFooter = new Label() { Text = "Flyout Footer" }; shell.FlyoutContent = new VerticalStackLayout() { new Label() { Text = "Flyout Content" } }; shell.FlyoutHeaderBehavior = FlyoutHeaderBehavior.CollapseOnScroll; }, async (shell, handler) => { await OpenFlyout(handler); var headerFrame = GetFrameRelativeToFlyout(handler, (IView)shell.FlyoutHeader); var contentFrame = GetFrameRelativeToFlyout(handler, (IView)shell.FlyoutContent); var footerFrame = GetFrameRelativeToFlyout(handler, (IView)shell.FlyoutFooter); // validate footer position AssertionExtensions.CloseEnough(footerFrame.Y, headerFrame.Height + contentFrame.Height); }); }
public async Task FlyoutHeaderMinimumHeight(FlyoutHeaderBehavior behavior) { await RunShellTest(shell => { var layout = new VerticalStackLayout() { new Label() { Text = "Flyout Header" } }; shell.FlyoutHeader = layout; shell.FlyoutHeaderBehavior = behavior; }, async (shell, handler) => { await OpenFlyout(handler); var flyoutFrame = GetFrameRelativeToFlyout(handler, shell.FlyoutHeader as IView); if (behavior == FlyoutHeaderBehavior.CollapseOnScroll) { // 56 was pulled from the ActionBar height on Android // and then just used across all three platforms for // the min height when using collapse on scroll AssertionExtensions.CloseEnough(56, flyoutFrame.Height); } else { AssertionExtensions.AssertWithMessage(() => Assert.True(flyoutFrame.Height < 56), $"Expected < 56 Actual: {flyoutFrame.Height}" ); } }); }
public static Task <bool> Wait(Func <bool> exitCondition, int timeout = 1000) => AssertionExtensions.Wait(exitCondition, timeout);
protected Task <bool> Wait(Func <bool> exitCondition, int timeout = 1000) => AssertionExtensions.Wait(exitCondition, timeout);