-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/CommunityToolkit.Maui.DeviceTests/CommunityToolkit.Maui.DeviceTests/BaseUITest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Xunit; | ||
|
||
namespace CommunityToolkit.Maui.DeviceTests; | ||
[Collection("UITests")] | ||
public abstract class UITests<T> : IAsyncLifetime | ||
where T : Page | ||
{ | ||
protected T CurrentPage { get; private set; } = default!; | ||
|
||
protected IMauiContext MauiContext { get; private set; } = default!; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
Routing.RegisterRoute("uitests", typeof(T)); | ||
|
||
await Shell.Current.GoToAsync("uitests"); | ||
|
||
CurrentPage = (T)Shell.Current.CurrentPage; | ||
MauiContext = CurrentPage.Handler!.MauiContext!; | ||
if (CurrentPage.IsLoaded) | ||
{ | ||
return; | ||
} | ||
|
||
var tcs = new TaskCompletionSource(); | ||
CurrentPage.Loaded += OnLoaded; | ||
|
||
await Task.WhenAny(tcs.Task, Task.Delay(1000)); | ||
|
||
CurrentPage.Loaded -= OnLoaded; | ||
|
||
Assert.True(CurrentPage.IsLoaded); | ||
|
||
void OnLoaded(object? sender, EventArgs e) | ||
{ | ||
CurrentPage.Loaded -= OnLoaded; | ||
tcs.SetResult(); | ||
} | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
CurrentPage = null!; | ||
|
||
await Shell.Current.GoToAsync(".."); | ||
|
||
Routing.UnRegisterRoute("uitests"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...t.Maui.DeviceTests/CommunityToolkit.Maui.DeviceTests/Tests/UITests/StatusBarTestPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage | ||
x:Class="CommunityToolkit.Maui.DeviceTests.Tests.UITests.StatusBarTestPage" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" | ||
Title="StatusBarTestPage"> | ||
<ContentPage.Behaviors> | ||
<toolkit:StatusBarBehavior StatusBarColor="Fuchsia" /> | ||
</ContentPage.Behaviors> | ||
|
||
<VerticalStackLayout> | ||
<Label | ||
HorizontalOptions="Center" | ||
Text="Welcome to .NET MAUI!" | ||
VerticalOptions="Center" /> | ||
</VerticalStackLayout> | ||
</ContentPage> |
9 changes: 9 additions & 0 deletions
9
...aui.DeviceTests/CommunityToolkit.Maui.DeviceTests/Tests/UITests/StatusBarTestPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace CommunityToolkit.Maui.DeviceTests.Tests.UITests; | ||
|
||
public partial class StatusBarTestPage : ContentPage | ||
{ | ||
public StatusBarTestPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...olkit.Maui.DeviceTests/CommunityToolkit.Maui.DeviceTests/Tests/UITests/StatusBarUITest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using CommunityToolkit.Maui.Behaviors; | ||
using Xunit; | ||
|
||
namespace CommunityToolkit.Maui.DeviceTests.Tests.UITests; | ||
public sealed class StatusBarUITest : UITests<StatusBarTestPage> | ||
{ | ||
[UIFact] | ||
public void IsBehaviorAttached() | ||
{ | ||
var behavior = CurrentPage.Behaviors.FirstOrDefault( x => x is StatusBarBehavior); | ||
|
||
Assert.NotNull(behavior); | ||
} | ||
|
||
[UIFact] | ||
public void GetTheColor() | ||
{ | ||
var behavior = CurrentPage.Behaviors.FirstOrDefault(x => x is StatusBarBehavior) as StatusBarBehavior; | ||
|
||
Assert.NotNull(behavior); | ||
|
||
var color = behavior.StatusBarColor; | ||
|
||
Assert.Equal(Colors.Fuchsia, color); | ||
} | ||
} |