-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change default HTML formatting to a tree layout rather than a table (#…
…2671) * split HTML formatter tests into smaller files * split PlainTextFormatterTests into smaller files * refactoring * implement tree views for objects * remove HtmlFormatter.MaxProperties * improve dictionary and sequence rendering, open top level of treeview * remove old object table formatters, clean up
- Loading branch information
1 parent
9b75e3c
commit 276ca26
Showing
25 changed files
with
2,052 additions
and
1,872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/Microsoft.DotNet.Interactive.Formatting.Tests/HtmlFormatterTests.Json.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Text.Json; | ||
using FluentAssertions; | ||
using Microsoft.DotNet.Interactive.Formatting.Tests.Utility; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using static Microsoft.DotNet.Interactive.Formatting.Tests.Tags; | ||
|
||
namespace Microsoft.DotNet.Interactive.Formatting.Tests; | ||
|
||
public partial class HtmlFormatterTests : FormatterTestBase | ||
{ | ||
public class Json : FormatterTestBase | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public Json(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public void JsonDocument_and_JsonDocument_RootElement_output_the_same_HTML() | ||
{ | ||
var jsonString = JsonSerializer.Serialize(new { Name = "cherry", Deliciousness = 9000 }); | ||
|
||
var jsonDocument = JsonDocument.Parse(jsonString); | ||
var jsonElement = JsonDocument.Parse(jsonString).RootElement; | ||
|
||
var jsonDocumentHtml = jsonDocument.ToDisplayString(HtmlFormatter.MimeType); | ||
var jsonElementHtml = jsonElement.ToDisplayString(HtmlFormatter.MimeType); | ||
|
||
jsonDocumentHtml.Should().Be(jsonElementHtml); | ||
} | ||
|
||
[Fact] | ||
public void JSON_object_output_contains_a_text_summary() | ||
{ | ||
var jsonString = JsonSerializer.Serialize(new { Name = "cherry", Deliciousness = 9000 }); | ||
|
||
var jsonDocument = JsonDocument.Parse(jsonString); | ||
|
||
var html = jsonDocument.ToDisplayString(HtmlFormatter.MimeType); | ||
|
||
html.Should().ContainAll( | ||
"<code>", | ||
jsonString.HtmlEncode().ToString(), | ||
"</code>"); | ||
} | ||
|
||
[Fact] | ||
public void JSON_object_output_contains_table_of_properties_within_details_tag() | ||
{ | ||
var jsonString = JsonSerializer.Serialize(new { Name = "cherry", Deliciousness = 9000 }); | ||
|
||
var jsonDocument = JsonDocument.Parse(jsonString); | ||
|
||
var html = jsonDocument.ToDisplayString(HtmlFormatter.MimeType); | ||
|
||
html.Should().ContainAll( | ||
"<details", | ||
"<td>Name</td>", | ||
"<td><span>"cherry"</span></td>", | ||
"</details>"); | ||
} | ||
|
||
[Fact] | ||
public void JSON_array_output_contains_a_text_summary() | ||
{ | ||
var jsonString = JsonSerializer.Serialize(new object[] { "apple", "banana", "cherry" }); | ||
|
||
var jsonDocument = JsonDocument.Parse(jsonString); | ||
|
||
var html = jsonDocument.ToDisplayString(HtmlFormatter.MimeType); | ||
|
||
html.Should().ContainAll( | ||
"<code>", | ||
jsonString.HtmlEncode().ToString(), | ||
"</code>"); | ||
} | ||
|
||
[Fact] | ||
public void JSON_array_output_contains_table_of_items_within_details_tag() | ||
{ | ||
var jsonString = JsonSerializer.Serialize(new object[] { "apple", "banana", "cherry" }); | ||
|
||
var jsonDocument = JsonDocument.Parse(jsonString); | ||
|
||
var html = jsonDocument.ToDisplayString(HtmlFormatter.MimeType).RemoveStyleElement(); | ||
|
||
html.Should().Contain( | ||
"<tr><td><span>"apple"</span></td></tr><tr><td><span>"banana"</span></td></tr><tr><td><span>"cherry"</span></td></tr>"); | ||
} | ||
|
||
[Fact] | ||
public void Strings_with_escaped_sequences_are_encoded() | ||
{ | ||
var value = "hola! \n \t \" \" ' ' the joy of escapes! ==> & white space "; | ||
|
||
var text = value.ToDisplayString("text/html").RemoveStyleElement(); | ||
|
||
text.Should().Be($"{PlainTextBegin}hola! \n \t " " ' ' the joy of escapes! ==> & white space {PlainTextEnd}"); | ||
} | ||
|
||
[Fact] | ||
public void Strings_with_unicode_sequences_are_encoded() | ||
{ | ||
var value = "hola! ʰ˽˵ΘϱϪԘÓŴ𝓌🦁♿🌪🍒☝🏿"; | ||
|
||
var text = value.ToDisplayString("text/html").RemoveStyleElement(); | ||
|
||
text.Should().Be($"{PlainTextBegin}{value.HtmlEncode()}{PlainTextEnd}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.