Skip to content

[Housekeeping] Enabling ignored tests #20129

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
merged 8 commits into from
Feb 2, 2024
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 @@ -14,7 +14,7 @@ namespace Microsoft.Maui.DeviceTests
public abstract partial class HandlerTestBase<THandler, TStub>
{
[Fact]
public async Task DisconnectHandlerDoesntCrash()
public virtual async Task DisconnectHandlerDoesntCrash()
{
var handler = await CreateHandlerAsync(new TStub()) as IPlatformViewHandler;
await InvokeOnMainThreadAsync(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,18 @@ public async Task TextChangedEventsFireCorrectly(string initialText, string newT
Assert.Equal(0, eventFiredCount);
}

[Fact
#if WINDOWS
(Skip = "Failing on Windows")
#endif
]
[Fact]
public async Task CursorPositionDoesntResetWhenNativeTextValueChanges()
{
var textInput = new TStub()
{
Text = "Hello"
};


int cursorPosition = 0;
await InvokeOnMainThreadAsync(() =>

await AttachAndRun(textInput, handler =>
{
var handler = CreateHandler<THandler>(textInput);
UpdateCursorStartPosition(handler, 5);
handler.UpdateValue(nameof(ITextInput.Text));
cursorPosition = GetCursorStartPosition(handler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Xunit;

namespace Microsoft.Maui.DeviceTests
Expand All @@ -22,19 +20,21 @@ public async Task IsRunningInitializesCorrectly(bool isRunning)
await ValidatePropertyInitValue(activityIndicator, () => activityIndicator.IsRunning, GetNativeIsRunning, activityIndicator.IsRunning);
}

[Fact(DisplayName = "Background Updates Correctly"
#if WINDOWS
, Skip = "Failing on Windows"
#endif
)]
public async Task BackgroundUpdatesCorrectly()
[Theory(DisplayName = "Background Updates Correctly")]
[InlineData(0xFFFF0000)]
[InlineData(0xFF00FF00)]
[InlineData(0xFF0000FF)]
public async Task BackgroundUpdatesCorrectly(uint color)
{
var expected = Color.FromUint(color);

var activityIndicator = new ActivityIndicatorStub()
{
Background = new SolidPaintStub(Color.FromUint(0xFF888888)),
IsRunning = true
};

await ValidateHasColor(activityIndicator, Colors.Yellow, () => activityIndicator.Background = new SolidPaintStub(Colors.Yellow), nameof(activityIndicator.Background));
await ValidateHasColor(activityIndicator, expected, () => activityIndicator.Background = new SolidPaintStub(expected), nameof(activityIndicator.Background));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public async Task DashedStrokeInitializesCorrectly(uint color)
}

[Theory(DisplayName = "StrokeShape Initializes Correctly")]
[InlineData("Ellipse")]
[InlineData("Rectangle")]
[InlineData("RoundRectangle")]
public async Task StrokeShapeInitializesCorrectly(string shape)
Expand All @@ -91,6 +92,11 @@ public async Task StrokeShapeInitializesCorrectly(string shape)
Width = 300
};

if (shape == "Ellipse")
{
border.Shape = new EllipseShapeStub();
}

if (shape == "Rectangle")
{
border.Shape = new RectangleShapeStub();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ namespace Microsoft.Maui.DeviceTests
{
public partial class DatePickerHandlerTests
{
[Fact]
public override async Task DisconnectHandlerDoesntCrash()
{
var datePicker = new DatePickerStub
{
MinimumDate = DateTime.Today.AddDays(-1),
MaximumDate = DateTime.Today.AddDays(1),
Date = DateTime.Today
};

var handler = await CreateHandlerAsync(datePicker) as IPlatformViewHandler;
await InvokeOnMainThreadAsync(handler.DisconnectHandler);
}

[Theory(DisplayName = "Format Initializes Correctly")]
[InlineData("dd/MM/yyyy", "{day.integer(2)}/{month.integer(2)}/{year.full}")]
[InlineData("d/M/yy", "{day.integer}/{month.integer(1)}/{year.abbreviated}")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Xunit;
using static Microsoft.Maui.DeviceTests.AssertHelpers;

Expand All @@ -10,11 +8,7 @@ namespace Microsoft.Maui.DeviceTests
[Category(TestCategory.SearchBar)]
public partial class SearchBarHandlerTests : CoreHandlerTestBase<SearchBarHandler, SearchBarStub>
{
[Theory(DisplayName = "Background Initializes Correctly"
#if IOS || MACCATALYST
, Skip = "This test is currently invalid on iOS https://github.com/dotnet/maui/issues/13693"
#endif
)]
[Theory(DisplayName = "Background Initializes Correctly")]
[InlineData(0xFFFF0000)]
[InlineData(0xFF00FF00)]
[InlineData(0xFF0000FF)]
Expand All @@ -28,9 +22,17 @@ public async Task BackgroundInitializesCorrectly(uint color)
Text = "Background",
};

#if IOS || MACCATALYST
await ValidatePropertyInitValue(searchBar, () =>
(searchBar.Background as SolidPaint).Color,
GetNativeBackgroundColor,
(searchBar.Background as SolidPaint).Color);
#else
await ValidateHasColor(searchBar, expected);
#endif
}


[Fact(DisplayName = "Text Initializes Correctly")]
public async Task TextInitializesCorrectly()
{
Expand Down Expand Up @@ -255,11 +257,7 @@ public async Task MaxLengthInitializesCorrectly(int maxLength)
Assert.Equal(expectedText, platformText);
}

[Fact(DisplayName = "CancelButtonColor Initialize Correctly"
#if WINDOWS
, Skip = "Fails on Windows"
#endif
)]
[Fact(DisplayName = "CancelButtonColor Initialize Correctly")]
public async Task CancelButtonColorInitializeCorrectly()
{
var searchBar = new SearchBarStub()
Expand All @@ -269,7 +267,17 @@ public async Task CancelButtonColorInitializeCorrectly()
CancelButtonColor = Colors.Yellow,
};

#if WINDOWS
// The cancel button won't exist in the SearchBar until the SearchBar is loaded (and OnApplyTemplate is called)
// so we need to attach the SearchBar to the running app before we can check the color

await AttachAndRun(searchBar, async (searchBarHandler) =>
{
await ValidatePropertyInitValue(searchBar, () => searchBar.CancelButtonColor, GetNativeCancelButtonColor, Colors.Yellow);
});
#else
await ValidateHasColor(searchBar, Colors.Yellow);
#endif
}

[Fact(DisplayName = "Null Cancel Button Color Doesn't Crash")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ double GetInputFieldHeight(SearchBarHandler searchBarHandler)
static UISearchBar GetNativeSearchBar(SearchBarHandler searchBarHandler) =>
(UISearchBar)searchBarHandler.PlatformView;

Color GetNativeBackgroundColor(SearchBarHandler searchBarHandler) =>
GetNativeSearchBar(searchBarHandler).BarTintColor.ToColor();

string GetNativeText(SearchBarHandler searchBarHandler) =>
GetNativeSearchBar(searchBarHandler).Text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ namespace Microsoft.Maui.DeviceTests
{
public partial class SliderHandlerTests
{
[Fact(DisplayName = "Thumb Color Initializes Correctly")]
public async Task ThumbColorInitializesCorrectly()
{
var slider = new SliderStub()
{
ThumbColor = Colors.Purple
};

await ValidateNativeThumbColor(slider, Colors.Purple);
}

[Fact(DisplayName = "ThumbImageSource Initializes Correctly", Skip = "There seems to be an issue, so disable for now: https://github.com/dotnet/maui/issues/1275")]
public async Task ThumbImageSourceInitializesCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Xunit;
using static Microsoft.Maui.DeviceTests.AssertHelpers;
Expand All @@ -9,6 +8,28 @@ namespace Microsoft.Maui.DeviceTests
{
public partial class SliderHandlerTests
{
[Fact(DisplayName = "Thumb Color Initializes Correctly")]
public async Task ThumbColorInitializesCorrectly()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use this code for all the platforms?

{
var slider = new SliderStub()
{
ThumbColor = Colors.Purple
};

await InvokeOnMainThreadAsync(async () =>
{
var handler = CreateHandler(slider);

await handler.PlatformView.AttachAndRun(async () =>
{
await AssertEventually(() => handler.PlatformView.IsLoaded());

await ValidateNativeThumbColor(slider, Colors.Purple);
}, MauiContext);
});

}

// https://github.com/dotnet/maui/issues/12405
[Theory(DisplayName = "Platform Slider SmallChange Initializes Correctly")]
[InlineData(0, 1, 0)]
Expand Down Expand Up @@ -97,7 +118,7 @@ await handler.PlatformView.AttachAndRun(async () =>
});
}

Slider GetNativeSlider(SliderHandler sliderHandler) =>
UI.Xaml.Controls.Slider GetNativeSlider(SliderHandler sliderHandler) =>
sliderHandler.PlatformView;

double GetNativeProgress(SliderHandler sliderHandler) =>
Expand Down Expand Up @@ -128,5 +149,25 @@ bool ImageSourceLoaded(SliderHandler sliderHandler)
{
return (sliderHandler.PlatformView as MauiSlider)?.ThumbImageSource != null;
}

async Task ValidateNativeThumbColor(ISlider slider, Color color)
{
var expected = await GetValueAsync(slider, handler =>
{
var nativeSlider = GetNativeSlider(handler);

if (nativeSlider.GetFirstDescendant<Thumb>() is Thumb thumb)
{
if (thumb.Background is UI.Xaml.Media.SolidColorBrush solidThumb)
{
return solidThumb.Color.ToColor();
}
}

return null;
});

Assert.Equal(expected, color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ public async Task PercentValueInitializesCorrectly(double min, double max, doubl
Assert.Equal(expectedPercent, nativePercent, 5);
}

#if !WINDOWS
[Fact(DisplayName = "Thumb Color Initializes Correctly", Skip = "There seems to be an issue, so disable for now: https://github.com/dotnet/maui/issues/1275")]
public async Task ThumbColorInitializesCorrectly()
{
var slider = new SliderStub()
{
ThumbColor = Colors.Purple
};

await ValidateNativeThumbColor(slider, Colors.Purple);
}
#endif

[Fact(DisplayName = "Null Thumb Color Doesn't Crash")]
public async Task NullThumbColorDoesntCrash()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ namespace Microsoft.Maui.DeviceTests
{
public partial class SliderHandlerTests
{
[Fact(DisplayName = "Thumb Color Initializes Correctly")]
public async Task ThumbColorInitializesCorrectly()
{
var slider = new SliderStub()
{
ThumbColor = Colors.Purple
};

await ValidateNativeThumbColor(slider, Colors.Purple);
}

[Fact(DisplayName = "ThumbImageSource Initializes Correctly")]
public async Task ThumbImageSourceInitializesCorrectly()
{
Expand Down