Skip to content

Commit

Permalink
[UITesting] Moved ButtonHandler.ImageSourceInitializesCorrectly to Ap…
Browse files Browse the repository at this point in the history
…pium (#24934)

* [UITesting] Moved ButtonHandler.ImageSourceInitializesCorrectly to appium

* Added snapshots
  • Loading branch information
kubaflo authored and rmarinho committed Oct 16, 2024
1 parent ddf0d1f commit 931d69e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 46 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24916.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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="red.png"/>
<Button ImageSource="green.png"/>
<Button ImageSource="blue.png"/>
<Label Text="Image buttons:"/>
<ImageButton Source="red.png"/>
<ImageButton Source="green.png"/>
<ImageButton Source="blue.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();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 931d69e

Please sign in to comment.