-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
- Loading branch information
1 parent
dfaa042
commit aa817b5
Showing
11 changed files
with
126 additions
and
7 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
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
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
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
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
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
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
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
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
74 changes: 74 additions & 0 deletions
74
src/Controls/tests/Core.UnitTests/VisualTreeHelperTests.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,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Graphics; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class VisualTreeHelperTests : BaseTestFixture | ||
{ | ||
[Test] | ||
public void VerticalStackLayoutChildren() | ||
{ | ||
var verticalStackLayout = new VerticalStackLayout() { IsPlatformEnabled = true }; | ||
verticalStackLayout.Children.Add(new Label()); | ||
verticalStackLayout.Children.Add(new Button()); | ||
Assert.AreEqual(verticalStackLayout.Children.Count, (verticalStackLayout as IVisualTreeElement).GetVisualChildren().Count); | ||
} | ||
|
||
[Test] | ||
public void HorizontalStackLayoutChildren() | ||
{ | ||
var horizontalStackLayout = new HorizontalStackLayout() { IsPlatformEnabled = true }; | ||
horizontalStackLayout.Children.Add(new Label()); | ||
horizontalStackLayout.Children.Add(new Button()); | ||
Assert.AreEqual(horizontalStackLayout.Children.Count, (horizontalStackLayout as IVisualTreeElement).GetVisualChildren().Count); | ||
} | ||
|
||
[Test] | ||
public void StackLayoutChildren() | ||
{ | ||
var stackLayout = new StackLayout() { IsPlatformEnabled = true }; | ||
stackLayout.Children.Add(new Label()); | ||
stackLayout.Children.Add(new Button()); | ||
Assert.AreEqual(stackLayout.Children.Count, (stackLayout as IVisualTreeElement).GetVisualChildren().Count); | ||
} | ||
|
||
[Test] | ||
public void ApplicationChildren() | ||
{ | ||
var app = new Application(); | ||
var iapp = app as IApplication; | ||
var page = new ContentPage(); | ||
|
||
app.MainPage = page; | ||
|
||
var window = iapp.CreateWindow(null); | ||
|
||
var appChildren = (app as IVisualTreeElement).GetVisualChildren(); | ||
var windowChildren = (window as IVisualTreeElement).GetVisualChildren(); | ||
Assert.Greater(appChildren.Count, 0); | ||
Assert.IsTrue(appChildren[0] is IWindow); | ||
Assert.AreEqual(windowChildren.Count, 1); | ||
} | ||
|
||
[Test] | ||
public void VisualElementParent() | ||
{ | ||
var app = new Application(); | ||
var iapp = app as IApplication; | ||
var page = new ContentPage(); | ||
app.MainPage = page; | ||
var window = iapp.CreateWindow(null); | ||
var appParent = (app as IVisualTreeElement).GetVisualParent(); | ||
var windowParent = (window as IVisualTreeElement).GetVisualParent(); | ||
Assert.IsNull(appParent); | ||
Assert.IsNotNull(windowParent); | ||
} | ||
} | ||
} |
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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public interface IVisualTreeElement | ||
{ | ||
IReadOnlyList<IVisualTreeElement> GetVisualChildren(); | ||
|
||
IVisualTreeElement? GetVisualParent(); | ||
} | ||
} |