Skip to content

Commit

Permalink
Fix issue & add tests (#22864)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfversluis authored Jun 7, 2024
1 parent c48fcbf commit a66d40c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
using Xunit;
using static Microsoft.Maui.DeviceTests.AssertHelpers;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -38,5 +42,48 @@ static int GetPlatformSelectionLength(EditorHandler editorHandler)

return -1;
}

[Category(TestCategory.Editor)]
public class PlaceholderTests : ControlsHandlerTestBase
{
[Fact]
public async Task PlaceholderFontFamily()
{
EnsureHandlerCreated(builder =>
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(Editor), typeof(EditorHandler));
});
});

var expectedFontFamily = "Times New Roman";

var editor = new Editor
{
FontFamily = expectedFontFamily,
Placeholder = "This is a placeholder"
};

ContentPage contentPage = new ContentPage()
{
Content = new VerticalStackLayout()
{
editor
}
};

await CreateHandlerAndAddToWindow(contentPage, async () =>
{
await AssertEventually(() => editor.IsVisible);
var handler = CreateHandler<EditorHandler>(editor);
var platformControl = GetPlatformControl(handler);

var placeholderLabel = handler.PlatformView.Subviews.OfType<UIKit.UILabel>().FirstOrDefault();

Assert.Equal(expectedFontFamily, placeholderLabel?.Font?.FamilyName);
});
}
}
}
}
43 changes: 43 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,48 @@ await CreateHandlerAndAddToWindow(rootPage, async () =>
Assert.True(isFocused, $"{page} failed to focus the second entry DANG");
}
}

[Category(TestCategory.Entry)]
public class PlaceholderTests : ControlsHandlerTestBase
{
[Fact]
public async Task PlaceholderFontFamily()
{
EnsureHandlerCreated(builder =>
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(Entry), typeof(EntryHandler));
});
});

var expectedFontFamily = "Times New Roman";

var entry = new Entry
{
FontFamily = expectedFontFamily,
Placeholder = "This is a placeholder"
};

ContentPage contentPage = new ContentPage()
{
Content = new VerticalStackLayout()
{
entry
}
};

await CreateHandlerAndAddToWindow(contentPage, async () =>
{
await AssertEventually(() => entry.IsVisible);
var handler = CreateHandler<EntryHandler>(entry);
var platformControl = GetPlatformControl(handler);

var placeholderLabel = handler.PlatformView.Subviews.OfType<UIKit.UILabel>().FirstOrDefault();

Assert.Equal(expectedFontFamily, placeholderLabel?.Font?.FamilyName);
});
}
}
}
}
6 changes: 3 additions & 3 deletions src/Core/src/Platform/iOS/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public override UIFont? Font
set
{
base.Font = value;
UpdatePlaceholderFontSize(value);
UpdatePlaceholderFont(value);

}
}
Expand Down Expand Up @@ -175,10 +175,10 @@ void ShouldCenterVertically()
};
}

void UpdatePlaceholderFontSize(UIFont? value)
void UpdatePlaceholderFont(UIFont? value)
{
_defaultPlaceholderSize ??= _placeholderLabel.Font.PointSize;
_placeholderLabel.Font = _placeholderLabel.Font.WithSize(
_placeholderLabel.Font = value ?? _placeholderLabel.Font.WithSize(
value?.PointSize ?? _defaultPlaceholderSize.Value);
}

Expand Down

0 comments on commit a66d40c

Please sign in to comment.