Skip to content

Commit

Permalink
chore: Workaround test to pass on android
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed Oct 10, 2024
1 parent b570680 commit 3628d17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 11 additions & 6 deletions src/Uno.Toolkit.RuntimeTests/Tests/TabBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,20 @@ public async Task Verify_ItemTemplated_Disabled_Not_Selectable()
new TestRecord("False", false),
new TestRecord("True", true)
};
var SUT = new TabBar
{
Style = (Style)Application.Current.Resources["TopTabBarStyle"],
ItemsSource = source,
ItemTemplate = XamlHelper.LoadXaml<DataTemplate>(@"

var dt = XamlHelper.LoadXaml<DataTemplate>(@"
<DataTemplate>
<utu:TabBarItem Content=""{Binding Name}"" IsSelectable=""{Binding IsSelectable}"" />
</DataTemplate>
")
");

var SUT = new TabBar
{
// If `ItemTemplate` is not set first then the order of
// `OnItemTemplateChanged` and `GetContainerForItemOverride` are not correct and test fail on android
ItemTemplate = dt,
Style = (Style)Application.Current.Resources["TopTabBarStyle"],
ItemsSource = source
};

await UnitTestUIContentHelperEx.SetContentAndWait(SUT);
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ private void RaiseSelectionChangedEvent(object? prevItem, object? nextItem)

internal TabBarItem? GetInnerContainer(DependencyObject? container)
{
if (IsUsingOwnContainerAsTemplateRoot)
if (IsUsingOwnContainerAsTemplateRoot && container is ContentPresenter cp)
{
return (container as ContentPresenter)?.Content as TabBarItem;
return cp.Content as TabBarItem;
}

return container as TabBarItem;
Expand All @@ -421,9 +421,9 @@ private void RaiseSelectionChangedEvent(object? prevItem, object? nextItem)
internal DependencyObject? InnerContainerFromIndex(int index)
{
var container = ContainerFromIndex(index);
if (IsUsingOwnContainerAsTemplateRoot)
if (IsUsingOwnContainerAsTemplateRoot && container is ContentPresenter cp)
{
container = (container as ContentPresenter)?.Content as DependencyObject;
container = cp.Content as DependencyObject;
}

return container;
Expand Down

0 comments on commit 3628d17

Please sign in to comment.