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

Fix has color to use maui context on passed in view #19682

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -118,30 +118,25 @@ public async Task ShellFlyoutBackgroundInitializesCorrectly(string colorHex)
shell.Items.Add(shellItem);
});

await InvokeOnMainThreadAsync(async () =>
await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
{
await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
{
var rootNavView = handler.PlatformView;
var shellItemView = shell.CurrentItem.Handler.PlatformView as MauiNavigationView;
var expectedRoot = UI.Xaml.Controls.NavigationViewPaneDisplayMode.Left;
var expectedShellItems = UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftMinimal;

Assert.Equal(expectedRoot, rootNavView.PaneDisplayMode);
Assert.NotNull(shellItemView);
Assert.Equal(expectedShellItems, shellItemView.PaneDisplayMode);
var rootNavView = handler.PlatformView;
var shellItemView = shell.CurrentItem.Handler.PlatformView as MauiNavigationView;
var expectedRoot = UI.Xaml.Controls.NavigationViewPaneDisplayMode.Left;
var expectedShellItems = UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftMinimal;

return Task.CompletedTask;
});
Assert.Equal(expectedRoot, rootNavView.PaneDisplayMode);
Assert.NotNull(shellItemView);
Assert.Equal(expectedShellItems, shellItemView.PaneDisplayMode);

await AssertionExtensions.Wait(() =>
await AssertionExtensions.AssertEventually(() =>
{
var platformView = shell.Handler.PlatformView as FrameworkElement;
return platformView is not null && (platformView.Height > 0 || platformView.Width > 0);
var platformView = shell.CurrentPage.Handler.PlatformView as FrameworkElement;
return platformView is not null && (platformView.ActualHeight > 0 || platformView.ActualWidth > 0);
});
});

await ValidateHasColor(shell, expectedColor, typeof(ShellHandler));
await ValidateHasColor(shell, expectedColor, typeof(ShellHandler));
});
}

[Fact(DisplayName = "Back Button Enabled/Disabled")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,9 @@ await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
Assert.False(pageReference.IsAlive, "Page should not be alive!");
}

[Fact(DisplayName = "HideSoftInputOnTapped Doesnt Crash If Entry Is Still Focused After Window Is Null")]
//HideSoftInputOnTapped doesn't currently do anything on windows
#if !WINDOWS
[Fact(DisplayName = "HideSoftInputOnTapped Doesn't Crash If Entry Is Still Focused After Window Is Null")]
public async Task HideSoftInputOnTappedDoesntCrashIfEntryIsStillFocusedAfterWindowIsNull()
{
SetupBuilder();
Expand Down Expand Up @@ -1067,6 +1069,7 @@ ContentPage CreatePage(out Entry entry)
};
}
}
#endif

[Fact(DisplayName = "Can Reuse Pages")]
public async Task CanReusePages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,40 @@ protected TCustomHandler CreateHandler<THandler, TCustomHandler>(IElement elemen
return handler;
}

protected IPlatformViewHandler CreateHandler(IElement view, Type handlerType)
protected IPlatformViewHandler CreateHandler(IElement view, Type handlerType) =>
CreateHandler(view, handlerType, MauiContext);

protected IPlatformViewHandler CreateHandler(IElement view, Type handlerType, IMauiContext mauiContext)
{
if (view.Handler is IPlatformViewHandler t)
return t;

var handler = (IPlatformViewHandler)Activator.CreateInstance(handlerType);
InitializeViewHandler(view, handler, MauiContext);
InitializeViewHandler(view, handler, mauiContext);
return handler;

}

protected Task ValidateHasColor(IView view, Color color, Type handlerType, Action action = null, string updatePropertyValue = null, double? tolerance = null)
protected Task ValidateHasColor(
IView view,
Color color,
Type handlerType,
Action action = null,
string updatePropertyValue = null,
double? tolerance = null)
{
return InvokeOnMainThreadAsync(async () =>
{
var handler = CreateHandler(view, handlerType);
var mauiContext = view?.Handler?.MauiContext ?? MauiContext;
var handler = CreateHandler(view, handlerType, mauiContext);
var plaformView = handler.ToPlatform();
action?.Invoke();
if (!string.IsNullOrEmpty(updatePropertyValue))
{
handler.UpdateValue(updatePropertyValue);
}

await plaformView.AssertContainsColor(color, MauiContext, tolerance: tolerance);
await plaformView.AssertContainsColor(color, mauiContext, tolerance: tolerance);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public static async Task<T> AttachAndRun<T>(this FrameworkElement view, Func<Win
// Window is not a XAML type so is never on the hierarchy
var window = (Window)mauiContext!.Services!.GetService(typeof(Window))!;

Assert.True(window?.Content is not null,
"Content on Window has not been set. Most likely the window under test isn't being registered against the test service being used. Check if you're passing the right MauiContext in");

if (window.Content.XamlRoot != view.XamlRoot)
throw new Exception("The window retrieved from the service is different than the window this view is attached to");

Expand Down
Loading