Skip to content

Commit

Permalink
Adding a test to validate loading images
Browse files Browse the repository at this point in the history
I noticed that in one of my PRs I loaded a lower res image and another test caught it. Adding these tests to ensure that at least we validate the on-screen image.
  • Loading branch information
mattleibow committed Jan 25, 2024
1 parent cb1ac24 commit 75c65b5
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample
{
internal class ImageLoadingGalleryPage : CoreGalleryBasePage
{
protected override void Build()
{
Add(Test.ImageLoading.FromBundleSvg, ImageSource.FromFile("dotnet_bot.png"));

Add(Test.ImageLoading.FromBundlePng, ImageSource.FromFile("groceries.png"));

Add(Test.ImageLoading.FromBundleJpg, ImageSource.FromFile("oasis.jpg"));

Add(Test.ImageLoading.FromBundleGif, ImageSource.FromFile("animated_heart.gif"));
}

ViewContainer<Image> Add(Test.ImageLoading test, ImageSource image) =>
Add(test, new Image
{
Source = image,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Start
});

ViewContainer<Image> Add(Test.ImageLoading test, Image image) =>
Add(new ViewContainer<Image>(test, image));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override string ToString()
new GalleryPageFactory(() => new DragAndDropGallery(), "Drag and Drop Gallery"),
new GalleryPageFactory(() => new GestureRecognizerGallery(), "Gesture Recognizer Gallery"),
new GalleryPageFactory(() => new InputTransparencyGalleryPage(), "Input Transparency Gallery"),
new GalleryPageFactory(() => new ImageLoadingGalleryPage(), "Image Loading Gallery"),
// Elements
new GalleryPageFactory(() => new ActivityIndicatorCoreGalleryPage(), "ActivityIndicator Gallery"),
new GalleryPageFactory(() => new BoxViewCoreGalleryPage(), "Box Gallery"),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/Controls/samples/Controls.Sample.UITests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@ public enum CarouselView
IsBounceEnabled
}

public enum ImageLoading
{
FromBundleSvg,
FromBundlePng,
FromBundleJpg,
FromBundleGif,
}

public enum InputTransparency
{
Default,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Maui.Controls.Sample;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests
{
public class ImageLoadingGalleryTests : CoreGalleryBasePageTest
{
public ImageLoadingGalleryTests(TestDevice device)
: base(device)
{
}

protected override void NavigateToGallery()
{
App.NavigateToGallery("Image Loading Gallery");
}

[Test]
public void LoadAndVerifyPng() => LoadAndVerify(Test.ImageLoading.FromBundlePng);

[Test]
public void LoadAndVerifyJpg() => LoadAndVerify(Test.ImageLoading.FromBundleJpg);

[Test]
public void LoadAndVerifyGif() => LoadAndVerify(Test.ImageLoading.FromBundleGif);

[Test]
public void LoadAndVerifySvg() => LoadAndVerify(Test.ImageLoading.FromBundleSvg);

void LoadAndVerify(Test.ImageLoading test)
{
var remote = new EventViewContainerRemote(UITestContext, test);
remote.GoTo(test.ToString());

App.WaitForElement($"{test}VisualElement");
Thread.Sleep(1000); // android has some button animations that need to finish

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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 75c65b5

Please sign in to comment.