Skip to content

Commit

Permalink
Fix broken handler test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Mar 29, 2021
1 parent e301a0a commit 3a04c7e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/Core/tests/DeviceTests/AssertionExtensions.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ public static double GetCharacterSpacing(this NSAttributedString text)
return kerning.DoubleValue;
}

public static UIColor GetForegroundColor(this NSAttributedString text)
{
if (text == null)
return UIColor.Clear;

var value = text.GetAttribute(UIStringAttributeKey.ForegroundColor, 0, out var range);

if (value == null)
return UIColor.Clear;

Assert.Equal(0, range.Location);
Assert.Equal(text.Length, range.Length);

var kerning = Assert.IsType<UIColor>(value);

return kerning;
}

public static void AssertHasUnderline(this NSAttributedString attributedString)
{
var value = attributedString.GetAttribute(UIStringAttributeKey.UnderlineStyle, 0, out var range);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
using UIKit;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
Expand All @@ -9,24 +11,36 @@ public partial class PickerHandlerTests
[Fact(DisplayName = "Title Color Initializes Correctly")]
public async Task TitleColorInitializesCorrectly()
{
var xplatTitleColor = Color.CadetBlue;

var picker = new PickerStub
{
Title = "Select an Item",
TitleColor = Color.CadetBlue
TitleColor = xplatTitleColor
};

await ValidateNativeTitleColor(picker, picker.TitleColor);
var expectedValue = xplatTitleColor.ToNative();

var values = await GetValueAsync(picker, (handler) =>
{
return new
{
ViewValue = picker.TitleColor,
NativeViewValue = GetNativeTitleColor(handler)
};
});

Assert.Equal(xplatTitleColor, values.ViewValue);
Assert.Equal(expectedValue, values.NativeViewValue);
}

MauiPicker GetNativePicker(PickerHandler pickerHandler) =>
(MauiPicker)pickerHandler.View;

Task ValidateNativeTitleColor(IPicker picker, Color color)
UIColor GetNativeTitleColor(PickerHandler pickerHandler)
{
return InvokeOnMainThreadAsync(() =>
{
return GetNativePicker(CreateHandler(picker)).AssertContainsColor(color);
});
var mauiPicker = GetNativePicker(pickerHandler);
return mauiPicker.AttributedPlaceholder.GetForegroundColor();
}
}
}

0 comments on commit 3a04c7e

Please sign in to comment.