Skip to content

Commit

Permalink
improve dictionary and sequence rendering, open top level of treeview
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Feb 4, 2023
1 parent 538bc7c commit 5fe4981
Show file tree
Hide file tree
Showing 11 changed files with 561 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class HtmlFormatterTests
{
public class Objects_TableView : FormatterTestBase
{
// FIX: (Objects_TableView) delete?
[Fact]
public void Formatters_are_generated_on_the_fly_when_HTML_mime_type_is_requested()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Formatters_are_generated_on_the_fly_for_anonymous_types()
.RemoveStyleElement()
.Should()
.BeEquivalentHtmlTo($$"""
<details class="dni-treeview">
<details open="open" class="dni-treeview">
{{Tags.SummaryTextBegin}}{ a = 123 }{{Tags.SummaryTextEnd}}
<div>
<table>
Expand Down Expand Up @@ -112,8 +112,8 @@ public void It_formats_objects_as_tree()
html
.Should()
.BeEquivalentHtmlTo($"""
<details class="dni-treeview">
{Tags.SummaryTextBegin}Microsoft.DotNet.Interactive.Formatting.Tests.EntityId{Tags.SummaryTextEnd}
<details open="open" class="dni-treeview">
{Tags.SummaryTextBegin}{typeof(EntityId).FullName}{Tags.SummaryTextEnd}
<div>
<table>
<thead>
Expand Down Expand Up @@ -166,7 +166,7 @@ public void It_formats_value_tuples_as_tree()
.RemoveStyleElement()
.Should()
.BeEquivalentHtmlTo($"""
<details class="dni-treeview">
<details open="open" class="dni-treeview">
{Tags.SummaryTextBegin}(123, hello){Tags.SummaryTextEnd}
<div>
<table>
Expand Down Expand Up @@ -206,13 +206,9 @@ public void Object_properties_are_formatted_using_nested_trees()

formatter.Format(instance, writer);

writer.ToString()
.RemoveStyleElement()
.Should()
.BeEquivalentHtmlTo(
$$"""
<details class="dni-treeview">
{{Tags.SummaryTextBegin}}{ A = 123, B = { BA = 456 } }{{Tags.SummaryTextEnd}}
var expected = $$"""
<details open="open" class="dni-treeview">
<summary><span class="dni-code-hint"><code>{ A = 123, B = { BA = 456 } }</code></span></summary>
<div>
<table>
<thead>
Expand All @@ -230,8 +226,8 @@ public void Object_properties_are_formatted_using_nested_trees()
<tr>
<td>B</td>
<td>
<details class="dni-treeview">
{{Tags.SummaryTextBegin}}{ BA = 456 }{{Tags.SummaryTextEnd}}
<details open="open" class="dni-treeview">
<summary><span class="dni-code-hint"><code>{ BA = 456 }</code></span></summary>
<div>
<table>
<thead>
Expand All @@ -256,8 +252,14 @@ public void Object_properties_are_formatted_using_nested_trees()
</table>
</div>
</details>
""");
""";

var actual = writer.ToString().RemoveStyleElement();

actual
.Should()
.BeEquivalentHtmlTo(
expected);
}

[Fact]
Expand All @@ -275,12 +277,13 @@ public void Scalar_sequence_properties_are_formatted_using_plain_text_formatter(

formatter.Format(instance, writer);

writer.ToString()
.RemoveStyleElement()
.Should()
.BeEquivalentHtmlTo(
$$"""
<details class="dni-treeview">
var html = writer.ToString().RemoveStyleElement();

html
.Should()
.BeEquivalentHtmlTo(
$$"""
<details open="open" class="dni-treeview">
{{Tags.SummaryTextBegin}}{ PropertyA = 123, PropertyB = System.Linq.Enumerable+RangeIterator }{{Tags.SummaryTextEnd}}
<div>
<table>
Expand Down Expand Up @@ -311,25 +314,6 @@ public void Scalar_sequence_properties_are_formatted_using_plain_text_formatter(
""");
}

[Fact]
public void Collection_properties_are_formatted_using_plain_text_formatting()
{
var writer = new StringWriter();

var instance = new
{
PropertyA = Enumerable.Range(1, 3)
};

var formatter = HtmlFormatter.GetPreferredFormatterFor(instance.GetType());

formatter.Format(instance, writer);

writer.ToString()
.Should()
.Contain("[ 1, 2, 3 ]");
}

[Fact]
public void It_displays_exceptions_thrown_by_properties_in_the_property_value_cell()
{
Expand All @@ -349,7 +333,7 @@ public void It_displays_exceptions_thrown_by_properties_in_the_property_value_ce
<tr>
<td>NotOk</td>
<td>
<details class="dni-treeview">
<details open="open" class="dni-treeview">
<summary><span class="dni-code-hint"><code>System.Exception: not ok
""".Crunch());
}
Expand Down
Loading

0 comments on commit 5fe4981

Please sign in to comment.