Skip to content
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 @@ -5,6 +5,8 @@
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Xunit;
using System.Collections.ObjectModel;
using System.Linq;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -86,6 +88,102 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(contentPage,
});
}

//src/Compatibility/Core/tests/Android/RendererTests.cs
[Fact(DisplayName = "EmptySource should have a count of zero")]
[Trait("Category", "CollectionView")]
public void EmptySourceCountIsZero()
{
var emptySource = new EmptySource();
var count = emptySource.Count;
Assert.Equal(0, count);
}

//src/Compatibility/Core/tests/Android/ObservableItemsSourceTests.cs#L52
[Fact(DisplayName = "CollectionView with SnapPointsType set should not crash")]
public async Task SnapPointsDoNotCrashOnOlderAPIs()
{
SetupBuilder();

var collectionView = new CollectionView();

var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical)
{
SnapPointsType = SnapPointsType.Mandatory
};
collectionView.ItemsLayout = itemsLayout;

await InvokeOnMainThreadAsync(() =>
{
var handler = CreateHandler<CollectionViewHandler>(collectionView);

var platformView = handler.PlatformView;

collectionView.Handler = null;
});
}

//src/Compatibility/Core/tests/Android/ObservableItemsSourceTests.cs#L52
[Fact(DisplayName = "ObservableCollection modifications are reflected after UI thread processes them")]
public async Task ObservableSourceItemsCountConsistent()
{
SetupBuilder();

var source = new ObservableCollection<string>();
source.Add("Item 1");
source.Add("Item 2");
var ois = ItemsSourceFactory.Create(source, Application.Current, new MockCollectionChangedNotifier());

Assert.Equal(2, ois.Count);

source.Add("Item 3");
var count = 0;
await InvokeOnMainThreadAsync(() =>
{
count = ois.Count;
Assert.Equal(3, ois.Count);
});
}

class MockCollectionChangedNotifier : ICollectionChangedNotifier
{
public int InsertCount;
public int RemoveCount;

public void NotifyDataSetChanged()
{
}

public void NotifyItemChanged(IItemsViewSource source, int startIndex)
{
}

public void NotifyItemInserted(IItemsViewSource source, int startIndex)
{
InsertCount += 1;
}

public void NotifyItemMoved(IItemsViewSource source, int fromPosition, int toPosition)
{
}

public void NotifyItemRangeChanged(IItemsViewSource source, int start, int end)
{
}

public void NotifyItemRangeInserted(IItemsViewSource source, int startIndex, int count)
{
}

public void NotifyItemRangeRemoved(IItemsViewSource source, int startIndex, int count)
{
}

public void NotifyItemRemoved(IItemsViewSource source, int startIndex)
{
RemoveCount += 1;
}
}

Rect GetCollectionViewCellBounds(IView cellContent)
{
if (!cellContent.ToPlatform().IsLoaded())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using UIKit;
using Xunit;
using Xunit.Sdk;
using Foundation;
using Microsoft.Maui.Handlers;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -125,6 +127,73 @@ await InvokeOnMainThreadAsync(() =>
#endif
}

//src/Compatibility/Core/tests/iOS/ObservableItemsSourceTests.cs
[Fact(DisplayName = "IndexPath Range Generation Is Correct")]
public void GenerateIndexPathRange()
{
SetupBuilder();

var result = IndexPathHelpers.GenerateIndexPathRange(0, 0, 5);

Assert.Equal(5, result.Length);

Assert.Equal(0, result[0].Section);
Assert.Equal(0, (int)result[0].Item);

Assert.Equal(0, result[4].Section);
Assert.Equal(4, (int)result[4].Item);
}

//src/Compatibility/Core/tests/iOS/ObservableItemsSourceTests.cs
[Fact(DisplayName = "IndexPath Range Generation For Loops Is Correct")]
public void GenerateIndexPathRangeForLoop()
{
SetupBuilder();

var result = IndexPathHelpers.GenerateLoopedIndexPathRange(0, 15, 3, 2, 3);

Assert.Equal(9, result.Length);

for (int i = 0; i < result.Length; i++)
{
Assert.Equal(0, result[i].Section);
}

Assert.Equal(2, (int)result[0].Item);
Assert.Equal(3, (int)result[1].Item);
Assert.Equal(4, (int)result[2].Item);

Assert.Equal(7, (int)result[3].Item);
Assert.Equal(8, (int)result[4].Item);
Assert.Equal(9, (int)result[5].Item);

Assert.Equal(12, (int)result[6].Item);
Assert.Equal(13, (int)result[7].Item);
Assert.Equal(14, (int)result[8].Item);
}

//src/Compatibility/Core/tests/iOS/ObservableItemsSourceTests.cs
[Fact(DisplayName = "IndexPath Validity Check Is Correct")]
public void IndexPathValidTest()
{
var list = new List<string>
{
"one",
"two",
"three"
};

var source = new ListSource((IEnumerable<object>)list);

var valid = NSIndexPath.FromItemSection(2, 0);
var invalidItem = NSIndexPath.FromItemSection(7, 0);
var invalidSection = NSIndexPath.FromItemSection(1, 9);

Assert.True(source.IsIndexPathValid(valid));
Assert.False(source.IsIndexPathValid(invalidItem));
Assert.False(source.IsIndexPathValid(invalidSection));
}

/// <summary>
/// Simulates what a developer might do with a Page/View
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,68 @@ await CreateHandlerAndAddToWindow<ShellRenderer>(shell, async (handler) =>
});
}

//src/Compatibility/Core/tests/Android/ShellTests.cs
[Fact(DisplayName = "Flyout Header Changes When Updated")]
public async Task FlyoutHeaderReactsToChanges()
{
SetupBuilder();

var initialHeader = new Label() { Text = "Hello" };
var newHeader = new Label() { Text = "Hello Part 2" };

var shell = await CreateShellAsync(shell =>
{
shell.CurrentItem = new FlyoutItem() { Items = { new ContentPage() }, Title = "Flyout Item" };
shell.FlyoutHeader = initialHeader;
});

await CreateHandlerAndAddToWindow<ShellRenderer>(shell, async (handler) =>
{
var initialHeaderPlatformView = initialHeader.ToPlatform();
Assert.NotNull(initialHeaderPlatformView);
Assert.NotNull(initialHeader.Handler);

shell.FlyoutHeader = newHeader;

var newHeaderPlatformView = newHeader.ToPlatform();
Assert.NotNull(newHeaderPlatformView);
Assert.NotNull(newHeader.Handler);

Assert.Null(initialHeader.Handler);

await OpenFlyout(handler);

var appBar = newHeaderPlatformView.GetParentOfType<AppBarLayout>();
Assert.NotNull(appBar);
});
}

//src/Compatibility/Core/tests/Android/ShellTests.cs
[Fact(DisplayName = "Ensure Default Colors are White for BottomNavigationView")]
public async Task ShellTabColorsDefaultToWhite()
{
SetupBuilder();

var shell = await CreateShellAsync(shell =>
{
shell.Items.Add(new Tab() { Items = { new ContentPage() }, Title = "Tab 1" });
});

await CreateHandlerAndAddToWindow<ShellRenderer>(shell, (handler) =>
{
var bottomNavigationView = GetDrawerLayout(handler).GetFirstChildOfType<BottomNavigationView>();
Assert.NotNull(bottomNavigationView);

var background = bottomNavigationView.Background;
Assert.NotNull(background);

if (background is ColorChangeRevealDrawable changeRevealDrawable)
{
Assert.Equal(Android.Graphics.Color.White, changeRevealDrawable.EndColor);
}
});
}

protected AView GetFlyoutPlatformView(ShellRenderer shellRenderer)
{
var drawerLayout = GetDrawerLayout(shellRenderer);
Expand Down
Loading