CommandBarTests.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 CommandBarRenderTests : TestBase
  16. {
  17. public CommandBarRenderTests()
  18. : base(@"Controls\CommandBar")
  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 CommandBar_Default_PrimaryCommands()
  27. {
  28. var target = new Decorator
  29. {
  30. Width = 500,
  31. Height = 60,
  32. Child = new CommandBar
  33. {
  34. Background = Brushes.LightGray,
  35. PrimaryCommands =
  36. {
  37. new CommandBarButton
  38. {
  39. Label = "New",
  40. Icon = new Path
  41. {
  42. Data = StreamGeometry.Parse("M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"),
  43. Fill = Brushes.Black,
  44. Width = 20,
  45. Height = 20,
  46. Stretch = Stretch.Uniform
  47. }
  48. },
  49. new CommandBarButton
  50. {
  51. Label = "Save",
  52. Icon = new Path
  53. {
  54. 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"),
  55. Fill = Brushes.Black,
  56. Width = 20,
  57. Height = 20,
  58. Stretch = Stretch.Uniform
  59. }
  60. },
  61. new CommandBarSeparator(),
  62. new CommandBarToggleButton
  63. {
  64. Label = "Bold",
  65. Icon = new Path
  66. {
  67. 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"),
  68. Fill = Brushes.Black,
  69. Width = 20,
  70. Height = 20,
  71. Stretch = Stretch.Uniform
  72. }
  73. }
  74. }
  75. }
  76. };
  77. target.Styles.Add(new SimpleTheme());
  78. target.Styles.Add(FontStyle);
  79. await RenderToFile(target);
  80. CompareImages(skipImmediate: true);
  81. }
  82. [Fact]
  83. public async Task CommandBar_Compact_LabelCollapsed()
  84. {
  85. var target = new Decorator
  86. {
  87. Width = 300,
  88. Height = 60,
  89. Child = new CommandBar
  90. {
  91. Background = Brushes.LightGray,
  92. DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed,
  93. OverflowButtonVisibility = CommandBarOverflowButtonVisibility.Collapsed,
  94. PrimaryCommands =
  95. {
  96. new CommandBarButton
  97. {
  98. Icon = new Path
  99. {
  100. Data = StreamGeometry.Parse("M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"),
  101. Fill = Brushes.Black,
  102. Width = 20,
  103. Height = 20,
  104. Stretch = Stretch.Uniform
  105. }
  106. },
  107. new CommandBarButton
  108. {
  109. Icon = new Path
  110. {
  111. 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"),
  112. Fill = Brushes.Black,
  113. Width = 20,
  114. Height = 20,
  115. Stretch = Stretch.Uniform
  116. }
  117. },
  118. new CommandBarSeparator(),
  119. new CommandBarToggleButton
  120. {
  121. IsChecked = true,
  122. Icon = new Path
  123. {
  124. 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"),
  125. Fill = Brushes.Black,
  126. Width = 20,
  127. Height = 20,
  128. Stretch = Stretch.Uniform
  129. }
  130. }
  131. }
  132. }
  133. };
  134. target.Styles.Add(new SimpleTheme());
  135. target.Styles.Add(FontStyle);
  136. await RenderToFile(target);
  137. CompareImages(skipImmediate: true);
  138. }
  139. }
  140. }