public async Task HorizontalTextAlignmentInitializesCorrectly() { var xplatHorizontalTextAlignment = TextAlignment.End; var labelStub = new LabelStub() { Text = "Test", HorizontalTextAlignment = xplatHorizontalTextAlignment }; var values = await GetValueAsync(labelStub, (handler) => { return(new { ViewValue = labelStub.HorizontalTextAlignment, PlatformViewValue = GetNativeHorizontalTextAlignment(handler) }); }); Assert.Equal(xplatHorizontalTextAlignment, values.ViewValue); (var gravity, var textAlignment) = values.PlatformViewValue; // Device Tests runner has RTL support enabled, so we expect TextAlignment values // (If it didn't, we'd have to fall back to gravity) var expectedValue = ATextAlignemnt.ViewEnd; Assert.Equal(expectedValue, textAlignment); }
public async Task FontFamilyInitializesCorrectly(string family) { var label = new LabelStub() { Text = "Test", Font = Font.OfSize(family, 10) }; var handler = await CreateHandlerAsync(label); var nativeLabel = GetNativeLabel(handler); var fontManager = App.Services.GetRequiredService <IFontManager>(); var nativeFont = fontManager.GetTypeface(Font.OfSize(family, 0.0)); Assert.Equal(nativeFont, nativeLabel.Typeface); if (string.IsNullOrEmpty(family)) { Assert.Equal(fontManager.DefaultTypeface, nativeLabel.Typeface); } else { Assert.NotEqual(fontManager.DefaultTypeface, nativeLabel.Typeface); } }
public async Task CanSetAlignmentAndLineHeight() { // Verifying that setting LineHeight (which requires an attributed string on iOS) // doesn't cancel out the text alignment value (which can be set without an attributed string) var xplatHorizontalTextAlignment = TextAlignment.End; double xplatLineHeight = 2; var label = new LabelStub() { Text = "Test", HorizontalTextAlignment = xplatHorizontalTextAlignment, LineHeight = xplatLineHeight }; var expectedAlignment = UITextAlignment.Right; var expectedLineHeight = xplatLineHeight; var handler = await CreateHandlerAsync(label); var actualAlignment = await InvokeOnMainThreadAsync(() => GetNativeHorizontalTextAlignment(handler)); var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler)); Assert.Equal(expectedLineHeight, actualLineHeight); Assert.Equal(expectedAlignment, actualAlignment); }
public async Task TextInitializesCorrectly() { var label = new LabelStub() { Text = "Test" }; await ValidatePropertyInitValue(label, () => label.Text, GetNativeText, label.Text); }
public async Task CharacterSpacingInitializesCorrectly() { var label = new LabelStub() { Text = "Test CharacterSpacing", CharacterSpacing = 4.0 }; await ValidatePropertyInitValue(label, () => label.CharacterSpacing, GetNativeCharacterSpacing, label.CharacterSpacing); }
public async Task BackgroundColorInitializesCorrectly() { var label = new LabelStub() { BackgroundColor = Color.Blue, Text = "Test" }; await ValidateNativeBackgroundColor(label, Color.Blue); }
public async Task TextColorInitializesCorrectly() { var label = new LabelStub() { Text = "Test", TextColor = Color.Red }; await ValidatePropertyInitValue(label, () => label.TextColor, GetNativeTextColor, label.TextColor); }
public async Task FontSizeInitializesCorrectly(int fontSize) { var label = new LabelStub() { Text = "Test", Font = Font.OfSize("Arial", fontSize) }; await ValidatePropertyInitValue(label, () => label.Font.FontSize, GetNativeUnscaledFontSize, label.Font.FontSize); }
public async Task AttributesInitializeCorrectly(FontAttributes attributes, bool isBold, bool isItalic) { var label = new LabelStub() { Text = "Test", Font = Font.OfSize("Arial", 10).WithAttributes(attributes) }; await ValidatePropertyInitValue(label, () => label.Font.FontAttributes.HasFlag(FontAttributes.Bold), GetNativeIsBold, isBold); await ValidatePropertyInitValue(label, () => label.Font.FontAttributes.HasFlag(FontAttributes.Italic), GetNativeIsItalic, isItalic); }
public async Task NegativeMaxValueWithWrapIsCorrect() { var label = new LabelStub() { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit", MaxLines = -1, LineBreakMode = LineBreakMode.WordWrap }; var nativeValue = await GetValueAsync(label, GetNativeMaxLines); Assert.Equal(int.MaxValue, nativeValue); }
public async Task TextDoesNotAffectCharacterSpacing(string initialText, string newText) { var label = new LabelStub { Text = initialText, CharacterSpacing = 5, }; await ValidateUnrelatedPropertyUnaffected( label, GetNativeCharacterSpacing, nameof(ILabel.Text), () => label.Text = newText); }
public async Task CharacterSpacingUpdatesCorrectly(double setValue, double unsetValue) { var label = new LabelStub { Text = "This is TEXT!" }; await ValidatePropertyUpdatesValue( label, nameof(ILabel.CharacterSpacing), GetNativeCharacterSpacing, setValue, unsetValue); }
public async Task FontDoesNotAffectCharacterSpacing() { var label = new LabelStub { Text = "This is TEXT!", CharacterSpacing = 5, Font = Font.SystemFontOfSize(20) }; await ValidateUnrelatedPropertyUnaffected( label, GetNativeCharacterSpacing, nameof(ILabel.Font), () => label.Font = Font.SystemFontOfSize(15)); }
public async Task PaddingInitializesCorrectly() { var label = new LabelStub() { Text = "Test", Padding = new Thickness(5, 10, 15, 20) }; var handler = await CreateHandlerAsync(label); var insets = ((MauiLabel)handler.NativeView).TextInsets; Assert.Equal(5, insets.Left); Assert.Equal(10, insets.Top); Assert.Equal(15, insets.Right); Assert.Equal(20, insets.Bottom); }
public async Task TextDecorationsAppliedWhenTextAdded() { TextDecorations xplatTextDecorations = TextDecorations.Underline; var label = new LabelStub() { TextDecorations = xplatTextDecorations }; // No text set var handler = await CreateHandlerAsync(label); label.Text = "Now we have text"; await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.Text))); var attributedText = await InvokeOnMainThreadAsync(() => GetAttributedText(handler)); attributedText.AssertHasUnderline(); }
public async Task CharacterSpacingAppliedWhenTextAdded() { double xplatCharacterSpacing = 1.5; var expectedCharacterSpacing = xplatCharacterSpacing; var label = new LabelStub() { CharacterSpacing = xplatCharacterSpacing }; // No text set var handler = await CreateHandlerAsync(label); label.Text = "Now we have text"; await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.Text))); var actualCharacterSpacing = await InvokeOnMainThreadAsync(() => GetNativeCharacterSpacing(handler)); Assert.Equal(expectedCharacterSpacing, actualCharacterSpacing); }
public async Task LineHeightAppliedWhenTextAdded() { double xplatLineHeight = 2; var expectedLineHeight = xplatLineHeight; var label = new LabelStub() { LineHeight = xplatLineHeight }; // No text set var handler = await CreateHandlerAsync(label); label.Text = "Now we have text"; await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.Text))); var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler)); Assert.Equal(expectedLineHeight, actualLineHeight); }
public async Task ValidateMaxLinesSettingTextDecorations() { int xplatMaxLines = 2; var labelHandler = new LabelStub() { MaxLines = xplatMaxLines, LineBreakMode = LineBreakMode.TailTruncation }; var values = await GetValueAsync(labelHandler, (handler) => { return(new { ViewValue = labelHandler.MaxLines, PlatformViewValue = GetNativeMaxLines(handler) }); }); Assert.Equal(xplatMaxLines, values.ViewValue); }
public async Task HorizontalTextAlignmentAdjustsForFlowDirection(TextAlignment alignment, FlowDirection flowDirection, UITextAlignment expected) { var label = new LabelStub { Text = "This is TEXT!", HorizontalTextAlignment = alignment, FlowDirection = flowDirection }; var values = await GetValueAsync(label, (handler) => { return(new { ViewValue = label.HorizontalTextAlignment, NativeViewValue = GetNativeHorizontalTextAlignment(handler) }); }); Assert.Equal(expected, values.NativeViewValue); }
public async Task TextDecorationsInitializesCorrectly() { var xplatTextDecorations = TextDecorations.Underline; var labelHandler = new LabelStub() { TextDecorations = xplatTextDecorations }; var values = await GetValueAsync(labelHandler, (handler) => { return(new { ViewValue = labelHandler.TextDecorations, NativeViewValue = GetNativeTextDecorations(handler) }); }); Assert.Equal(xplatTextDecorations, values.ViewValue); Assert.True(values.NativeViewValue != null); }
public async Task TextDecorationsInitializesCorrectly() { var xplatTextDecorations = TextDecorations.Underline; var labelHandler = new LabelStub() { Text = "Test", // Native values won't actually apply unless there's text TextDecorations = xplatTextDecorations }; var values = await GetValueAsync(labelHandler, (handler) => { return(new { ViewValue = labelHandler.TextDecorations, GetNativeLabel(handler).AttributedText }); }); Assert.Equal(xplatTextDecorations, values.ViewValue); values.AttributedText.AssertHasUnderline(); }
public async Task LineHeightSurvivesTextDecorations() { TextDecorations xplatTextDecorations = TextDecorations.Underline; double xplatLineHeight = 2; var expectedLineHeight = xplatLineHeight; var label = new LabelStub() { Text = "test", LineHeight = xplatLineHeight }; var handler = await CreateHandlerAsync(label); label.TextDecorations = xplatTextDecorations; await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.TextDecorations))); var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler)); var attributedText = await InvokeOnMainThreadAsync(() => GetAttributedText(handler)); Assert.Equal(expectedLineHeight, actualLineHeight); attributedText.AssertHasUnderline(); }
public async Task LineHeightInitializesCorrectly() { var xplatLineHeight = 1.5d; var labelHandler = new LabelStub() { LineHeight = xplatLineHeight }; var values = await GetValueAsync(labelHandler, (handler) => { return(new { ViewValue = labelHandler.LineHeight, NativeViewValue = GetNativeLineHeight(handler) }); }); float expectedValue = 1.5f; Assert.Equal(xplatLineHeight, values.ViewValue); Assert.Equal(expectedValue, values.NativeViewValue); }
public async Task TextDecorationsInitializesCorrectly() { var xplatTextDecorations = TextDecorations.Underline; var labelHandler = new LabelStub() { TextDecorations = xplatTextDecorations }; var values = await GetValueAsync(labelHandler, (handler) => { return(new { ViewValue = labelHandler.TextDecorations, PlatformViewValue = GetNativeTextDecorations(handler) }); }); PaintFlags expectedValue = PaintFlags.UnderlineText; Assert.Equal(xplatTextDecorations, values.ViewValue); values.PlatformViewValue.AssertHasFlag(expectedValue); }
public async Task PaddingInitializesCorrectly() { var label = new LabelStub() { Text = "Test", Padding = new Thickness(5, 10, 15, 20) }; var handler = await CreateHandlerAsync(label); var(left, top, right, bottom) = GetNativePadding((TextView)handler.PlatformView); var context = handler.PlatformView.Context; var expectedLeft = context.ToPixels(5); var expectedTop = context.ToPixels(10); var expectedRight = context.ToPixels(15); var expectedBottom = context.ToPixels(20); Assert.Equal(expectedLeft, left); Assert.Equal(expectedTop, top); Assert.Equal(expectedRight, right); Assert.Equal(expectedBottom, bottom); }
public async Task LineHeightSurvivesCharacterSpacing() { double xplatCharacterSpacing = 1.5; var expectedCharacterSpacing = xplatCharacterSpacing; double xplatLineHeight = 2; var expectedLineHeight = xplatLineHeight; var label = new LabelStub() { Text = "test", LineHeight = xplatLineHeight }; var handler = await CreateHandlerAsync(label); label.CharacterSpacing = xplatCharacterSpacing; await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.CharacterSpacing))); var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler)); var actualCharacterSpacing = await InvokeOnMainThreadAsync(() => GetNativeCharacterSpacing(handler)); Assert.Equal(expectedLineHeight, actualLineHeight); Assert.Equal(expectedCharacterSpacing, actualCharacterSpacing); }
public async Task HorizontalTextAlignmentInitializesCorrectly() { var xplatHorizontalTextAlignment = TextAlignment.End; var labelStub = new LabelStub() { Text = "Test", HorizontalTextAlignment = xplatHorizontalTextAlignment }; UITextAlignment expectedValue = UITextAlignment.Right; var values = await GetValueAsync(labelStub, (handler) => { return(new { ViewValue = labelStub.HorizontalTextAlignment, NativeViewValue = GetNativeHorizontalTextAlignment(handler) }); }); Assert.Equal(xplatHorizontalTextAlignment, values.ViewValue); values.NativeViewValue.AssertHasFlag(expectedValue); }
public async Task FontFamilyInitializesCorrectly(string family) { var label = new LabelStub() { Text = "Test", Font = Font.OfSize(family, 10) }; var(services, nativeFont) = await GetValueAsync(label, handler => (handler.Services, GetNativeLabel(handler).Font)); var fontManager = services.GetRequiredService <IFontManager>(); var expectedNativeFont = fontManager.GetFont(Font.OfSize(family, 0.0)); Assert.Equal(expectedNativeFont.FamilyName, nativeFont.FamilyName); if (string.IsNullOrEmpty(family)) { Assert.Equal(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName); } else { Assert.NotEqual(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName); } }