Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
6 changes: 3 additions & 3 deletions eng/pipelines/common/device-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ steps:
retryCountOnTaskFailure: 2

- task: PublishTestResults@2
displayName: Publish the $(System.PhaseName) test results
displayName: Publish the $(Agent.JobName) test results
condition: always()
inputs:
testResultsFormat: xUnit
testResultsFiles: '$(TestResultsDirectory)/**/TestResults*(-*).xml'
testRunTitle: '$(System.PhaseName)_${{ parameters.windowsPackageId }} (attempt: $(System.JobAttempt))'
testRunTitle: '$(Agent.JobName) (attempt $(System.JobAttempt))'

- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: always()
inputs:
artifactName: $(System.PhaseName)_attempt_$(System.JobAttempt)
artifactName: '$(Agent.JobName) (attempt $(System.JobAttempt))'

# This must always be placed as the last step in the job
- template: agent-rebooter/mac.v1.yml@yaml-templates
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/common/ui-tests-compatibility-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ steps:
# retryCountOnTaskFailure: 2

- task: PublishTestResults@2
displayName: Publish the $(System.PhaseName) test results
displayName: Publish the $(Agent.JobName) test results
condition: always()
inputs:
testResultsFormat: NUnit
testResultsFiles: '**/TestResult*.xml'
testRunTitle: '$(System.PhaseName)'
testRunTitle: '$(Agent.JobName)'
searchFolder: '$(TestResultsDirectory)'
failTaskOnFailedTests: true

Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/common/ui-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ steps:
retryCountOnTaskFailure: 2

- task: PublishTestResults@2
displayName: Publish the $(System.PhaseName) test results
displayName: Publish the $(Agent.JobName) test results
condition: always()
inputs:
testResultsFormat: VSTest
testResultsFiles: '$(TestResultsDirectory)/*.trx'
testRunTitle: '$(System.PhaseName)'
testRunTitle: '$(Agent.JobName)'
failTaskOnFailedTests: true

- task: PublishBuildArtifacts@1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Handlers;
using Xunit;

Expand All @@ -11,6 +11,11 @@ namespace Microsoft.Maui.DeviceTests
[Category(TestCategory.Label)]
public partial class FormattedStringTests : ControlsHandlerTestBase
{
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
base.ConfigureBuilder(mauiAppBuilder)
.ConfigureMauiHandlers(handlers =>
handlers.AddHandler<Label, LabelHandler>());

[Fact]
public async Task NativeFormattedStringContainsSpan()
{
Expand Down
39 changes: 38 additions & 1 deletion src/Controls/tests/DeviceTests/ControlsDeviceTestExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Microsoft.Maui.Controls;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using Xunit;

#if ANDROID || IOS || MACCATALYST
using ShellHandler = Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer;
#endif
Expand Down Expand Up @@ -44,6 +47,9 @@ public static MauiAppBuilder ConfigureTestBuilder(this MauiAppBuilder mauiAppBui
})
.ConfigureMauiHandlers(handlers =>
{
// TODO: removing these causes a crash and it is very hard to fugure out which test
// is needing these mappers

handlers.AddHandler(typeof(Editor), typeof(EditorHandler));
handlers.AddHandler(typeof(VerticalStackLayout), typeof(LayoutHandler));
handlers.AddHandler(typeof(Controls.Window), typeof(WindowHandlerStub));
Expand All @@ -53,5 +59,36 @@ public static MauiAppBuilder ConfigureTestBuilder(this MauiAppBuilder mauiAppBui
#endif
});
}


public static Task Wait(this Image image, int timeout = 1000) =>
AssertionExtensions.Wait(() => !image.IsLoading, timeout);

public static void SetupShellHandlers(this MauiAppBuilder builder)
{
builder.ConfigureMauiHandlers(SetupShellHandlers);
}

public static void SetupShellHandlers(this IMauiHandlersCollection handlers)
{
handlers.TryAddHandler(typeof(Controls.Shell), typeof(ShellHandler));
handlers.TryAddHandler<Layout, LayoutHandler>();
handlers.TryAddHandler<Image, ImageHandler>();
handlers.TryAddHandler<Label, LabelHandler>();
handlers.TryAddHandler<Button, ButtonHandler>();
handlers.TryAddHandler<Page, PageHandler>();
handlers.TryAddHandler(typeof(Toolbar), typeof(ToolbarHandler));
handlers.TryAddHandler(typeof(MenuBar), typeof(MenuBarHandler));
handlers.TryAddHandler(typeof(MenuBarItem), typeof(MenuBarItemHandler));
handlers.TryAddHandler(typeof(MenuFlyoutItem), typeof(MenuFlyoutItemHandler));
handlers.TryAddHandler(typeof(MenuFlyoutSubItem), typeof(MenuFlyoutSubItemHandler));
handlers.TryAddHandler<ScrollView, ScrollViewHandler>();

#if WINDOWS
handlers.TryAddHandler(typeof(ShellItem), typeof(ShellItemHandler));
handlers.TryAddHandler(typeof(ShellSection), typeof(ShellSectionHandler));
handlers.TryAddHandler(typeof(ShellContent), typeof(ShellContentHandler));
#endif
}
}
}
6 changes: 0 additions & 6 deletions src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder
return mauiAppBuilder.ConfigureTestBuilder();
}

protected void SetupShellHandlers(IMauiHandlersCollection handlers) =>
handlers.SetupShellHandlers();

protected THandler CreateHandler<THandler>(IElement view)
where THandler : IElementHandler, new()
{
Expand Down Expand Up @@ -514,9 +511,6 @@ protected IToolbar GetToolbar(IElementHandler handler)
?.Toolbar;
}

protected Task ValidateHasColor<THandler>(IView view, Color color, Action action = null) =>
ValidateHasColor(view, color, typeof(THandler), action);

protected static void MockAccessibilityExpectations(View view)
{
#if IOS || MACCATALYST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public partial class AccessibilityTests : ControlsHandlerTestBase
[InlineData(false)]
public async Task IsInAccessibleTree(bool result)
{
EnsureHandlerCreated(builder =>
builder.ConfigureMauiHandlers(handlers =>
handlers.AddHandler<Button, ButtonHandler>()));

var button = new Button();
AutomationProperties.SetIsInAccessibleTree(button, result);
var important = await GetValueAsync<bool, ButtonHandler>(button, handler => button.IsAccessibilityElement());
Expand All @@ -34,6 +38,10 @@ public async Task IsInAccessibleTree(bool result)
[InlineData(false)]
public async Task ExcludedWithChildren(bool result)
{
EnsureHandlerCreated(builder =>
builder.ConfigureMauiHandlers(handlers =>
handlers.AddHandler<Button, ButtonHandler>()));

var button = new Button();
AutomationProperties.SetExcludedWithChildren(button, result);
var excluded = await GetValueAsync<bool, ButtonHandler>(button, handler => button.IsExcludedWithChildren());
Expand Down
16 changes: 6 additions & 10 deletions src/Controls/tests/DeviceTests/Elements/Border/BorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ namespace Microsoft.Maui.DeviceTests
[Category(TestCategory.Border)]
public partial class BorderTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
EnsureHandlerCreated(builder =>
{
builder.ConfigureMauiHandlers(handlers =>
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
base.ConfigureBuilder(mauiAppBuilder)
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Grid, LayoutHandler>();
handlers.AddHandler<Label, LabelHandler>();
handlers.AddHandler<Border, BorderHandler>();
});
});
}

[Fact(DisplayName = "Rounded Rectangle Border occupies correct space")]
public Task RoundedRectangleBorderLayoutIsCorrect()
Expand All @@ -42,7 +39,7 @@ public Task RoundedRectangleBorderLayoutIsCorrect()
WidthRequest = 100
};

return AssertColorAtPoint(border, expected, typeof(BorderHandler), 10, 10);
return AssertColorAtPoint(border, expected, 10, 10);
}

[Fact(DisplayName = "StrokeThickness does not inset stroke path")]
Expand Down Expand Up @@ -80,15 +77,14 @@ public async Task BorderStrokeThicknessDoesNotInsetStrokePath()
#if IOS
// FIXME: iOS seems to have a white boarder around the Border stroke
#else
await AssertColorAtPoint(grid, Colors.Black, typeof(LayoutHandler), 1, 1);
await AssertColorAtPoint(grid, Colors.Black, 1, 1);
#endif
}


[Fact("Border Does Not Leak")]
public async Task DoesNotLeak()
{
SetupBuilder();
WeakReference platformViewReference = null;
WeakReference handlerReference = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace Microsoft.Maui.DeviceTests
[Category(TestCategory.BoxView)]
public partial class BoxViewTests : ControlsHandlerTestBase
{
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
base.ConfigureBuilder(mauiAppBuilder)
.ConfigureMauiHandlers(handlers =>
handlers.AddHandler<BoxView, ShapeViewHandler>());

[Theory(DisplayName = "BoxView Initializes Correctly")]
[InlineData(0xFFFF0000)]
[InlineData(0xFF00FF00)]
Expand All @@ -26,7 +31,7 @@ public async Task BoxViewInitializesCorrectly(uint color)
WidthRequest = 200
};

await ValidateHasColor(boxView, expected, typeof(ShapeViewHandler));
await ValidateHasColor(boxView, expected);
}
}
}
6 changes: 6 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Button)]
public partial class ButtonTests : ControlsHandlerTestBase
{
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
base.ConfigureBuilder(mauiAppBuilder)
.ConfigureMauiHandlers(handlers =>
handlers.AddHandler<Button, ButtonHandler>());

[Theory]
[ClassData(typeof(TextTransformCases))]
public async Task InitialTextTransformApplied(string text, TextTransform transform, string expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,19 @@ namespace Microsoft.Maui.DeviceTests
[Category(TestCategory.CarouselView)]
public partial class CarouselViewTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
EnsureHandlerCreated(builder =>
{
builder.ConfigureMauiHandlers(handlers =>
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
base.ConfigureBuilder(mauiAppBuilder)
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<CarouselView, CarouselViewHandler>();
handlers.AddHandler<IContentView, ContentViewHandler>();
handlers.AddHandler<Grid, LayoutHandler>();
handlers.AddHandler<Label, LabelHandler>();
});
});
}

[Fact]
public async Task CarouselViewDataTemplateSelectorSelectorNoCrash()
{
SetupBuilder();

ObservableCollection<int> data = new ObservableCollection<int>()
{
1,
Expand Down Expand Up @@ -77,8 +71,6 @@ await CreateHandlerAndAddToWindow<LayoutHandler>(layout, async (handler) =>
[Fact]
public async Task HiddenCarouselViewNoCrash()
{
SetupBuilder();

ObservableCollection<int> data = new ObservableCollection<int>()
{
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.CheckBox)]
public partial class CheckBoxTests : ControlsHandlerTestBase
{
protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
base.ConfigureBuilder(mauiAppBuilder)
.ConfigureMauiHandlers(handlers =>
handlers.AddHandler<CheckBox, CheckBoxHandler>());

[Theory("Checkbox Background Updates Correctly With BackgroundColor Property"
#if WINDOWS
,Skip = "Failing"
Expand All @@ -28,7 +34,7 @@ public async Task UpdatingCheckBoxBackgroundColorUpdatesBackground(string colorS

checkBox.BackgroundColor = color;

await ValidateHasColor<CheckBoxHandler>(checkBox, color);
await ValidateHasColor(checkBox, color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public async Task PushAndPopPageWithCollectionView()

modalPage.Content = collectionView;

SetupBuilder();

await CreateHandlerAndAddToWindow<IWindowHandler>(rootPage,
async (_) =>
{
Expand Down Expand Up @@ -54,8 +52,6 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(rootPage,
[Fact]
public async Task NullItemsSourceDisplaysHeaderFooterAndEmptyView()
{
SetupBuilder();

var emptyView = new Label { Text = "Empty" };
var header = new Label { Text = "Header" };
var footer = new Label { Text = "Footer" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public partial class CollectionViewTests
[Fact(DisplayName = "CollectionView Disconnects Correctly")]
public async Task CollectionViewHandlerDisconnects()
{
SetupBuilder();

ObservableCollection<string> data = new ObservableCollection<string>()
{
"Item 1",
Expand Down Expand Up @@ -57,7 +55,6 @@ await CreateHandlerAndAddToWindow<LayoutHandler>(layout, (handler) =>
[Fact(Skip = "FIX FOR .NET8")]
public async Task ValidateItemContainerDefaultHeight()
{
SetupBuilder();
ObservableCollection<string> data = new ObservableCollection<string>()
{
"Item 1",
Expand Down Expand Up @@ -104,7 +101,6 @@ void ValidateItemContainerStyle(CollectionView collectionView)
[Fact]
public async Task ValidateSendRemainingItemsThresholdReached()
{
SetupBuilder();
ObservableCollection<string> data = new();
for (int i = 0; i < 20; i++)
{
Expand Down
Loading