ContentPageTests.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System.Threading.Tasks;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Shapes;
  4. using Avalonia.Layout;
  5. using Avalonia.Media;
  6. using Avalonia.Styling;
  7. using Avalonia.Themes.Simple;
  8. using Xunit;
  9. #if AVALONIA_SKIA
  10. namespace Avalonia.Skia.RenderTests
  11. #else
  12. namespace Avalonia.Direct2D1.RenderTests.Controls
  13. #endif
  14. {
  15. public class ContentPageRenderTests : TestBase
  16. {
  17. public ContentPageRenderTests()
  18. : base(@"Controls\ContentPage")
  19. {
  20. }
  21. private static Style FontStyle => new Style(x => x.OfType<TextBlock>())
  22. {
  23. Setters = { new Setter(TextBlock.FontFamilyProperty, TestFontFamily) }
  24. };
  25. [Fact]
  26. public async Task ContentPage_Default_Content()
  27. {
  28. var target = new Decorator
  29. {
  30. Width = 400,
  31. Height = 200,
  32. Child = new ContentPage
  33. {
  34. Background = Brushes.White,
  35. Header = "My Page",
  36. Content = new Border
  37. {
  38. Width = 120,
  39. Height = 40,
  40. Background = new SolidColorBrush(Color.Parse("#F5F5F5")),
  41. HorizontalAlignment = HorizontalAlignment.Center,
  42. VerticalAlignment = VerticalAlignment.Center
  43. },
  44. HorizontalContentAlignment = HorizontalAlignment.Center,
  45. VerticalContentAlignment = VerticalAlignment.Center
  46. }
  47. };
  48. target.Styles.Add(new SimpleTheme());
  49. target.Styles.Add(FontStyle);
  50. await RenderToFile(target);
  51. CompareImages(skipImmediate: true);
  52. }
  53. [Fact]
  54. public async Task ContentPage_WithTopAndBottomCommandBars()
  55. {
  56. var target = new Decorator
  57. {
  58. Width = 400,
  59. Height = 260,
  60. Child = new ContentPage
  61. {
  62. Background = Brushes.White,
  63. Header = "Editor",
  64. TopCommandBar = new CommandBar
  65. {
  66. Background = Brushes.LightGray,
  67. PrimaryCommands =
  68. {
  69. new CommandBarButton
  70. {
  71. Label = "Save",
  72. Icon = new Path
  73. {
  74. Data = StreamGeometry.Parse("M15,9H5V5H15M12,19A3,3 0 0,1 9,16A3,3 0 0,1 12,13A3,3 0 0,1 15,16A3,3 0 0,1 12,19M17,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V7L17,3Z"),
  75. Fill = Brushes.Black,
  76. Width = 20,
  77. Height = 20,
  78. Stretch = Stretch.Uniform
  79. }
  80. },
  81. new CommandBarSeparator(),
  82. new CommandBarToggleButton
  83. {
  84. Label = "Bold",
  85. Icon = new Path
  86. {
  87. Data = StreamGeometry.Parse("M15.6,10.79C17.04,10.07 18,8.64 18,7C18,4.79 16.21,3 14,3H7V21H14.73C16.78,21 18.5,19.37 18.5,17.32C18.5,15.82 17.72,14.53 16.5,13.77C16.2,13.59 15.9,13.44 15.6,13.32V10.79M10,6.5H13C13.83,6.5 14.5,7.17 14.5,8C14.5,8.83 13.83,9.5 13,9.5H10V6.5M13.5,17.5H10V14H13.5C14.33,14 15,14.67 15,15.5C15,16.33 14.33,17.5 13.5,17.5Z"),
  88. Fill = Brushes.Black,
  89. Width = 20,
  90. Height = 20,
  91. Stretch = Stretch.Uniform
  92. }
  93. }
  94. }
  95. },
  96. BottomCommandBar = new CommandBar
  97. {
  98. Background = Brushes.LightGray,
  99. DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed,
  100. OverflowButtonVisibility = CommandBarOverflowButtonVisibility.Collapsed,
  101. PrimaryCommands =
  102. {
  103. new CommandBarButton
  104. {
  105. Icon = new Path
  106. {
  107. Data = StreamGeometry.Parse("M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"),
  108. Fill = Brushes.Black,
  109. Width = 20,
  110. Height = 20,
  111. Stretch = Stretch.Uniform
  112. }
  113. }
  114. }
  115. },
  116. Content = new Border
  117. {
  118. Width = 120,
  119. Height = 40,
  120. Background = new SolidColorBrush(Color.Parse("#F5F5F5")),
  121. HorizontalAlignment = HorizontalAlignment.Center,
  122. VerticalAlignment = VerticalAlignment.Center
  123. },
  124. HorizontalContentAlignment = HorizontalAlignment.Center,
  125. VerticalContentAlignment = VerticalAlignment.Center
  126. }
  127. };
  128. target.Styles.Add(new SimpleTheme());
  129. target.Styles.Add(FontStyle);
  130. await RenderToFile(target);
  131. CompareImages(skipImmediate: true);
  132. }
  133. }
  134. }