Skip to content

Commit ee137cf

Browse files
Enabled the translation property for device tests
1 parent 42e2dc1 commit ee137cf

File tree

8 files changed

+234
-0
lines changed

8 files changed

+234
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22
using System.Threading.Tasks;
3+
using Microsoft.Maui.Controls;
34
using Microsoft.Maui.Graphics;
45
using Microsoft.Maui.Handlers;
56
using Microsoft.Maui.Platform;
7+
using Xunit;
8+
using System.ComponentModel;
69

710
namespace Microsoft.Maui.DeviceTests
811
{
@@ -19,5 +22,34 @@ Task<float> GetPlatformOpacity(ShapeViewHandler handler)
1922
return nativeView.Alpha;
2023
});
2124
}
25+
26+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
27+
[Fact]
28+
[Description("The Translation property of a BoxView should match with native Translation")]
29+
public async Task BoxViewTranslationConsistent()
30+
{
31+
var boxView = new BoxView()
32+
{
33+
HeightRequest = 100,
34+
WidthRequest = 200,
35+
TranslationX = 50,
36+
TranslationY = -20
37+
};
38+
39+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
40+
var nativeView = GetNativeBoxView(handler);
41+
await InvokeOnMainThreadAsync(() =>
42+
{
43+
var translation = nativeView.TranslationX;
44+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
45+
var expectedInPixels = density * boxView.TranslationX;
46+
47+
Assert.Equal(expectedInPixels, translation, 1.0);
48+
49+
var translationY = nativeView.TranslationY;
50+
var expectedYInPixels = density * boxView.TranslationY;
51+
Assert.Equal(expectedYInPixels, translationY, 1.0);
52+
});
53+
}
2254
}
2355
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,33 @@ await InvokeOnMainThreadAsync(async () =>
107107
Assert.Equal(expectedValue, nativeOpacityValue);
108108
});
109109
}
110+
111+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
112+
[Fact]
113+
[Description("The Translation property of a Button should match with native Translation")]
114+
public async Task ButtonTranslationConsistent()
115+
{
116+
var button = new Button()
117+
{
118+
Text = "Button Test",
119+
TranslationX = 50,
120+
TranslationY = -20
121+
};
122+
123+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
124+
var nativeView = GetPlatformButton(handler);
125+
await InvokeOnMainThreadAsync(() =>
126+
{
127+
var translation = nativeView.TranslationX;
128+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
129+
var expectedInPixels = density * button.TranslationX;
130+
131+
Assert.Equal(expectedInPixels, translation, 1.0);
132+
133+
var translationY = nativeView.TranslationY;
134+
var expectedYInPixels = density * button.TranslationY;
135+
Assert.Equal(expectedYInPixels, translationY, 1.0);
136+
});
137+
}
110138
}
111139
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Maui.Graphics;
66
using Microsoft.Maui.Handlers;
77
using Xunit;
8+
using System.ComponentModel;
89

910
namespace Microsoft.Maui.DeviceTests
1011
{
@@ -22,5 +23,32 @@ Task<float> GetPlatformOpacity(CheckBoxHandler CheckBoxHandler)
2223
return nativeView.Alpha;
2324
});
2425
}
26+
27+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
28+
[Fact]
29+
[Description("The Translation property of a CheckBox should match with native Translation")]
30+
public async Task CheckBoxTranslationConsistent()
31+
{
32+
var checkBox = new CheckBox()
33+
{
34+
TranslationX = 50,
35+
TranslationY = -20
36+
};
37+
38+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
39+
var nativeView = GetNativeCheckBox(handler);
40+
await InvokeOnMainThreadAsync(() =>
41+
{
42+
var translation = nativeView.TranslationX;
43+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
44+
var expectedInPixels = density * checkBox.TranslationX;
45+
46+
Assert.Equal(expectedInPixels, translation, 1.0);
47+
48+
var translationY = nativeView.TranslationY;
49+
var expectedYInPixels = density * checkBox.TranslationY;
50+
Assert.Equal(expectedYInPixels, translationY, 1.0);
51+
});
52+
}
2553
}
2654
}

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

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

78
namespace Microsoft.Maui.DeviceTests
89
{
@@ -66,5 +67,33 @@ public async Task CursorPositionPreservedWhenTextTransformPresent()
6667

6768
Assert.Equal(2, editor.CursorPosition);
6869
}
70+
71+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
72+
[Fact]
73+
[Description("The Translation property of a Editor should match with native Translation")]
74+
public async Task EditorTranslationConsistent()
75+
{
76+
var editor = new Editor()
77+
{
78+
Text = "Editor Test",
79+
TranslationX = 50,
80+
TranslationY = -20
81+
};
82+
83+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
84+
var nativeView = GetPlatformControl(handler);
85+
await InvokeOnMainThreadAsync(() =>
86+
{
87+
var translation = nativeView.TranslationX;
88+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
89+
var expectedInPixels = density * editor.TranslationX;
90+
91+
Assert.Equal(expectedInPixels, translation, 1.0);
92+
93+
var translationY = nativeView.TranslationY;
94+
var expectedYInPixels = density * editor.TranslationY;
95+
Assert.Equal(expectedYInPixels, translationY, 1.0);
96+
});
97+
}
6998
}
7099
}

src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs

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

78
namespace Microsoft.Maui.DeviceTests
89
{
@@ -80,5 +81,33 @@ public async Task UpdateTextWithTextLongerThanMaxLength()
8081

8182
Assert.Equal(longText[..4], entry.Text);
8283
}
84+
85+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
86+
[Fact]
87+
[Description("The Translation property of a Entry should match with native Translation")]
88+
public async Task EntryTranslationConsistent()
89+
{
90+
var entry = new Entry()
91+
{
92+
Text = "Entry Test",
93+
TranslationX = 50,
94+
TranslationY = -20
95+
};
96+
97+
var handler = await CreateHandlerAsync<EntryHandler>(entry);
98+
var nativeView = GetPlatformControl(handler);
99+
await InvokeOnMainThreadAsync(() =>
100+
{
101+
var translation = nativeView.TranslationX;
102+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
103+
var expectedInPixels = density * entry.TranslationX;
104+
105+
Assert.Equal(expectedInPixels, translation, 1.0);
106+
107+
var translationY = nativeView.TranslationY;
108+
var expectedYInPixels = density * entry.TranslationY;
109+
Assert.Equal(expectedYInPixels, translationY, 1.0);
110+
});
111+
}
83112
}
84113
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Maui.Handlers;
1212
using Microsoft.Maui.Platform;
1313
using Xunit;
14+
using System.ComponentModel;
1415

1516
namespace Microsoft.Maui.DeviceTests
1617
{
@@ -88,6 +89,34 @@ await InvokeOnMainThreadAsync((System.Action)(() =>
8889
}));
8990
}
9091

92+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
93+
[Fact]
94+
[Description("The Translation property of a Label should match with native Translation")]
95+
public async Task LabelTranslationConsistent()
96+
{
97+
var label = new Label()
98+
{
99+
Text = "Label Test",
100+
TranslationX = 50,
101+
TranslationY = -20
102+
};
103+
104+
var handler = await CreateHandlerAsync<LabelHandler>(label);
105+
var nativeView = GetPlatformLabel(handler);
106+
await InvokeOnMainThreadAsync(() =>
107+
{
108+
var translation = nativeView.TranslationX;
109+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
110+
var expectedInPixels = density * label.TranslationX;
111+
112+
Assert.Equal(expectedInPixels, translation, 1.0);
113+
114+
var translationY = nativeView.TranslationY;
115+
var expectedYInPixels = density * label.TranslationY;
116+
Assert.Equal(expectedYInPixels, translationY, 1.0);
117+
});
118+
}
119+
91120
TextView GetPlatformLabel(LabelHandler labelHandler) =>
92121
labelHandler.PlatformView;
93122

src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.Android.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System.Linq;
22
using System.Threading.Tasks;
33
using Android.Widget;
4+
using Microsoft.Maui.Controls;
45
using Microsoft.Maui.Handlers;
56
using Microsoft.Maui.Platform;
67
using SearchView = AndroidX.AppCompat.Widget.SearchView;
8+
using Xunit;
9+
using System.ComponentModel;
710

811
namespace Microsoft.Maui.DeviceTests
912
{
@@ -39,5 +42,33 @@ Task<float> GetPlatformOpacity(SearchBarHandler searchBarHandler)
3942
return nativeView.Alpha;
4043
});
4144
}
45+
46+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
47+
[Fact]
48+
[Description("The Translation property of a SearchBar should match with native Translation")]
49+
public async Task SearchBarTranslationConsistent()
50+
{
51+
var searchBar = new SearchBar()
52+
{
53+
Text = "SearchBar Test",
54+
TranslationX = 50,
55+
TranslationY = -20
56+
};
57+
58+
var handler = await CreateHandlerAsync<SearchBarHandler>(searchBar);
59+
var nativeView = GetPlatformControl(handler);
60+
await InvokeOnMainThreadAsync(() =>
61+
{
62+
var translation = nativeView.TranslationX;
63+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
64+
var expectedInPixels = density * searchBar.TranslationX;
65+
66+
Assert.Equal(expectedInPixels, translation, 1.0);
67+
68+
var translationY = nativeView.TranslationY;
69+
var expectedYInPixels = density * searchBar.TranslationY;
70+
Assert.Equal(expectedYInPixels, translationY, 1.0);
71+
});
72+
}
4273
}
4374
}

src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.Android.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,33 @@ await InvokeOnMainThreadAsync(() =>
9898
Assert.Equal(expectedValue, nativeOpacityValue);
9999
});
100100
}
101+
102+
//src/Compatibility/Core/tests/Android/TranslationTests.cs
103+
[Fact]
104+
[Description("The Translation property of a SwipeView should match with native Translation")]
105+
public async Task SwipeViewTranslationConsistent()
106+
{
107+
var swipeView = new SwipeView()
108+
{
109+
TranslationX = 50,
110+
TranslationY = -20
111+
};
112+
113+
var handler = await CreateHandlerAsync<SwipeViewHandler>(swipeView);
114+
var nativeView = GetPlatformControl(handler);
115+
await InvokeOnMainThreadAsync(() =>
116+
{
117+
var translation = nativeView.TranslationX;
118+
var density = Microsoft.Maui.Devices.DeviceDisplay.Current.MainDisplayInfo.Density;
119+
var expectedInPixels = density * swipeView.TranslationX;
120+
121+
Assert.Equal(expectedInPixels, translation, 1.0);
122+
123+
var translationY = nativeView.TranslationY;
124+
var expectedYInPixels = density * swipeView.TranslationY;
125+
Assert.Equal(expectedYInPixels, translationY, 1.0);
126+
});
127+
}
128+
101129
}
102130
}

0 commit comments

Comments
 (0)