Skip to content

Commit

Permalink
[UITesting] Moved ButtonHandler.ImageSourceInitializesCorrectly to ap…
Browse files Browse the repository at this point in the history
…pium
  • Loading branch information
kubaflo committed Sep 25, 2024
1 parent 7d59b44 commit 4f52615
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 46 deletions.
32 changes: 32 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24916.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue24916"
Title="Issue 24916">
<ContentPage.Resources>
<Style TargetType="Button">
<Setter Property="WidthRequest"
Value="100"/>
<Setter Property="HeightRequest"
Value="100"/>
<Setter Property="BackgroundColor"
Value="Black"/>
</Style>
<Style TargetType="ImageButton">
<Setter Property="WidthRequest"
Value="100"/>
<Setter Property="HeightRequest"
Value="100"/>
<Setter Property="BackgroundColor"
Value="Black"/>
</Style>
</ContentPage.Resources>
<VerticalStackLayout>
<Label Text="Buttons:" AutomationId="label"/>
<Button ImageSource="oasis.png"/>
<Button ImageSource="dotnet_bot.png"/>
<Label Text="Image buttons:"/>
<ImageButton Source="oasis.png"/>
<ImageButton Source="dotnet_bot.png"/>
</VerticalStackLayout>
</ContentPage>
12 changes: 12 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24916.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 24916, "Image Source in Button initializes correctly", PlatformAffected.All)]
public partial class Issue24916 : ContentPage
{
public Issue24916()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue24916 : _IssuesUITest
{
public Issue24916(TestDevice testDevice) : base(testDevice){}

public override string Issue => "Image Source in Button initializes correctly";

[Test]
[Category(UITestCategories.Button)]
public void ImageSourceInitializesCorrectly()
{
App.WaitForElement("label");
VerifyScreenshot();
}
}
}
21 changes: 0 additions & 21 deletions src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,6 @@ public async Task ClickEventFires()
Assert.True(clicked);
}

[Theory(DisplayName = "ImageSource Initializes Correctly")]
[InlineData("red.png", "#FF0000")]
[InlineData("green.png", "#00FF00")]
[InlineData("black.png", "#000000")]
public async Task ImageSourceInitializesCorrectly(string filename, string colorHex)
{
var image = new ButtonStub
{
Background = new SolidPaintStub(Colors.Black),
ImageSource = new FileImageSourceStub(filename),
};

await AttachAndRun(image, async (handler) =>
{
await AssertEventually(() => ImageSourceLoaded(handler));
var expectedColor = Color.FromArgb(colorHex);
await handler.PlatformView.AssertContainsColor(expectedColor, MauiContext);
});
}

[Theory(DisplayName = "Padding Initializes Correctly")]
[InlineData(0, 0, 0, 0)]
[InlineData(1, 1, 1, 1)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,6 @@ public async Task ClickEventFires()
Assert.True(clicked);
}

[Theory(DisplayName = "ImageSource Initializes Correctly")]
[InlineData("red.png", "#FF0000")]
[InlineData("green.png", "#00FF00")]
[InlineData("black.png", "#000000")]
public async Task ImageSourceInitializesCorrectly(string filename, string colorHex)
{
var imageButton = new ImageButtonStub
{
Background = new SolidPaintStub(Colors.Black),
ImageSource = new FileImageSourceStub(filename),
};

var order = new List<string>();

await InvokeOnMainThreadAsync(async () =>
{
var handler = CreateHandler(imageButton);
await AssertEventually(() => ImageSourceLoaded(handler));
var expectedColor = Color.FromArgb(colorHex);
await handler.PlatformView.AssertContainsColor(expectedColor, MauiContext);
});
}

[Fact(DisplayName = "LoadingCompleted event fires")]
public async Task LoadingCompletedEventFires()
{
Expand Down

0 comments on commit 4f52615

Please sign in to comment.