Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ public partial class BoxViewTests
{
MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewViewHandler) =>
boxViewViewHandler.PlatformView;

Task<float> GetPlatformOpacity(ShapeViewHandler handler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetNativeBoxView(handler);
return nativeView.Alpha;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ public partial class BoxViewTests
{
W2DGraphicsView GetNativeBoxView(ShapeViewHandler boxViewHandler) =>
boxViewHandler.PlatformView;

Task<float> GetPlatformOpacity(ShapeViewHandler handler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetNativeBoxView(handler);
return (float)nativeView.Opacity;
});
}
}
}
19 changes: 19 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
Expand Down Expand Up @@ -45,5 +46,23 @@ public async Task BoxViewBackgroundColorConsistent()

await ValidateHasColor(boxView, expected, typeof(ShapeViewHandler));
}

[Fact]
[Description("The Opacity property of a BoxView should match with native Opacity")]
public async Task VerifyBoxViewOpacityProperty()
{
var boxView = new BoxView
{
Opacity = 0.35f
};
var expectedValue = boxView.Opacity;

var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
await InvokeOnMainThreadAsync(async () =>
{
var nativeOpacityValue = await GetPlatformOpacity(handler);
Assert.Equal(expectedValue, nativeOpacityValue);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public partial class BoxViewTests
MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewHandler) =>
boxViewHandler.PlatformView;

Task<float> GetPlatformOpacity(ShapeViewHandler handler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetNativeBoxView(handler);
return (float)nativeView.Alpha;
});
}

[Fact(DisplayName = "ShapeView Parts Keep Around")]
public async Task ShapeViewPartsKeepAround()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using AndroidX.AppCompat.Widget;
using AndroidX.Core.Widget;
Expand All @@ -24,6 +25,14 @@ AppCompatButton GetPlatformButton(ButtonHandler buttonHandler) =>
Android.Text.TextUtils.TruncateAt? GetPlatformLineBreakMode(ButtonHandler buttonHandler) =>
GetPlatformButton(buttonHandler).Ellipsize;

Task<float> GetPlatformOpacity(ButtonHandler buttonHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformButton(buttonHandler);
return nativeView.Alpha;
});
}

[Theory(DisplayName = "Button Icon has Correct Position"), Category(TestCategory.Layout)]
[InlineData(Button.ButtonContentLayout.ImagePosition.Left)]
Expand Down Expand Up @@ -81,5 +90,22 @@ await CreateHandlerAndAddToWindow(page, () =>
});
}

[Fact]
[Description("The Opacity property of a Button should match with native Opacity")]
public async Task VerifyButtonOpacityProperty()
{
var button = new Button
{
Opacity = 0.35f
};
var expectedValue = button.Opacity;

var handler = await CreateHandlerAsync<ButtonHandler>(button);
await InvokeOnMainThreadAsync(async () =>
{
var nativeOpacityValue = await GetPlatformOpacity(handler);
Assert.Equal(expectedValue, nativeOpacityValue);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.ComponentModel;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
Expand All @@ -19,5 +21,32 @@ Button GetPlatformButton(ButtonHandler buttonHandler) =>

TextTrimming GetPlatformLineBreakMode(ButtonHandler buttonHandler) =>
(GetPlatformButton(buttonHandler).Content as FrameworkElement)!.GetFirstDescendant<TextBlock>()!.TextTrimming;

Task<float> GetPlatformOpacity(ButtonHandler buttonHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformButton(buttonHandler);
return (float)nativeView.Opacity;
});
}

[Fact]
[Description("The Opacity property of a Button should match with native Opacity")]
public async Task VerifyButtonOpacityProperty()
{
var button = new Microsoft.Maui.Controls.Button
{
Opacity = 0.35f
};
var expectedValue = button.Opacity;

var handler = await CreateHandlerAsync<ButtonHandler>(button);
await InvokeOnMainThreadAsync(async () =>
{
var nativeOpacityValue = await GetPlatformOpacity(handler);
Assert.Equal(expectedValue, nativeOpacityValue);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,5 @@ public async Task ButtonBackgroundColorConsistent()

await ValidateHasColor(button, expected, typeof(ButtonHandler));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ public partial class CheckBoxTests
{
AppCompatCheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) =>
checkBoxHandler.PlatformView;

Task<float> GetPlatformOpacity(CheckBoxHandler CheckBoxHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetNativeCheckBox(CheckBoxHandler);
return nativeView.Alpha;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ public partial class CheckBoxTests
{
CheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) =>
checkBoxHandler.PlatformView;

Task<float> GetPlatformOpacity(CheckBoxHandler checkBoxHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetNativeCheckBox(checkBoxHandler);
return (float)nativeView.Opacity;
});
}
}
}
19 changes: 19 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Xunit;
using System.ComponentModel;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -43,5 +44,23 @@ public async Task UpdatingCheckBoxBackgroundColorUpdatesBackground(string colorS

await ValidateHasColor<CheckBoxHandler>(checkBox, color);
}

[Fact]
[Description("The Opacity property of a CheckBox should match with native Opacity")]
public async Task VerifyCheckBoxOpacityProperty()
{
var checkBox = new CheckBox
{
Opacity = 0.35f
};
var expectedValue = checkBox.Opacity;

var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
await InvokeOnMainThreadAsync(async () =>
{
var nativeOpacityValue = await GetPlatformOpacity(handler);
Assert.Equal(expectedValue, nativeOpacityValue);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ public partial class CheckBoxTests
{
MauiCheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) =>
checkBoxHandler.PlatformView;

Task<float> GetPlatformOpacity(CheckBoxHandler checkBoxHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetNativeCheckBox(checkBoxHandler);
return (float)nativeView.Alpha;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ static int GetPlatformSelectionLength(EditorHandler editorHandler)
return -1;
}

Task<float> GetPlatformOpacity(EditorHandler editorHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(editorHandler);
return nativeView.Alpha;
});
}

[Fact]
public async Task CursorPositionPreservedWhenTextTransformPresent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ static Task<string> GetPlatformText(EditorHandler handler)
return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Text);
}

Task<float> GetPlatformOpacity(EditorHandler editorHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(editorHandler);
return (float)nativeView.Opacity;
});
}

static void SetPlatformText(EditorHandler editorHandler, string text) =>
GetPlatformControl(editorHandler).Text = text;

Expand Down
18 changes: 18 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,24 @@ await InvokeOnMainThreadAsync(() =>
}
#endif

[Fact]
[Description("The Opacity property of a Editor should match with native Opacity")]
public async Task VerifyEditorOpacityProperty()
{
var editor = new Editor
{
Opacity = 0.35f
};
var expectedValue = editor.Opacity;

var handler = await CreateHandlerAsync<EditorHandler>(editor);
await InvokeOnMainThreadAsync(async () =>
{
var nativeOpacityValue = await GetPlatformOpacity(handler);
Assert.Equal(expectedValue, nativeOpacityValue);
});
}

[Category(TestCategory.Editor)]
[Category(TestCategory.TextInput)]
[Collection(RunInNewWindowCollection)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ static int GetPlatformSelectionLength(EditorHandler editorHandler)
return -1;
}

Task<float> GetPlatformOpacity(EditorHandler editorHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(editorHandler);
return (float)nativeView.Alpha;
});
}

[Category(TestCategory.Editor)]
public class PlaceholderTests : ControlsHandlerTestBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ static int GetPlatformSelectionLength(EntryHandler entryHandler)
return -1;
}

Task<float> GetPlatformOpacity(EntryHandler entryHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(entryHandler);
return nativeView.Alpha;
});
}

[Fact]
public async Task CursorPositionPreservedWhenTextTransformPresent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ static Task<string> GetPlatformText(EntryHandler handler)
return InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Text);
}

Task<float> GetPlatformOpacity(EntryHandler entryHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(entryHandler);
return (float)nativeView.Opacity;
});
}

static void SetPlatformText(EntryHandler entryHandler, string text) =>
GetPlatformControl(entryHandler).Text = text;

Expand Down
18 changes: 18 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ public async Task EntryBackgroundColorConsistent()
await ValidateHasColor(entry, expected, typeof(EntryHandler));
}

[Fact]
[Description("The Opacity property of an Entry should match with native Opacity")]
public async Task VerifyEntryOpacityProperty()
{
var entry = new Entry
{
Opacity = 0.35f
};
var expectedValue = entry.Opacity;

var handler = await CreateHandlerAsync<EntryHandler>(entry);
await InvokeOnMainThreadAsync(async () =>
{
var nativeOpacityValue = await GetPlatformOpacity(handler);
Assert.Equal(expectedValue, nativeOpacityValue);
});
}

[Category(TestCategory.Entry)]
[Category(TestCategory.TextInput)]
[Collection(RunInNewWindowCollection)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ static int GetPlatformSelectionLength(EntryHandler entryHandler)

return -1;
}

Task<float> GetPlatformOpacity(EntryHandler entryHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(entryHandler);
return (float)nativeView.Alpha;
});
}

[Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
public class ScrollTests : ControlsHandlerTestBase
Expand Down
Loading
Loading