Skip to content

Commit

Permalink
test: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed May 1, 2024
1 parent bea89ae commit ea22bd4
Showing 1 changed file with 206 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,212 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[TestClass]
public partial class Given_FrameworkElement
{
[TestMethod]
[RunsOnUIThread]
public async Task When_Clip_Two_Grids_With_Translate_And_Ellipse()
{
var redEllipse = new Ellipse()
{
Fill = new SolidColorBrush(Microsoft.UI.Colors.Red),
Width = 120,
Height = 120,
};

var grid = new Grid()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Blue),
BorderThickness = new(1),
RenderTransform = new TranslateTransform() { X = 20 },
Children =
{
redEllipse,
},
};

var parentGrid = new Grid()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Yellow),
BorderThickness = new(1),
Children =
{
grid,
},
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
};

var root = new Grid() { Children = { parentGrid }, Width = 150, Height = 150, Background = new SolidColorBrush(Microsoft.UI.Colors.Gray) };
await UITestHelper.Load(root);

var screenshot = await UITestHelper.ScreenShot(root);
var yellowBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Yellow, tolerance: 10);
var blueBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Blue, tolerance: 10);
var redBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Red, tolerance: 10);

Assert.AreEqual(new Rect(0, 0, 99, 99), yellowBounds);
Assert.AreEqual(new Rect(21, 1, 77, 97), blueBounds);
#if WINAPPSDK
Assert.AreEqual(new Rect(23, 3, 75, 95), redBounds);
#else
Assert.AreEqual(new Rect(22, 2, 76, 96), redBounds);
#endif
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Clip_Border_And_Clip_With_Translate_And_Ellipse()
{
var redEllipse = new Ellipse()
{
Fill = new SolidColorBrush(Microsoft.UI.Colors.Red),
Width = 120,
Height = 120,
};

var grid = new Grid()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Blue),
BorderThickness = new(1),
RenderTransform = new TranslateTransform() { X = 20 },
Children =
{
redEllipse,
},
};

var parentBorder = new Border()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Yellow),
BorderThickness = new(1),
Child = grid,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
};

var root = new Grid() { Children = { parentBorder }, Width = 150, Height = 150, Background = new SolidColorBrush(Microsoft.UI.Colors.Gray) };
await UITestHelper.Load(root);

var screenshot = await UITestHelper.ScreenShot(root);
var yellowBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Yellow, tolerance: 10);
var blueBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Blue, tolerance: 10);
var redBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Red, tolerance: 10);
Assert.AreEqual(new Rect(0, 0, 99, 99), yellowBounds);
Assert.AreEqual(new Rect(21, 1, 77, 97), blueBounds);
#if WINAPPSDK
Assert.AreEqual(new Rect(23, 3, 75, 95), redBounds);
#else
Assert.AreEqual(new Rect(22, 2, 76, 96), redBounds);
#endif
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Clip_Grid_And_Border_With_Translate_And_Ellipse()
{
var redEllipse = new Ellipse()
{
Fill = new SolidColorBrush(Microsoft.UI.Colors.Red),
Width = 120,
Height = 120,
};

var border = new Border()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Blue),
BorderThickness = new(1),
RenderTransform = new TranslateTransform() { X = 20 },
Child = redEllipse,
};

var parentGrid = new Grid()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Yellow),
BorderThickness = new(1),
Children =
{
border,
},
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
};

var root = new Grid() { Children = { parentGrid }, Width = 150, Height = 150, Background = new SolidColorBrush(Microsoft.UI.Colors.Gray) };
await UITestHelper.Load(root);

var screenshot = await UITestHelper.ScreenShot(root);
var yellowBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Yellow, tolerance: 10);
var blueBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Blue, tolerance: 10);
var redBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Red, tolerance: 10);

Assert.AreEqual(new Rect(0, 0, 99, 99), yellowBounds);
Assert.AreEqual(new Rect(21, 1, 97, 97), blueBounds);
#if WINAPPSDK
Assert.AreEqual(new Rect(23, 3, 95, 95), redBounds);
#else
Assert.AreEqual(new Rect(22, 2, 96, 96), redBounds);
#endif
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Clip_Two_Borders_With_Translate_And_Ellipse()
{
var redEllipse = new Ellipse()
{
Fill = new SolidColorBrush(Microsoft.UI.Colors.Red),
Width = 120,
Height = 120,
};

var border = new Border()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Blue),
BorderThickness = new(1),
RenderTransform = new TranslateTransform() { X = 20 },
Child = redEllipse,
};

var parentBorder = new Border()
{
Width = 100,
Height = 100,
BorderBrush = new SolidColorBrush(Microsoft.UI.Colors.Yellow),
BorderThickness = new(1),
Child = border,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
};

var root = new Grid() { Children = { parentBorder }, Width = 150, Height = 150, Background = new SolidColorBrush(Microsoft.UI.Colors.Gray) };
await UITestHelper.Load(root);

var screenshot = await UITestHelper.ScreenShot(root);
var yellowBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Yellow, tolerance: 10);
var blueBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Blue, tolerance: 10);
var redBounds = ImageAssert.GetColorBounds(screenshot, Microsoft.UI.Colors.Red, tolerance: 10);
Assert.AreEqual(new Rect(0, 0, 99, 99), yellowBounds);
Assert.AreEqual(new Rect(21, 1, 97, 97), blueBounds);
#if WINAPPSDK
Assert.AreEqual(new Rect(23, 3, 95, 95), redBounds);
#else
Assert.AreEqual(new Rect(22, 2, 96, 96), redBounds);
#endif
}

#if __WASM__
// TODO Android does not handle measure invalidation properly
[TestMethod]
Expand Down

0 comments on commit ea22bd4

Please sign in to comment.