TableWithVerticalHeadersTests.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using QuestPDF.ConformanceTests.TestEngine;
  2. using QuestPDF.Drawing;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.ConformanceTests.Table;
  7. internal class TableWithVerticalHeadersTests : ConformanceTestBase
  8. {
  9. protected override Document GetDocumentUnderTest()
  10. {
  11. return Document
  12. .Create(document =>
  13. {
  14. document.Page(page =>
  15. {
  16. page.Margin(60);
  17. page.Content()
  18. .Shrink()
  19. .Border(1)
  20. .BorderColor(Colors.Grey.Darken1)
  21. .SemanticTable()
  22. .Table(table =>
  23. {
  24. table.ColumnsDefinition(columns =>
  25. {
  26. columns.RelativeColumn();
  27. columns.RelativeColumn();
  28. columns.RelativeColumn();
  29. columns.RelativeColumn();
  30. });
  31. table.Header(header =>
  32. {
  33. header.Cell().Element(HeaderCellStyle).Text("Name");
  34. header.Cell().Element(HeaderCellStyle).Text("Position");
  35. header.Cell().Element(HeaderCellStyle).Text("Department");
  36. header.Cell().Element(HeaderCellStyle).Text("Experience");
  37. });
  38. // Row 1:
  39. table.Cell().Element(CellStyle).Text("John Smith");
  40. table.Cell().Element(CellStyle).Text("Senior Developer");
  41. table.Cell().Element(CellStyle).Text("Engineering");
  42. table.Cell().Element(CellStyle).Text("5 years");
  43. // Row 2:
  44. table.Cell().Element(CellStyle).Text("Jane Doe");
  45. table.Cell().Element(CellStyle).Text("UX Designer");
  46. table.Cell().Element(CellStyle).Text("Design");
  47. table.Cell().Element(CellStyle).Text("3 years");
  48. IContainer HeaderCellStyle(IContainer container) =>
  49. container
  50. .Border(1)
  51. .BorderColor(Colors.Grey.Lighten2)
  52. .Background(Colors.Grey.Lighten3)
  53. .Padding(8)
  54. .AlignMiddle()
  55. .DefaultTextStyle(x => x.Bold());
  56. IContainer CellStyle(IContainer container) =>
  57. container
  58. .Border(1)
  59. .BorderColor(Colors.Grey.Lighten2)
  60. .Padding(8);
  61. });
  62. });
  63. });
  64. }
  65. protected override SemanticTreeNode? GetExpectedSemanticTree()
  66. {
  67. return ExpectedSemanticTree.DocumentRoot(root =>
  68. {
  69. root.Child("Table", table =>
  70. {
  71. table.Child("THead", thead =>
  72. {
  73. thead.Child("TR", row =>
  74. {
  75. row.Child("TH", th => th.Attribute("Table", "Scope", "Column").Child("P"));
  76. row.Child("TH", th => th.Attribute("Table", "Scope", "Column").Child("P"));
  77. row.Child("TH", th => th.Attribute("Table", "Scope", "Column").Child("P"));
  78. row.Child("TH", th => th.Attribute("Table", "Scope", "Column").Child("P"));
  79. });
  80. });
  81. table.Child("TBody", tbody =>
  82. {
  83. tbody.Child("TR", row =>
  84. {
  85. row.Child("TD", td => td.Child("P"));
  86. row.Child("TD", td => td.Child("P"));
  87. row.Child("TD", td => td.Child("P"));
  88. row.Child("TD", td => td.Child("P"));
  89. });
  90. tbody.Child("TR", row =>
  91. {
  92. row.Child("TD", td => td.Child("P"));
  93. row.Child("TD", td => td.Child("P"));
  94. row.Child("TD", td => td.Child("P"));
  95. row.Child("TD", td => td.Child("P"));
  96. });
  97. });
  98. });
  99. });
  100. }
  101. }