Skip to content

[Testing] Migration of Compatibility.Core platform-specific unit tests into device tests - 6 #28399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ protected bool IsBackButtonVisible(IElementHandler handler)
return false;
}

protected void AssertTranslationMatches(Android.Views.View nativeView, double expectedTranslationX, double expectedTranslationY)
{
var context = nativeView?.Context ?? throw new InvalidOperationException("Context cannot be null.");

var expectedXInPixels = context.ToPixels(expectedTranslationX);
Assert.Equal(expectedXInPixels, nativeView.TranslationX, precision: 1);

var expectedYInPixels = context.ToPixels(expectedTranslationY);
Assert.Equal(expectedYInPixels, nativeView.TranslationY, precision: 1);
}

class WindowTestFragment : Fragment
{
TaskCompletionSource<bool> _taskCompletionSource = new TaskCompletionSource<bool>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,26 @@ Task<bool> GetPlatformIsVisible(ShapeViewHandler boxViewViewHandler)
return nativeView.Visibility == Android.Views.ViewStates.Visible;
});
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a BoxView should match with native Translation")]
public async Task BoxViewTranslationConsistent()
{
var boxView = new BoxView()
{
HeightRequest = 100,
WidthRequest = 200,
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
var nativeView = GetNativeBoxView(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, boxView.TranslationX, boxView.TranslationY);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,25 @@ public async Task RotationConsistent()
var platformRotation = await InvokeOnMainThreadAsync(() => platformButton.Rotation);
Assert.Equal(expected, platformRotation);
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a Button should match with native Translation")]
public async Task ButtonTranslationConsistent()
{
var button = new Button()
{
Text = "Button Test",
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<ButtonHandler>(button);
var nativeView = GetPlatformButton(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, button.TranslationX, button.TranslationY);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,24 @@ Task<bool> GetPlatformIsVisible(CheckBoxHandler checkBoxHandler)
return nativeView.Visibility == Android.Views.ViewStates.Visible;
});
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a CheckBox should match with native Translation")]
public async Task CheckBoxTranslationConsistent()
{
var checkBox = new CheckBox()
{
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
var nativeView = GetNativeCheckBox(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, checkBox.TranslationX, checkBox.TranslationY);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,25 @@ await InvokeOnMainThreadAsync(() =>
Assert.Equal(expectedValue, isEnabled);
});
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a Editor should match with native Translation")]
public async Task EditorTranslationConsistent()
{
var editor = new Editor()
{
Text = "Editor Test",
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<EditorHandler>(editor);
var nativeView = GetPlatformControl(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, editor.TranslationX, editor.TranslationY);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,25 @@ public async Task RotationConsistent()
var platformRotation = await InvokeOnMainThreadAsync(() => platformEntry.Rotation);
Assert.Equal(expected, platformRotation);
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a Entry should match with native Translation")]
public async Task EntryTranslationConsistent()
{
var entry = new Entry()
{
Text = "Entry Test",
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var nativeView = GetPlatformControl(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, entry.TranslationX, entry.TranslationY);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,26 @@ await InvokeOnMainThreadAsync(() =>
});
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a Label should match with native Translation")]
public async Task LabelTranslationConsistent()
{
var label = new Label()
{
Text = "Label Test",
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<LabelHandler>(label);
var nativeView = GetPlatformLabel(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, label.TranslationX, label.TranslationY);
});
}

TextView GetPlatformLabel(LabelHandler labelHandler) =>
labelHandler.PlatformView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,25 @@ Task<bool> GetPlatformIsVisible(SearchBarHandler searchBarHandler)
return nativeView.Visibility == Android.Views.ViewStates.Visible;
});
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a SearchBar should match with native Translation")]
public async Task SearchBarTranslationConsistent()
{
var searchBar = new SearchBar()
{
Text = "SearchBar Test",
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<SearchBarHandler>(searchBar);
var nativeView = GetPlatformControl(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, searchBar.TranslationX, searchBar.TranslationY);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ await InvokeOnMainThreadAsync(() =>
});
}

//src/Compatibility/Core/tests/Android/TranslationTests.cs
[Fact]
[Description("The Translation property of a SwipeView should match with native Translation")]
public async Task SwipeViewTranslationConsistent()
{
var swipeView = new SwipeView()
{
TranslationX = 50,
TranslationY = -20
};

var handler = await CreateHandlerAsync<SwipeViewHandler>(swipeView);
var nativeView = GetPlatformControl(handler);
await InvokeOnMainThreadAsync(() =>
{
AssertTranslationMatches(nativeView, swipeView.TranslationX, swipeView.TranslationY);
});
}

[Fact]
[Description("The IsEnabled of a SwipeView should match with native IsEnabled")]
public async Task VerifySwipeViewIsEnabledProperty()
Expand Down
Loading