Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Apr 23, 2024
1 parent b4ac4a2 commit 8136301
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

#if WINDOWS
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
#endif

#if IOS || MACCATALYST
using UIKit;
using Foundation;
#endif

namespace Maui.Controls.Sample.Pages
{
public partial class DropFileToMauiApp
{

public DropFileToMauiApp()
{
InitializeComponent();
}

void DropGestureDragLeave(object? sender, DragEventArgs e)
{

}

async void DropGestureDrop(object? sender, DropEventArgs e)
{
var filePaths = new List<string>();

#if WINDOWS
if (e.PlatformArgs is not null && e.PlatformArgs.DragEventArgs.DataView.Contains(StandardDataFormats.StorageItems))
{
var items = await e.PlatformArgs.DragEventArgs.DataView.GetStorageItemsAsync();
if (items.Any())
{
foreach (var item in items)
{
if (item is StorageFile file)
{
filePaths.Add(item.Path);
}
}

}
}
#elif MACCATALYST

var session = e.PlatformArgs?.DropSession;
if (session == null)
{
return;
}
foreach (UIDragItem item in session.Items)
{
var result = await LoadItemAsync(item.ItemProvider, item.ItemProvider.RegisteredTypeIdentifiers.ToList());
if (result is not null)
{
filePaths.Add(result.FileUrl?.Path!);
}
}
foreach (var item in filePaths)
{
Debug.WriteLine($"Path: {item}");
}

static async Task<LoadInPlaceResult?> LoadItemAsync(NSItemProvider itemProvider, List<string> typeIdentifiers)
{
if (typeIdentifiers is null || typeIdentifiers.Count == 0)
{
return null;
}

var typeIdent = typeIdentifiers.First();

if (itemProvider.HasItemConformingTo(typeIdent))
{
return await itemProvider.LoadInPlaceFileRepresentationAsync(typeIdent);
}

typeIdentifiers.Remove(typeIdent);

return await LoadItemAsync(itemProvider, typeIdentifiers);
}
#else
await Task.CompletedTask;
#endif

lblPath.Text = filePaths.FirstOrDefault();
}

void DropGestureDragOver(object? sender, DragEventArgs e)
{
Debug.WriteLine($"Dragging {e.Data?.Text}, {e.Data?.Image}");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,46 @@ public void HideSoftInputOnTappedPageTest(string control, bool hideOnTapped)
{
this.IgnoreIfPlatforms(new[]
{
TestDevice.Mac, TestDevice.Windows
TestDevice.Windows
});

App.WaitForElement("HideSoftInputOnTappedTrue");

if (this.Device == TestDevice.Mac)
{
HideSoftInputOnTappedPageTestForMac(control, hideOnTapped);
}
else
{
HideSoftInputOnTappedPageTestForAndroidiOS(control, hideOnTapped);
}
}

void HideSoftInputOnTappedPageTestForMac(string control, bool hideOnTapped)
{
try
{
if (hideOnTapped)
App.Click("HideSoftInputOnTappedTrue");
else
App.Click("HideSoftInputOnTappedFalse");

App.WaitForElement(control);
App.Click(control);

Assert.IsTrue(App.IsFocused(control));

App.Click("EmptySpace");
Assert.AreEqual(!hideOnTapped, App.IsFocused(control));
}
finally
{
this.Back();
}
}

void HideSoftInputOnTappedPageTestForAndroidiOS(string control, bool hideOnTapped)
{
try
{
if (App.IsKeyboardShown())
Expand Down Expand Up @@ -52,9 +89,49 @@ public void TogglingHideSoftInputOnTapped()
{
this.IgnoreIfPlatforms(new[]
{
TestDevice.Mac, TestDevice.Windows
TestDevice.Windows
});

App.WaitForElement("HideSoftInputOnTappedFalse");

if (this.Device == TestDevice.Mac)
{
TogglingHideSoftInputOnTappedForMac();
}
else
{
TogglingHideSoftInputOnTappedForAndroidiOS();
}
}

public void TogglingHideSoftInputOnTappedForMac()
{
try
{
App.Click("HideSoftInputOnTappedFalse");

// Switch between enabling/disabling feature
for (int i = 0; i < 2; i++)
{
App.Click("HideKeyboardWhenTappingPage");
Assert.True(App.IsFocused("HideKeyboardWhenTappingPage"));
App.Click("EmptySpace");
Assert.AreEqual(false, App.IsFocused("HideKeyboardWhenTappingPage"));

App.Click("DontHideKeyboardWhenTappingPage");
Assert.True(App.IsFocused("DontHideKeyboardWhenTappingPage"));
App.Click("EmptySpace");
Assert.AreEqual(true, App.IsFocused("DontHideKeyboardWhenTappingPage"));
}
}
finally
{
this.Back();
}
}

public void TogglingHideSoftInputOnTappedForAndroidiOS()
{
try
{
if (App.IsKeyboardShown())
Expand Down
4 changes: 3 additions & 1 deletion src/Controls/tests/UITests/Tests/Issues/Issue19509.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public Issue19509(TestDevice device) : base(device)
public override string Issue => "Entry TextColor property not working when the Text value is bound after some time";

[Test]
public void Issue19509Test()
public async Task EntryTextColorStopsWorkingAfterPropertyIsUpdatedFromBinding()
{
App.WaitForElement("WaitForStubControl");

// 1. Click a button to update the text
App.Click("button");

await Task.Yield();

// 2. Verify that the Entry TextColor is correct (Green).
VerifyScreenshot();
Expand Down
23 changes: 23 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19926.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues;

public class Issue19926 : _IssuesUITest
{
public override string Issue => "[Android] Opacity bug on BoxView.Background";

public Issue19926(TestDevice device)
: base(device)
{ }

[Test]
public void PropertiesShouldBeCorrectlyApplied()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Mac, TestDevice.Windows });
_ = App.WaitForElement("boxView");

VerifyScreenshot();
}
}
24 changes: 24 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue21314.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Maui.Controls.Sample;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue21314 : _IssuesUITest {
public override string Issue => "Image has wrong orientation on iOS";

public Issue21314(TestDevice device) : base(device)
{
}

[Test]
public void ImageShouldBePortrait()
{
this.IgnoreIfPlatforms (new TestDevice[] { TestDevice.Android, TestDevice.Windows });

var image = App.WaitForElement ("theImage").GetRect();
Assert.Greater(image.Height, image.Width);
}
}
}
57 changes: 57 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue21711.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue21711 : _IssuesUITest
{
public Issue21711(TestDevice device) : base(device)
{
}

public override string Issue => "NullReferenceException from FlexLayout.InitItemProperties";

[Test]
public void AddDoesNotCrash()
{
App.WaitForElement("Add");

App.Click("Add");

App.WaitForElement("Item2");
App.WaitForElement("Item3");
}

[Test]
public void InsertDoesNotCrash()
{
App.WaitForElement("Insert");

App.Click("Insert");

App.WaitForElement("Item2");
App.WaitForElement("Item3");
}

[Test]
public void UpdateDoesNotCrash()
{
App.WaitForElement("Update");

App.Click("Update");

App.WaitForElement("Item3");
}

[Test]
public void RemoveDoesNotCrash()
{
App.WaitForElement("Remove");

App.Click("Remove");

App.WaitForElement("Item2");
}
}
}
45 changes: 45 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue5354.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Maui.AppiumTests;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;


namespace Maui.Controls.Sample.Issues
{
public partial class Issue5354 : _IssuesUITest
{
public Issue5354(TestDevice device) : base(device) { }

public override string Issue => "[CollectionView] Updating the ItemsLayout type should refresh the layout";

[Test]
[Category(UITestCategories.CollectionView)]
public void CollectionViewItemsLayoutUpdate()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Mac, TestDevice.Windows },
"This is a product bug.");

App.WaitForElement("CollectionView5354");
App.WaitForElement("Button5354");

for(int i = 0; i < 3; i++)
{
var linearRect0 = App.WaitForElement("Image0").GetRect();
var linearRect1 = App.WaitForElement("Image1").GetRect();

Assert.AreEqual(linearRect0.X, linearRect1.X);
Assert.GreaterOrEqual(linearRect1.Y, linearRect0.Y + linearRect0.Height);

App.Click("Button5354");

var gridRect0 = App.WaitForElement("Image0").GetRect();
var gridRect1 = App.WaitForElement("Image1").GetRect();

Assert.AreEqual(gridRect0.Y, gridRect1.Y);
Assert.AreEqual(gridRect0.Height, gridRect1.Height);

App.Click("Button5354");
}
}
}
}
6 changes: 3 additions & 3 deletions src/Controls/tests/UITests/UITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public override IConfig GetTestConfig()
config.SetProperty("Udid", Environment.GetEnvironmentVariable("DEVICE_UDID") ?? "");
break;
case TestDevice.iOS:
config.SetProperty("DeviceName", Environment.GetEnvironmentVariable("DEVICE_NAME") ?? "iPhone X");
config.SetProperty("PlatformVersion", Environment.GetEnvironmentVariable("PLATFORM_VERSION") ?? "17.0");
config.SetProperty("DeviceName", Environment.GetEnvironmentVariable("DEVICE_NAME") ?? "iPhone Xs");
config.SetProperty("PlatformVersion", Environment.GetEnvironmentVariable("PLATFORM_VERSION") ?? "17.2");
config.SetProperty("Udid", Environment.GetEnvironmentVariable("DEVICE_UDID") ?? "");
break;
case TestDevice.Windows:
Expand Down Expand Up @@ -191,4 +191,4 @@ public void VerifyScreenshot(string? name = null)
_visualRegressionTester.VerifyMatchesSnapshot(name!, actualImage, environmentName: environmentName, testContext: _visualTestContext);
}
}
}
}
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

0 comments on commit 8136301

Please sign in to comment.