Skip to content

Commit 82a1ebc

Browse files
Anandhan Rajagopalnivetha-nagalingam
authored andcommitted
[Testing] Migration of Compatibility.Core platform-specific unit tests into device tests - 3 (#28103)
* Added the CornerRadius and IsEnabled property for DeviceTest * IsEnabled property for Device tests * Addressed the feedbacks * Update BoxViewTests.cs * modified code changes * resolved windows build error * Update RadioButtonTests.Windows.cs * Update CheckBoxTests.iOS.cs * removed unwanted namespace * Update CheckBoxTests.cs * Update SwipeViewTests.Android.cs * Update BoxViewTests.Android.cs * Resolved build error in windows * Update RadioButtonTests.Windows.cs * Added the CornerRadius and IsEnabled property for DeviceTest * IsEnabled property for Device tests * Addressed the feedbacks * Update BoxViewTests.cs * modified code changes * resolved windows build error * Update RadioButtonTests.Windows.cs * Update CheckBoxTests.iOS.cs * removed unwanted namespace * Update CheckBoxTests.cs * Update SwipeViewTests.Android.cs * Resolved build error in windows * Update RadioButtonTests.Windows.cs * Update CheckBoxTests.Android.cs * Resolved conflict errors * Update BoxViewTests.Android.cs --------- Co-authored-by: nivetha-nagalingam <nivetha.nagalingam@syncfusion.com>
1 parent d2284b8 commit 82a1ebc

File tree

13 files changed

+275
-3
lines changed

13 files changed

+275
-3
lines changed

src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Android.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.ComponentModel;
33
using System.Threading.Tasks;
44
using Microsoft.Maui.Controls;
5+
using Microsoft.Maui.Controls.Handlers;
56
using Microsoft.Maui.Graphics;
67
using Microsoft.Maui.Handlers;
78
using Microsoft.Maui.Platform;
89
using Xunit;
910

11+
1012
namespace Microsoft.Maui.DeviceTests
1113
{
1214
public partial class BoxViewTests
@@ -96,6 +98,25 @@ public async Task RotationConsistent()
9698
var platformRotation = await InvokeOnMainThreadAsync(() => platformBoxView.Rotation);
9799
Assert.Equal(expected, platformRotation);
98100
}
101+
102+
[Fact]
103+
[Description("The IsEnabled property of a BoxView should match with native IsEnabled")]
104+
public async Task VerifyBoxViewIsEnabledProperty()
105+
{
106+
var boxView = new BoxView
107+
{
108+
IsEnabled = false
109+
};
110+
var expectedValue = boxView.IsEnabled;
111+
112+
var handler = await CreateHandlerAsync<BoxViewHandler>(boxView);
113+
var nativeView = GetNativeBoxView(handler);
114+
await InvokeOnMainThreadAsync(() =>
115+
{
116+
var isEnabled = nativeView.Enabled;
117+
Assert.Equal(expectedValue, isEnabled);
118+
});
119+
}
99120

100121
Task<bool> GetPlatformIsVisible(ShapeViewHandler boxViewViewHandler)
101122
{

src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Windows.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
using Microsoft.Maui.Graphics.Platform;
44
using Microsoft.Maui.Graphics.Win2D;
55
using Microsoft.Maui.Handlers;
6+
using Xunit;
7+
using System.ComponentModel;
8+
using Microsoft.Maui.Controls;
9+
using Microsoft.Maui.Controls.Handlers;
610

711
namespace Microsoft.Maui.DeviceTests
812
{
@@ -20,6 +24,25 @@ Task<float> GetPlatformOpacity(ShapeViewHandler handler)
2024
});
2125
}
2226

27+
[Fact]
28+
[Description("The IsEnabled property of a BoxView should match with native IsEnabled")]
29+
public async Task BoxViewIsEnabled()
30+
{
31+
var boxView = new BoxView
32+
{
33+
IsEnabled = false
34+
};
35+
var expectedValue = boxView.IsEnabled;
36+
37+
var handler = await CreateHandlerAsync<BoxViewHandler>(boxView);
38+
var nativeView = GetNativeBoxView(handler);
39+
await InvokeOnMainThreadAsync(() =>
40+
{
41+
var isEnabled = nativeView.IsEnabled;
42+
Assert.Equal(expectedValue, isEnabled);
43+
});
44+
}
45+
2346
Task<bool> GetPlatformIsVisible(ShapeViewHandler boxViewHandler)
2447
{
2548
return InvokeOnMainThreadAsync(() =>

src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using Microsoft.Maui.Controls;
55
using Microsoft.Maui.Graphics;
66
using Microsoft.Maui.Handlers;
7+
using Microsoft.Maui.Controls.Handlers;
78
using Microsoft.Maui.Hosting;
89
using Xunit;
9-
using Microsoft.Maui.Controls.Handlers;
1010

1111
namespace Microsoft.Maui.DeviceTests
1212
{
@@ -47,6 +47,21 @@ public async Task BoxViewBackgroundColorConsistent()
4747
await ValidateHasColor(boxView, expected, typeof(ShapeViewHandler));
4848
}
4949

50+
[Fact]
51+
[Description("The Background of a BoxView should match with native Background")]
52+
public async Task BoxViewBackgroundConsistent()
53+
{
54+
var boxView = new BoxView
55+
{
56+
HeightRequest = 100,
57+
WidthRequest = 200,
58+
Background = Brush.Red
59+
};
60+
var expected = (boxView.Background as SolidColorBrush)?.Color;
61+
62+
await ValidateHasColor(boxView, expected, typeof(BoxViewHandler));
63+
}
64+
5065
[Fact]
5166
[Description("The Opacity property of a BoxView should match with native Opacity")]
5267
public async Task VerifyBoxViewOpacityProperty()

src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.iOS.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#nullable enable
22
using System;
3+
using System.ComponentModel;
34
using System.Threading.Tasks;
45
using Microsoft.Maui.Controls;
56
using Microsoft.Maui.Graphics;
@@ -87,5 +88,24 @@ await InvokeOnMainThreadAsync(async () =>
8788
Assert.True(button.Width < gridWidth, $"Button shouldn't occupy entire layout width. Expected: {gridWidth}<, was {button.Width}");
8889
Assert.True(button.Height < gridHeight, $"Button shouldn't occupy entire layout height. Expected: {gridHeight}<, was {button.Height}");
8990
}
91+
92+
[Fact]
93+
[Description("The CornerRadius of a Button should match with native CornerRadius")]
94+
public async Task ButtonCornerRadius()
95+
{
96+
var button = new Button
97+
{
98+
CornerRadius = 15,
99+
};
100+
var expectedValue = button.CornerRadius;
101+
102+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
103+
var nativeView = GetPlatformButton(handler);
104+
await InvokeOnMainThreadAsync(() =>
105+
{
106+
var platformCornerRadius = nativeView.Layer.CornerRadius;
107+
Assert.Equal(expectedValue, platformCornerRadius);
108+
});
109+
}
90110
}
91111
}

src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Android.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ public async Task RotationConsistent()
9898
Assert.Equal(expected, platformRotation);
9999
}
100100

101+
[Fact("The IsEnabled of a CheckBox should match with native IsEnabled")]
102+
public async Task CheckBoxIsEnabled()
103+
{
104+
var checkBox = new CheckBox();
105+
checkBox.IsEnabled = false;
106+
var expectedValue = checkBox.IsEnabled;
107+
108+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
109+
var nativeView = GetNativeCheckBox(handler);
110+
await InvokeOnMainThreadAsync(() =>
111+
{
112+
var isEnabled = nativeView.Enabled;
113+
Assert.Equal(expectedValue, isEnabled);
114+
});
115+
}
116+
101117
Task<bool> GetPlatformIsVisible(CheckBoxHandler checkBoxHandler)
102118
{
103119
return InvokeOnMainThreadAsync(() =>

src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Windows.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.Maui.Graphics;
44
using Microsoft.Maui.Handlers;
55
using Microsoft.UI.Xaml.Controls;
6+
using Xunit;
67

78
namespace Microsoft.Maui.DeviceTests
89
{
@@ -19,6 +20,22 @@ Task<float> GetPlatformOpacity(CheckBoxHandler checkBoxHandler)
1920
return (float)nativeView.Opacity;
2021
});
2122
}
23+
24+
[Fact("The IsEnabled of a CheckBox should match with native IsEnabled")]
25+
public async Task CheckBoxIsEnabled()
26+
{
27+
var checkBox = new Microsoft.Maui.Controls.CheckBox();
28+
checkBox.IsEnabled = false;
29+
var expectedValue = checkBox.IsEnabled;
30+
31+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
32+
var nativeView = GetNativeCheckBox(handler);
33+
await InvokeOnMainThreadAsync(() =>
34+
{
35+
var isEnabled = nativeView.IsEnabled;
36+
Assert.Equal(expectedValue, isEnabled);
37+
});
38+
}
2239

2340
Task<bool> GetPlatformIsVisible(CheckBoxHandler checkBoxHandler)
2441
{

src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.iOS.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
33
using Microsoft.Maui.Graphics;
4+
using Microsoft.Maui.Controls;
45
using Microsoft.Maui.Handlers;
56
using Microsoft.Maui.Platform;
67
using Xunit;
@@ -21,6 +22,22 @@ Task<float> GetPlatformOpacity(CheckBoxHandler checkBoxHandler)
2122
return (float)nativeView.Alpha;
2223
});
2324
}
25+
26+
[Fact("The IsEnabled of a CheckBox should match with native IsEnabled")]
27+
public async Task CheckBoxIsEnabled()
28+
{
29+
var checkBox = new CheckBox();
30+
checkBox.IsEnabled = false;
31+
var expectedValue = checkBox.IsEnabled;
32+
33+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
34+
var nativeView = GetNativeCheckBox(handler);
35+
await InvokeOnMainThreadAsync(() =>
36+
{
37+
var isEnabled = nativeView.Enabled;
38+
Assert.Equal(expectedValue, isEnabled);
39+
});
40+
}
2441

2542
Task<bool> GetPlatformIsVisible(CheckBoxHandler checkBoxHandler)
2643
{

src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,25 @@ public async Task RotationConsistent()
150150
var platformRotation = await InvokeOnMainThreadAsync(() => PlatformEditor.Rotation);
151151
Assert.Equal(expected, platformRotation);
152152
}
153+
154+
[Fact]
155+
[Description("The IsEnabled property of a Editor should match with native IsEnabled")]
156+
public async Task VerifyEditorIsEnabledProperty()
157+
{
158+
var editor = new Editor
159+
{
160+
IsEnabled = false
161+
};
162+
var expectedValue = editor.IsEnabled;
163+
164+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
165+
var nativeView = GetPlatformControl(handler);
166+
await InvokeOnMainThreadAsync(() =>
167+
{
168+
var isEnabled = nativeView.Enabled;
169+
170+
Assert.Equal(expectedValue, isEnabled);
171+
});
172+
}
153173
}
154174
}

src/Controls/tests/DeviceTests/Elements/Label/LabelTests.Android.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ public async Task RotationConsistent()
162162
var platformRotation = await InvokeOnMainThreadAsync(() => platformLabel.Rotation);
163163
Assert.Equal(expected, platformRotation);
164164
}
165+
166+
[Fact]
167+
[Description("The IsEnabled property of a Label should match with native IsEnabled")]
168+
public async Task VerifyLabelIsEnabledProperty()
169+
{
170+
var label = new Label
171+
{
172+
IsEnabled = false
173+
};
174+
var expectedValue = label.IsEnabled;
175+
176+
var handler = await CreateHandlerAsync<LabelHandler>(label);
177+
var nativeView = GetPlatformLabel(handler);
178+
await InvokeOnMainThreadAsync(() =>
179+
{
180+
var isEnabled = nativeView.Enabled;
181+
Assert.Equal(expectedValue, isEnabled);
182+
});
183+
}
184+
165185
TextView GetPlatformLabel(LabelHandler labelHandler) =>
166186
labelHandler.PlatformView;
167187

src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Windows.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using Xunit;
23
using System.Threading.Tasks;
34
using Microsoft.Maui.Controls;
45
using Microsoft.Maui.Handlers;
@@ -27,12 +28,54 @@ public async Task VerifyRadioButtonOpacityProperty()
2728
var handler = await CreateHandlerAsync<RadioButtonHandler>(radioButton);
2829
var nativeView = GetNativeRadioButton(handler);
2930
await InvokeOnMainThreadAsync(() =>
30-
{
31+
{
3132
var nativeOpacityValue = (float)nativeView.Opacity;
3233
Assert.Equal(expectedValue, nativeOpacityValue);
3334
});
3435
}
3536

37+
[Fact]
38+
[Description("The CornerRadius of a RadioButton should match with native CornerRadius")]
39+
public async Task RadioButtonCornerRadius()
40+
{
41+
var radioButton = new RadioButton();
42+
radioButton.CornerRadius = 15;
43+
var expectedValue = radioButton.CornerRadius;
44+
45+
var handler = await CreateHandlerAsync<RadioButtonHandler>(radioButton);
46+
var nativeView = GetNativeRadioButton(handler);
47+
await InvokeOnMainThreadAsync(() =>
48+
{
49+
var cornerRadiusTopLeft = (float)nativeView.CornerRadius.TopLeft;
50+
var cornerRadiusTopRight = (float)nativeView.CornerRadius.TopRight;
51+
var cornerRadiusBottomLeft = (float)nativeView.CornerRadius.BottomLeft;
52+
var cornerRadiusBottomRight = (float)nativeView.CornerRadius.BottomRight;
53+
Assert.Equal(expectedValue, cornerRadiusTopLeft);
54+
Assert.Equal(expectedValue, cornerRadiusTopRight);
55+
Assert.Equal(expectedValue, cornerRadiusBottomLeft);
56+
Assert.Equal(expectedValue, cornerRadiusBottomRight);
57+
});
58+
}
59+
60+
[Fact]
61+
[Description("The IsEnabled of a RadioButton should match with native IsEnabled")]
62+
public async Task VerifyRadioButtonIsEnabledProperty()
63+
{
64+
var radioButton = new RadioButton
65+
{
66+
IsEnabled = false
67+
};
68+
var expectedValue = radioButton.IsEnabled;
69+
70+
var handler = await CreateHandlerAsync<RadioButtonHandler>(radioButton);
71+
var nativeView = GetNativeRadioButton(handler);
72+
await InvokeOnMainThreadAsync(() =>
73+
{
74+
var isEnabled = nativeView.IsEnabled;
75+
Assert.Equal(expectedValue, isEnabled);
76+
});
77+
}
78+
3679
[Fact]
3780
[Description("The IsVisible property of a RadioButton should match with native IsVisible")]
3881
public async Task VerifyRadioButtonIsVisibleProperty()
@@ -50,4 +93,3 @@ await InvokeOnMainThreadAsync(() =>
5093
});
5194
}
5295
}
53-
}

0 commit comments

Comments
 (0)