Skip to content

Commit

Permalink
Adding test and update render to fix issue with rendering separator w…
Browse files Browse the repository at this point in the history
…hen headers are hidden fixing issue 1391.
  • Loading branch information
BlazeFace authored and patriksvensson committed Apr 14, 2024
1 parent eb38f76 commit ff7282e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Spectre.Console/Widgets/Table/TableRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public static List<Segment> Render(TableRendererContext context, List<int> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
┌────────┬────────┐
│ Qux │ Corgi │
├────────┼────────┤
│ Waldo │ Grault │
├────────┼────────┤
│ Garply │ Fred │
└────────┴────────┘
23 changes: 23 additions & 0 deletions test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ff7282e

Please sign in to comment.