TableWithHorizontalHeadersTests.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 TableWithHorizontalHeadersTests : 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. });
  30. // Row 1: Name
  31. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Name");
  32. table.Cell().Element(CellStyle).Text("John Smith");
  33. table.Cell().Element(CellStyle).Text("Jane Doe");
  34. // Row 2: Position
  35. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Position");
  36. table.Cell().Element(CellStyle).Text("Senior Developer");
  37. table.Cell().Element(CellStyle).Text("UX Designer");
  38. // Row 3: Department
  39. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Department");
  40. table.Cell().Element(CellStyle).Text("Engineering");
  41. table.Cell().Element(CellStyle).Text("Design");
  42. // Row 4: Experience
  43. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Experience");
  44. table.Cell().Element(CellStyle).Text("5 years");
  45. table.Cell().Element(CellStyle).Text("3 years");
  46. IContainer HeaderCellStyle(IContainer container) =>
  47. container
  48. .Border(1)
  49. .BorderColor(Colors.Grey.Lighten2)
  50. .Background(Colors.Grey.Lighten3)
  51. .Padding(8)
  52. .AlignMiddle()
  53. .DefaultTextStyle(x => x.Bold());
  54. IContainer CellStyle(IContainer container) =>
  55. container
  56. .Border(1)
  57. .BorderColor(Colors.Grey.Lighten2)
  58. .Padding(8);
  59. });
  60. });
  61. });
  62. }
  63. protected override SemanticTreeNode? GetExpectedSemanticTree()
  64. {
  65. return ExpectedSemanticTree.DocumentRoot(root =>
  66. {
  67. root.Child("Table", table =>
  68. {
  69. table.Child("TBody", tbody =>
  70. {
  71. tbody.Child("TR", row =>
  72. {
  73. row.Child("TH", th => th.Attribute("Table", "Scope", "Row").Child("P"));
  74. row.Child("TD", td => td.Child("P"));
  75. row.Child("TD", td => td.Child("P"));
  76. });
  77. tbody.Child("TR", row =>
  78. {
  79. row.Child("TH", th => th.Attribute("Table", "Scope", "Row").Child("P"));
  80. row.Child("TD", td => td.Child("P"));
  81. row.Child("TD", td => td.Child("P"));
  82. });
  83. tbody.Child("TR", row =>
  84. {
  85. row.Child("TH", th => th.Attribute("Table", "Scope", "Row").Child("P"));
  86. row.Child("TD", td => td.Child("P"));
  87. row.Child("TD", td => td.Child("P"));
  88. });
  89. tbody.Child("TR", row =>
  90. {
  91. row.Child("TH", th => th.Attribute("Table", "Scope", "Row").Child("P"));
  92. row.Child("TD", td => td.Child("P"));
  93. row.Child("TD", td => td.Child("P"));
  94. });
  95. });
  96. });
  97. });
  98. }
  99. }