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

Find failing Frame tests in CI #21287

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Frame/FrameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public async Task FrameRespectsMinimums()
Assert.True(100 <= layoutFrame.Width);
}

#if !WINDOWS
[Fact]
public async Task FrameDoesNotInterpretConstraintsAsMinimums()
{
Expand Down Expand Up @@ -301,6 +302,7 @@ public async Task FrameIncludesPadding()
Assert.Equal(expected, layoutFrame.Width, 1.0d);
Assert.Equal(expected, layoutFrame.Height, 1.0d);
}
#endif

#if !ANDROID && !IOS && !MACCATALYST
[Fact]
Expand Down Expand Up @@ -429,6 +431,72 @@ public async Task FramesWithinFrames(double widthConstraint, double heightConstr
Assert.True(layoutFrame.Width > minExpectedWidth);
}

#if WINDOWS

class ContentLayoutPanel : WPanel
{
IView _view;
readonly double _widthConstraint;
readonly double _heightConstraint;

public ContentLayoutPanel(IView view, double widthConstraint, double heightConstraint)
{
if (!double.IsPositiveInfinity(widthConstraint))
this.Width = widthConstraint;

if (!double.IsPositiveInfinity(heightConstraint))
this.Height = heightConstraint;

_view = view;
_widthConstraint = widthConstraint;
_heightConstraint = heightConstraint;
var platformView = view.ToPlatform();

// Just in case this view is already parented to a wrapper that's been cycled out
if (platformView.Parent is ContentLayoutPanel clp)
clp.Children.Remove(platformView);

Children.Add(platformView);
}

protected override WSize ArrangeOverride(WSize finalSize) => _view.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)).ToPlatform();

protected override WSize MeasureOverride(WSize availableSize) => _view.Measure(_widthConstraint, _heightConstraint).ToPlatform();
}

async Task<Rect> LayoutFrame(Layout layout, Frame frame, double widthConstraint, double heightConstraint, Func<Task> additionalTests = null)
{
additionalTests ??= () => Task.CompletedTask;

await InvokeOnMainThreadAsync(async () =>
{
// create platform views
layout.ToHandler(MauiContext);
frame.ToHandler(MauiContext);

await new ContentLayoutPanel(layout, widthConstraint, heightConstraint).AttachAndRun(async () =>
{
await OnFrameSetToNotEmpty(layout);
await OnFrameSetToNotEmpty(frame);

// verify that the PlatformView was measured
var frameControlSize = (frame.Handler as IPlatformViewHandler).PlatformView.GetBoundingBox();
Assert.True(frameControlSize.Width > 0);
Assert.True(frameControlSize.Height > 0);

// if the control sits inside a container make sure that also measured
var containerControlSize = frame.ToPlatform().GetBoundingBox();
Assert.True(containerControlSize.Width > 0);
Assert.True(containerControlSize.Height > 0);

await additionalTests.Invoke();
}, MauiContext);
}
);

return layout.Frame;
}
#else
async Task<Rect> LayoutFrame(Layout layout, Frame frame, double widthConstraint, double heightConstraint, Func<Task> additionalTests = null)
{
additionalTests ??= () => Task.CompletedTask;
Expand All @@ -455,5 +523,6 @@ async Task<Rect> LayoutFrame(Layout layout, Frame frame, double widthConstraint,
return layout.Frame;
});
}
#endif
}
}