From ff7282ecb89d1fa99662302c148f7bbe98c99692 Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sun, 7 Apr 2024 09:19:43 -0700 Subject: [PATCH] Adding test and update render to fix issue with rendering separator when headers are hidden fixing issue 1391. --- .../Widgets/Table/TableRenderer.cs | 4 ++-- ...w_Separators_No_Header.Output.verified.txt | 7 ++++++ .../Unit/Widgets/Table/TableTests.cs | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/Spectre.Console.Tests/Expectations/Widgets/Table/Render_Row_Separators_No_Header.Output.verified.txt diff --git a/src/Spectre.Console/Widgets/Table/TableRenderer.cs b/src/Spectre.Console/Widgets/Table/TableRenderer.cs index 23bff61cd..0d1716685 100644 --- a/src/Spectre.Console/Widgets/Table/TableRenderer.cs +++ b/src/Spectre.Console/Widgets/Table/TableRenderer.cs @@ -150,9 +150,9 @@ public static List Render(TableRendererContext context, List colum result.Add(Segment.LineBreak); } - // Show row separator? + // Show row separator, if headers are hidden show separator after the first row if (context.Border.SupportsRowSeparator && context.ShowRowSeparators - && !isFirstRow && !isLastRow) + && (!isFirstRow || (isFirstRow && !context.ShowHeaders)) && !isLastRow) { var hasVisibleFootes = context is { ShowFooters: true, HasFooters: true }; var isNextLastLine = index == context.Rows.Count - 2; diff --git a/test/Spectre.Console.Tests/Expectations/Widgets/Table/Render_Row_Separators_No_Header.Output.verified.txt b/test/Spectre.Console.Tests/Expectations/Widgets/Table/Render_Row_Separators_No_Header.Output.verified.txt new file mode 100644 index 000000000..e296413d0 --- /dev/null +++ b/test/Spectre.Console.Tests/Expectations/Widgets/Table/Render_Row_Separators_No_Header.Output.verified.txt @@ -0,0 +1,7 @@ +┌────────┬────────┐ +│ Qux │ Corgi │ +├────────┼────────┤ +│ Waldo │ Grault │ +├────────┼────────┤ +│ Garply │ Fred │ +└────────┴────────┘ diff --git a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs index 9df303846..18379bdcd 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs @@ -159,6 +159,29 @@ public Task Should_Render_Table_With_Row_Separators_Correctly() return Verifier.Verify(console.Output); } + [Fact] + [Expectation("Render_Row_Separators_No_Header")] + public Task Should_Render_Table_With_Row_Separators_No_Header_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + + table.ShowRowSeparators(); + table.HideHeaders(); + + table.AddColumns("Foo", "Bar"); + table.AddRow("Qux", "Corgi"); + table.AddRow("Waldo", "Grault"); + table.AddRow("Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + [Fact] [Expectation("Render_EA_Character")] public Task Should_Render_Table_With_EA_Character_Correctly()