Skip to content

Commit

Permalink
feat: Adding message dialog test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrandolph committed Jun 2, 2022
1 parent 838a053 commit ee83684
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 109 deletions.
Expand Up @@ -48,10 +48,10 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args)
notif.RouteChanged += RouteUpdated;

// Option 1: Ad-hoc hosting of Navigation
//var f = new Frame();
//_window.Content = f;
//_window.AttachServices(_host.Services);
//f.Navigate(typeof(MainPage));
var f = new Frame();
_window.Content = f;
_window.AttachServices(_host.Services);
f.Navigate(typeof(MainPage));

// Option 2: Ad-hoc hosting using root content control
//var root = new ContentControl
Expand All @@ -66,14 +66,14 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args)
//root.Host(initialRoute: "");

// Option 3: Default hosting
_window.AttachNavigation(_host.Services,
// Option 1: This requires Shell to be the first RouteMap - best for perf as no reflection required
// initialRoute: ""
// Option 2: Specify route name
// initialRoute: "Shell"
// Option 3: Specify the view model. To avoid reflection, you can still define a routemap
initialViewModel: typeof(ShellViewModel)
);
//_window.AttachNavigation(_host.Services,
// // Option 1: This requires Shell to be the first RouteMap - best for perf as no reflection required
// // initialRoute: ""
// // Option 2: Specify route name
// // initialRoute: "Shell"
// // Option 3: Specify the view model. To avoid reflection, you can still define a routemap
// initialViewModel: typeof(ShellViewModel)
// );


_window.Activate();
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.Extensions.Navigation.UI/Region.cs
Expand Up @@ -48,6 +48,7 @@ public static class Region

private static void AttachedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Console.WriteLine("******** Attached");
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
return;
Expand All @@ -73,6 +74,8 @@ private static void RegisterElement(FrameworkElement element, bool active)
existingRegion.Detach();
}
}
Console.WriteLine($"******** Region exists {existingRegion is not null}");

var region = existingRegion ?? (active ? new NavigationRegion(element) : default);
}

Expand Down
53 changes: 36 additions & 17 deletions src/Uno.Extensions.Navigation.UI/Regions/NavigationRegion.cs
Expand Up @@ -9,6 +9,7 @@ public sealed class NavigationRegion : IRegion
private IServiceProvider? _services;
private IRegion? _parent;
private bool _isRoot;
private bool _isLoaded;
public IRegion? Parent
{
get => _parent;
Expand All @@ -30,9 +31,12 @@ private set
{
get
{
if (_services is null && Parent is not null)
Console.WriteLine("******** Region Services");
if (_services is null && Parent is not null)
{
_services = Parent?.Services?.CreateNavigationScope();
Console.WriteLine("******** Nav Scope");

_services = Parent?.Services?.CreateNavigationScope();
if (_services is null)
{
return null;
Expand All @@ -51,22 +55,32 @@ private set

public ICollection<IRegion> Children { get; } = new List<IRegion>();

public NavigationRegion(FrameworkElement? view = null, IServiceProvider? services = null)
{
View = view;
if (View is not null)
{
View.Loading += ViewLoading;
View.Loaded += ViewLoaded;
public NavigationRegion(FrameworkElement? view = null, IServiceProvider? services = null)
{
Console.WriteLine($"******** Nav Region {view?.GetType().Name??"null"}");

View = view;
if (View is not null)
{
View.Loading += ViewLoading;
View.Loaded += ViewLoaded;
View.SetInstance(this);
}

if (services is not null)
{
{
InitializeRootRegion(services);
}
}
}

if (View is not null &&
View.IsLoaded)
{
Console.WriteLine("******** View is loaded");

_ = HandleLoading();
}

}
public void Detach()
{
this.Parent = null;
Expand Down Expand Up @@ -100,12 +114,15 @@ private async void ViewLoading(DependencyObject sender, object args)

private void ViewUnloaded(object sender, RoutedEventArgs e)
{
if (View is null)
if (View is null ||
!_isLoaded)
{
return;
}

View.Loading += ViewLoading;
_isLoaded = false;

View.Loading += ViewLoading;
View.Loaded += ViewLoaded;
View.Unloaded -= ViewUnloaded;

Expand All @@ -114,7 +131,8 @@ private void ViewUnloaded(object sender, RoutedEventArgs e)

private Task HandleLoading()
{
if (View is null)
Console.WriteLine($"****** Loaded {View.GetType().Name}");
if (View is null)
{
return Task.CompletedTask;
}
Expand Down Expand Up @@ -169,12 +187,13 @@ public void ReassignParent()

private async Task HandleLoaded()
{
if (View is null)
if (View is null || _isLoaded)
{
return;
}
_isLoaded = true;

View.Loading -= ViewLoading;
View.Loading -= ViewLoading;
View.Loaded -= ViewLoaded;
View.Unloaded += ViewUnloaded;

Expand Down
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="TestHarness" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="31" />
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="31" />
<application android:label="TestHarness"></application>
</manifest>
8 changes: 6 additions & 2 deletions testing/TestHarness/TestHarness.Shared/App.xaml.cs
Expand Up @@ -51,7 +51,9 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
_window = Microsoft.UI.Xaml.Window.Current;
#endif

var rootFrame = _window.Content as Frame;


var rootFrame = _window.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
Expand All @@ -71,10 +73,12 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
_window.Content = rootFrame;
}



#if !(NET6_0_OR_GREATER && WINDOWS)
if (args.UWPLaunchActivatedEventArgs.PrelaunchActivated == false)
#endif
{
{
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
Expand Down
69 changes: 64 additions & 5 deletions testing/TestHarness/TestHarness.Shared/BaseTestSectionPage.cs
Expand Up @@ -2,22 +2,81 @@

namespace TestHarness;

public class BaseTestSectionPage:Page
public partial class BaseTestSectionPage : Page
{
protected IHost? Host { get; set; }

public BaseTestSectionPage()
{
Loaded += BaseTestSectionPage_Loaded;
}

private IHostInitialization? HostInit { get; set; }
private void BaseTestSectionPage_Loaded(object sender, RoutedEventArgs e)
{
Console.WriteLine("*********** Loaded");
if (HostInit is not null)
{
Console.WriteLine("*********** HostInit is not null");

InitializeHost();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

Console.WriteLine("*********** OnNavigatedTo");
if (e.Parameter is IHostInitialization hostInit)
{
var host = hostInit.InitializeHost();
this.AttachServiceProvider(host.Services).RegisterWindow((Application.Current as App)!.Window);
HostInit = hostInit;

if (this.FindName(Constants.NavigationRoot) is DependencyObject root)
if (this.IsLoaded)
{
Console.WriteLine("*********** this. IsLoaded");

InitializeHost();
}
}
}

private bool init;
private void InitializeHost()
{
if (init)
{
return;
}
init = true;
Console.WriteLine("*********** hostInit not null");
Host = HostInit!.InitializeHost();
Console.WriteLine("*********** Host");

var win = (Application.Current as App)?.Window!;
Console.WriteLine($"*********** Win exists {win is not null}");
this.AttachServiceProvider(Host.Services).RegisterWindow(win);
Console.WriteLine("*********** Attached and Registered");

if (this.FindName(Constants.NavigationRoot) is FrameworkElement root)
{
Console.WriteLine("*********** NavigationRoot found");
if (root.IsLoaded)
{
Console.WriteLine("*********** IsLoaded");

Region.SetAttached(root, true);
}
else
{
Console.WriteLine("*********** Not Loaded");

root.Loaded += (_, _) =>
{
Console.WriteLine("*********** Now Loaded");
Region.SetAttached(root, true);
};
}
}
}
}

Expand Up @@ -17,9 +17,13 @@ public IHost InitializeHost()
{
var host = context.HostingEnvironment;
// Configure log levels for different categories of logging
logBuilder.SetMinimumLevel(host.IsDevelopment() ? LogLevel.Warning : LogLevel.Information);
logBuilder.SetMinimumLevel(host.IsDevelopment() ? LogLevel.Trace : LogLevel.Information);
})

.UseLocalization()

.UseConfiguration()

// Enable navigation, including registering views and viewmodels
.UseNavigation(RegisterRoutes)

Expand Down Expand Up @@ -67,6 +71,7 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
new RouteMap("",
Nested: new[]
{
new RouteMap("Simple", View: views.FindByViewModel<SimpleDialogsViewModel>()),
new RouteMap("Confirm", View: confirmDialog),
new RouteMap("LocalizedConfirm", View: localizedDialog)
}));
Expand Down
Expand Up @@ -6,6 +6,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
Expand All @@ -26,6 +27,9 @@
VerticalContentAlignment="Stretch"
Grid.Row="1" />

<!--uen:Region.Attached="true"-->


<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
Expand Down
Expand Up @@ -8,6 +8,12 @@ public sealed partial class MessageDialogMainPage : BaseTestSectionPage
public MessageDialogMainPage()
{
this.InitializeComponent();

//var host = (new MessageDialogHostInit()).InitializeHost();

//var win = (Application.Current as App)?.Window!;
//Console.WriteLine($"*********** Win exists {win is not null}");
//win.Content.AttachServiceProvider(host.Services).RegisterWindow(win);
}

public async void SimpleDialogsClick(object sender, RoutedEventArgs e)
Expand Down
Expand Up @@ -6,6 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
AutomationProperties.AutomationId="SimpleDialogsPage"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
Expand Down
Expand Up @@ -5,6 +5,8 @@ public sealed partial class SimpleDialogsPage : Page
{
public SimpleDialogsPage()
{
Console.WriteLine("******* Page ");

this.InitializeComponent();
}

Expand All @@ -30,4 +32,14 @@ private async void MessageDialogCodebehindCancelClick(object sender, RoutedEvent
var messageDialogResult = await this.Navigator()!.ShowMessageDialogAsync<string>(this, content: "This is Content", title: "This is title", cancellation: cancelSource.Token);
MessageDialogResultText.Text = $"Message dialog result: {messageDialogResult}";
}

public void CloseAllMessageDialogs()//object sender, RoutedEventArgs args)
{
var popups = VisualTreeHelper.GetOpenPopups(Window.Current);
foreach (var popup in popups)
{
popup.IsOpen = false;
}

}
}
Expand Up @@ -2,4 +2,8 @@

public class SimpleDialogsViewModel
{
public SimpleDialogsViewModel()
{
Console.WriteLine("******* View Model ");
}
}
3 changes: 2 additions & 1 deletion testing/TestHarness/TestHarness.Shared/GlobalUsings.cs
Expand Up @@ -20,12 +20,13 @@
global using Uno.Extensions.Hosting;
global using Uno.Extensions.Navigation;
global using Uno.Extensions.Logging;
//global using Uno.Extensions.Localization;
global using Uno.Extensions.Localization;
global using Uno.Extensions.Serialization;
global using Uno.Extensions.Navigation.Toolkit;
global using Uno.Extensions.Navigation.Regions;
global using Uno.Extensions.Navigation.UI;


global using Uno.Toolkit.UI;
global using Microsoft.Extensions.Options;
global using Uno.Extensions;
Expand Down

0 comments on commit ee83684

Please sign in to comment.