Skip to content

Commit

Permalink
Update Uno sample to include a module
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 23, 2020
1 parent cb57f7e commit efa56f2
Show file tree
Hide file tree
Showing 24 changed files with 526 additions and 89 deletions.
2 changes: 1 addition & 1 deletion build/scripts/android-uitest-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ANDROID_HOME/platform-tools/adb devices

echo "Emulator started"

export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/wasm
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/android
export UNO_UITEST_PLATFORM=Android
export UNO_UITEST_ANDROIDAPK_PATH=$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.Droid/bin/Release/com.prismlibrary.helloworld-Signed.apk

Expand Down
2 changes: 1 addition & 1 deletion build/scripts/ios-uitest-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mono nuget.exe install NUnit.ConsoleRunner -Version 3.10.0

export UNO_UITEST_PLATFORM=iOS
export UNO_UITEST_IOSBUNDLE_PATH=$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.iOS/bin/iPhoneSimulator/Release/HelloUnoWorld.app
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/wasm
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/ios

mkdir -p $UNO_UITEST_SCREENSHOT_PATH

Expand Down
7 changes: 7 additions & 0 deletions e2e/Uno/HelloUnoWorld.Droid/HelloUnoWorld.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.Uwp.Managed">
<Version>2.0.1-uno.28</Version>
</PackageReference>
<PackageReference Include="Uno.UI" Version="2.0.528" />
<PackageReference Include="Uno.UI.RemoteControl" Version="2.0.528" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.32" />
Expand Down Expand Up @@ -109,6 +112,10 @@
<Project>{b2a9c972-bd7a-4a95-b62c-f8385b819900}</Project>
<Name>Prism.Uno</Name>
</ProjectReference>
<ProjectReference Include="..\ModuleA\ModuleA.csproj">
<Project>{a1ddecd2-0702-40d9-ad6f-163a86783bd2}</Project>
<Name>ModuleA</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\HelloUnoWorld.Shared\HelloUnoWorld.Shared.projitems" Label="Shared" Condition="Exists('..\HelloUnoWorld.Shared\HelloUnoWorld.Shared.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
Expand Down
12 changes: 9 additions & 3 deletions e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Prism.Modularity;
using HelloWorld.ViewModels;

namespace HelloUnoWorld
{
Expand All @@ -40,8 +42,6 @@ public App()
this.Suspending += OnSuspending;
}

public static string ViewAName = "ViewA";

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
#if __IOS__
Expand Down Expand Up @@ -113,9 +113,15 @@ protected override UIElement CreateShell()
return Container.Resolve<Shell>();
}

protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<ModuleA.ModuleAModule>(InitializationMode.OnDemand);
}

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<ViewA>(ViewAName);
containerRegistry.RegisterForNavigation<ViewA>(nameof(ViewA));
containerRegistry.RegisterForNavigation<ModulesPage, ModulesPageViewModel>();

containerRegistry.RegisterDialog<NotificationDialog, NotificationDialogViewModel>();
containerRegistry.RegisterDialog<ConfirmationDialog, ConfirmationDialogViewModel>();
Expand Down
8 changes: 8 additions & 0 deletions e2e/Uno/HelloUnoWorld.Shared/HelloUnoWorld.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
<DependentUpon>NotificationDialog.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Dialogs\NotificationDialogViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ModulesPageViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ShellViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\ModulesPage.xaml.cs">
<DependentUpon>ModulesPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Views\Shell.xaml.cs">
<DependentUpon>Shell.xaml</DependentUpon>
</Compile>
Expand All @@ -58,6 +62,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Views\ModulesPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Views\Shell.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
50 changes: 50 additions & 0 deletions e2e/Uno/HelloUnoWorld.Shared/ViewModels/ModulesPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Linq;
using Prism.Commands;
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Navigation;

namespace HelloWorld.ViewModels
{
public class ModulesPageViewModel : BindableBase, IDestructible
{
private IModuleManager _moduleManager { get; }
private IModuleCatalog _moduleCatalog { get; }

public ModulesPageViewModel(IModuleManager moduleManager, IModuleCatalog moduleCatalog)
{
_moduleManager = moduleManager;
_moduleCatalog = moduleCatalog;

_moduleManager.LoadModuleCompleted += OnModuleLoaded;
Modules = moduleCatalog.Modules;

LoadModule = new DelegateCommand<IModuleInfo>(LoadModuleExecuted);
}

private IEnumerable<IModuleInfo> _modules;
public IEnumerable<IModuleInfo> Modules
{
get => _modules;
set => SetProperty(ref _modules, value);
}

public DelegateCommand<IModuleInfo> LoadModule { get; }

private void LoadModuleExecuted(IModuleInfo moduleInfo)
{
_moduleManager.LoadModule(moduleInfo.ModuleName);
}

private void OnModuleLoaded(object sender, LoadModuleCompletedEventArgs e)
{
Modules = _moduleCatalog.Modules;
}

public void Destroy()
{
_moduleManager.LoadModuleCompleted -= OnModuleLoaded;
}
}
}
32 changes: 32 additions & 0 deletions e2e/Uno/HelloUnoWorld.Shared/Views/ModulesPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Page x:Class="HelloUnoWorld.Views.ModulesPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
xmlns:mxic="using:Microsoft.Xaml.Interactions.Core"
xmlns:modularity="using:Prism.Modularity"
xmlns:prismMvvm="using:Prism.Mvvm"
xmlns:prismI="using:Prism.Interactivity"
prismMvvm:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<ListView x:Name="listView" ItemsSource="{Binding Modules}" IsItemClickEnabled="true">
<mxi:Interaction.Behaviors>
<mxic:EventTriggerBehavior EventName="ItemClick">
<prismI:InvokeCommandAction Command="{Binding LoadModule}" TriggerParameterPath="ClickedItem" />
</mxic:EventTriggerBehavior>
</mxi:Interaction.Behaviors>
<ListView.ItemTemplate>
<DataTemplate x:DataType="modularity:IModuleInfo">
<StackPanel AutomationProperties.AutomationId="{x:Bind ModuleName}">
<TextBlock Text="{x:Bind ModuleName}" FontWeight="Bold" />
<TextBlock Text="{x:Bind State}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>
30 changes: 30 additions & 0 deletions e2e/Uno/HelloUnoWorld.Shared/Views/ModulesPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace HelloUnoWorld.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ModulesPage : Page
{
public ModulesPage()
{
this.InitializeComponent();
}
}
}
19 changes: 14 additions & 5 deletions e2e/Uno/HelloUnoWorld.Shared/Views/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" toolkit:VisibleBoundsPadding.PaddingMask="All">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ContentControl Grid.Row="1"
prismRegions:RegionManager.RegionName="ContentRegion" />
<StackPanel>
<TextBlock Text="{Binding Title}" FontSize="30" />
<StackPanel Grid.Row="1" Orientation="Vertical">
<Button x:Name="viewAButton"
Grid.Row="0"
Command="{Binding NavigateCommand}"
CommandParameter="ViewA"
Content="Navigate to Named View" />
<Button x:Name="showDialog"
Command="{Binding ShowDialogCommand}"
Content="Show Dialog" />
</StackPanel>
<Button x:Name="showModules"
Command="{Binding NavigateCommand}"
CommandParameter="ModulesPage"
Content="Modules" />
<Button x:Name="ModuleViewAButton"
Command="{Binding NavigateCommand}"
CommandParameter="ModulePageA"
Content="Navigate to Named View in Module" />
</StackPanel>
<ContentControl Grid.Row="2"
prismRegions:RegionManager.RegionName="ContentRegion" />
</Grid>
</ContentControl>
16 changes: 8 additions & 8 deletions e2e/Uno/HelloUnoWorld.UITests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace Sample.UITests
{
public class Constants
{
public readonly static string WebAssemblyDefaultUri = "http://localhost:62905/";
public readonly static string iOSAppName = "com.prismlibrary.helloworld";
public readonly static string AndroidAppName = "com.prismlibrary.helloworld";
public readonly static string iOSDeviceNameOrId = "iPad Pro (12.9-inch) (3rd generation)";
public class Constants
{
public readonly static string WebAssemblyDefaultUri = "http://localhost:62905/";
public readonly static string iOSAppName = "com.prismlibrary.helloworld";
public readonly static string AndroidAppName = "com.prismlibrary.helloworld";
public readonly static string iOSDeviceNameOrId = "iPad Pro (12.9-inch) (3rd generation)";

public readonly static Platform CurrentPlatform = Platform.Browser;
}
public readonly static Platform CurrentPlatform = Platform.Android;
}
}
26 changes: 13 additions & 13 deletions e2e/Uno/HelloUnoWorld.UITests/Dialog_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@

namespace Sample.UITests
{
public class Dialog_Tests : TestBase
{
[Test]
public void TestViewA()
{
Query testSelector = q => q.Marked("showDialog");
Query OkSelector = q => q.Marked("OKButton");
public class Dialog_Tests : TestBase
{
[Test]
public void TestViewA()
{
Query testSelector = q => q.Marked("showDialog");
Query OkSelector = q => q.Marked("OKButton");

App.WaitForElement(testSelector);
App.Screenshot("Dialog - Initial");
App.WaitForElement(testSelector);
TakeScreenshot("Initial");

App.Tap(testSelector);
App.Tap(testSelector);

App.WaitForElement(OkSelector);
App.WaitForElement(OkSelector);

App.Screenshot("Dialog - Opened");
TakeScreenshot("Opened");

App.Tap(OkSelector);

App.Screenshot("Dialog - Closed");
TakeScreenshot("Closed");
}
}
}
45 changes: 45 additions & 0 deletions e2e/Uno/HelloUnoWorld.UITests/Module_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using Uno.UITest.Helpers.Queries;
using Query = System.Func<Uno.UITest.IAppQuery, Uno.UITest.IAppQuery>;

namespace Sample.UITests
{
public class Module_Tests : TestBase
{
[Test]
public void ModulePageA()
{
Query modulesSelector = q => q.Marked("showModules");
Query testSelector = q => q.Marked("ModuleViewAButton");
Query moduleEntry = q => q.Marked("ModuleAModule");
Query endResult = q => q.Marked("ModulePageATextBlock");

TakeScreenshot("Initial");

App.WaitForElement(modulesSelector);

App.Tap(modulesSelector);

App.WaitForElement(moduleEntry);

TakeScreenshot("Opened");

App.Tap(moduleEntry);

TakeScreenshot("Tapped Module");

App.Tap(testSelector);

TakeScreenshot("Tapped ViewA");

App.WaitForElement(endResult);

App.WaitForDependencyPropertyValue(endResult, "Text", "ModulePage A");
}
}
}
28 changes: 14 additions & 14 deletions e2e/Uno/HelloUnoWorld.UITests/Region_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

namespace Sample.UITests
{
public class Region_Tests : TestBase
{
[Test]
public void TestViewA()
{
Query testSelector = q => q.Marked("viewAButton");
Query viewASelector = q => q.Marked("viewAText");
public class Region_Tests : TestBase
{
[Test]
public void TestViewA()
{
Query testSelector = q => q.Marked("viewAButton");
Query viewASelector = q => q.Marked("viewAText");

App.WaitForElement(testSelector);
App.Screenshot("TestViewA - Initial");
App.WaitForElement(testSelector);
TakeScreenshot("Initial");

App.Tap(testSelector);
App.Tap(testSelector);

App.WaitForElement(viewASelector);
App.WaitForElement(viewASelector);

App.Screenshot("TestViewA - Done");
}
}
TakeScreenshot("Done");
}
}
}
Loading

0 comments on commit efa56f2

Please sign in to comment.