Browse Source

Updated tests

pull/20954/head
Javier Suárez Ruiz 21 hours ago
parent
commit
ebd6d4034d
  1. 164
      tests/Avalonia.RenderTests/Controls/PipsPagerTests.cs
  2. BIN
      tests/TestFiles/Skia/Controls/PipsPager/PipsPager_Default.expected.png
  3. BIN
      tests/TestFiles/Skia/Controls/PipsPager/PipsPager_Preselected_Index.expected.png

164
tests/Avalonia.RenderTests/Controls/PipsPagerTests.cs

@ -1,11 +1,13 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Shapes;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Themes.Simple;
using Avalonia.Styling;
using Avalonia.Threading;
using Xunit;
#if AVALONIA_SKIA
@ -21,37 +23,118 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
{
}
private Decorator CreateTarget(int selectedPageIndex)
private static IControlTemplate CreatePipsPagerTemplate()
{
var pipsPager = new PipsPager
return new FuncControlTemplate<PipsPager>((control, scope) =>
{
NumberOfPages = 5,
SelectedPageIndex = selectedPageIndex,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
var stackPanel = new StackPanel
{
Name = "PART_RootPanel",
Spacing = 4,
[!StackPanel.OrientationProperty] = control[!PipsPager.OrientationProperty],
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
var target = new Decorator
{
Width = 400,
Height = 150,
Child = new Border
var buttonTemplate = new FuncControlTemplate<Button>((b, s) =>
new Border
{
Background = Brushes.LightGray,
Child = new TextBlock
{
[!TextBlock.TextProperty] = b[!Button.ContentProperty],
FontFamily = TestFontFamily,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
}
});
var prevButton = new Button
{
Background = Brushes.White,
Child = pipsPager
}
};
Name = "PART_PreviousButton",
Content = "<",
Template = buttonTemplate,
Width = 20,
Height = 20,
[!Button.IsVisibleProperty] = control[!PipsPager.IsPreviousButtonVisibleProperty]
}.RegisterInNameScope(scope);
AvaloniaLocator.CurrentMutable.Bind<ICursorFactory>().ToConstant(new CursorFactoryStub());
target.Styles.Add(new SimpleTheme());
var nextButton = new Button
{
Name = "PART_NextButton",
Content = ">",
Template = buttonTemplate,
Width = 20,
Height = 20,
[!Button.IsVisibleProperty] = control[!PipsPager.IsNextButtonVisibleProperty]
}.RegisterInNameScope(scope);
return target;
var listBoxTemplate = new FuncControlTemplate<ListBox>((lb, s) =>
new ItemsPresenter
{
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsPanelProperty] = lb[~ListBox.ItemsPanelProperty],
}.RegisterInNameScope(s));
var pipsList = new ListBox
{
Name = "PART_PipsPagerList",
Template = listBoxTemplate,
[!ListBox.ItemsSourceProperty] = new Binding("TemplateSettings.Pips") { Source = control },
[!ListBox.SelectedIndexProperty] = control[!PipsPager.SelectedPageIndexProperty],
ItemsPanel = new FuncTemplate<Panel?>(() => new StackPanel
{
Spacing = 2,
[!StackPanel.OrientationProperty] = control[!PipsPager.OrientationProperty]
})
}.RegisterInNameScope(scope);
var itemStyle = new Style(x => x.OfType<ListBoxItem>());
itemStyle.Setters.Add(new Setter(ListBoxItem.TemplateProperty,
new FuncControlTemplate<ListBoxItem>((item, s) =>
new Rectangle { Name = "Pip", Width = 10, Height = 10 }.RegisterInNameScope(s))));
var defaultPipStyle = new Style(x => x.OfType<ListBoxItem>().Template().Name("Pip"));
defaultPipStyle.Setters.Add(new Setter(Rectangle.FillProperty, Brushes.Gray));
var selectedStyle = new Style(x => x.OfType<ListBoxItem>().Class(":selected").Template().Name("Pip"));
selectedStyle.Setters.Add(new Setter(Rectangle.FillProperty, Brushes.Red));
pipsList.Styles.Add(itemStyle);
pipsList.Styles.Add(defaultPipStyle);
pipsList.Styles.Add(selectedStyle);
stackPanel.Children.Add(prevButton);
stackPanel.Children.Add(pipsList);
stackPanel.Children.Add(nextButton);
return stackPanel;
});
}
[Fact]
public async Task PipsPager_Default()
{
var target = CreateTarget(1);
var pipsPager = new PipsPager
{
Template = CreatePipsPagerTemplate(),
NumberOfPages = 5,
SelectedPageIndex = 1
};
var target = new Border
{
Padding = new Thickness(20),
Background = Brushes.White,
Child = pipsPager,
Width = 400,
Height = 150
};
target.Measure(new Size(400, 150));
target.Arrange(new Rect(0, 0, 400, 150));
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
await RenderToFile(target);
CompareImages(skipImmediate: true);
}
@ -59,23 +142,28 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
[Fact]
public async Task PipsPager_Preselected_Index()
{
var target = CreateTarget(3);
await RenderToFile(target);
CompareImages(skipImmediate: true);
}
var pipsPager = new PipsPager
{
Template = CreatePipsPagerTemplate(),
NumberOfPages = 5,
SelectedPageIndex = 3
};
private sealed class CursorFactoryStub : ICursorFactory
{
public ICursorImpl GetCursor(StandardCursorType cursorType) => new CursorStub();
var target = new Border
{
Padding = new Thickness(20),
Background = Brushes.White,
Child = pipsPager,
Width = 400,
Height = 150
};
public ICursorImpl CreateCursor(Bitmap cursor, PixelPoint hotSpot) => new CursorStub();
target.Measure(new Size(400, 150));
target.Arrange(new Rect(0, 0, 400, 150));
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
private sealed class CursorStub : ICursorImpl
{
public void Dispose()
{
}
}
await RenderToFile(target);
CompareImages(skipImmediate: true);
}
}
}

BIN
tests/TestFiles/Skia/Controls/PipsPager/PipsPager_Default.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
tests/TestFiles/Skia/Controls/PipsPager/PipsPager_Preselected_Index.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Loading…
Cancel
Save