-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the device tests to avoid duplicate tests (#14466)
* Refactor the device tests to avoid duplicate tests * Several duplicated tests because the HandlerTestBase class was re-used for the same control * There is now a new HandlerTestBasement with _just_ helper methods for all handler tests * Refactored the set of cross-handler tests for Focus, TextInput and TextStyle to depend on HandlerTestBasement * Not all platforms support all the permutations, yet...
- Loading branch information
1 parent
20e6293
commit 523653d
Showing
34 changed files
with
1,094 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Core/tests/DeviceTests.Shared/Core.DeviceTests.Shared.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/Core/tests/DeviceTests.Shared/HandlerTests/Focus/FocusHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.DeviceTests.Stubs; | ||
using Microsoft.Maui.Hosting; | ||
using Xunit; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public abstract partial class FocusHandlerTests<THandler, TStub, TLayoutStub> : HandlerTestBasement<THandler, TStub> | ||
where THandler : class, IViewHandler, new() | ||
where TStub : IStubBase, new() | ||
where TLayoutStub : IStubBase, ILayout, new() | ||
{ | ||
[Fact] | ||
public async Task FocusAndIsFocusedIsWorking() | ||
{ | ||
EnsureHandlerCreated(builder => | ||
{ | ||
builder.ConfigureMauiHandlers(handler => | ||
{ | ||
handler.AddHandler<TLayoutStub, LayoutHandler>(); | ||
handler.AddHandler<TStub, THandler>(); | ||
}); | ||
}); | ||
|
||
// create layout with 2 elements | ||
TStub inputControl1; | ||
TStub inputControl2; | ||
var layout = new TLayoutStub | ||
{ | ||
(inputControl1 = new TStub { Width = 100, Height = 50 }), | ||
(inputControl2 = new TStub { Width = 100, Height = 50 }) | ||
}; | ||
layout.Width = 100; | ||
layout.Height = 150; | ||
|
||
await InvokeOnMainThreadAsync(async () => | ||
{ | ||
var contentViewHandler = CreateHandler<LayoutHandler>(layout); | ||
await contentViewHandler.PlatformView.AttachAndRun(async () => | ||
{ | ||
var platform1 = inputControl1.ToPlatform(); | ||
var platform2 = inputControl2.ToPlatform(); | ||
|
||
// focus the first control | ||
inputControl1.Handler.Invoke(nameof(IView.Focus), new FocusRequest(false)); | ||
|
||
// assert | ||
await inputControl1.WaitForFocused(); | ||
Assert.True(inputControl1.IsFocused); | ||
Assert.False(inputControl2.IsFocused); | ||
|
||
// focus the second control | ||
inputControl2.Handler.Invoke(nameof(IView.Focus), new FocusRequest(false)); | ||
|
||
// assert | ||
await inputControl2.WaitForFocused(); | ||
Assert.False(inputControl1.IsFocused); | ||
Assert.True(inputControl2.IsFocused); | ||
}); | ||
}); | ||
} | ||
|
||
// TODO: Android is not unfocusing | ||
#if IOS || MACCATALYST || WINDOWS | ||
[Fact] | ||
public async Task UnfocusAndIsFocusedIsWorking() | ||
{ | ||
EnsureHandlerCreated(builder => | ||
{ | ||
builder.ConfigureMauiHandlers(handler => | ||
{ | ||
handler.AddHandler<TLayoutStub, LayoutHandler>(); | ||
handler.AddHandler<TStub, THandler>(); | ||
}); | ||
}); | ||
|
||
// create layout with 2 elements | ||
TStub inputControl1; | ||
TStub inputControl2; | ||
var layout = new TLayoutStub | ||
{ | ||
(inputControl1 = new TStub { Width = 100, Height = 50 }), | ||
(inputControl2 = new TStub { Width = 100, Height = 50 }) | ||
}; | ||
layout.Width = 100; | ||
layout.Height = 150; | ||
|
||
await InvokeOnMainThreadAsync(async () => | ||
{ | ||
var contentViewHandler = CreateHandler<LayoutHandler>(layout); | ||
await contentViewHandler.PlatformView.AttachAndRun(async () => | ||
{ | ||
var platform1 = inputControl1.ToPlatform(); | ||
var platform2 = inputControl2.ToPlatform(); | ||
|
||
// focus the first control | ||
inputControl1.Handler.Invoke(nameof(IView.Focus), new FocusRequest(false)); | ||
|
||
// assert | ||
await inputControl1.WaitForFocused(); | ||
Assert.True(inputControl1.IsFocused); | ||
Assert.False(inputControl2.IsFocused); | ||
|
||
// UNfocus the first control (revert the focus) | ||
inputControl1.Handler.Invoke(nameof(IView.Unfocus)); | ||
|
||
// assert | ||
await inputControl1.WaitForUnFocused(); | ||
Assert.False(inputControl1.IsFocused); | ||
Assert.False(inputControl2.IsFocused); | ||
}); | ||
}); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.