-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix ConvertTo-Html single matched column header bug #2184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| Describe "ConvertTo-Html Tests" -Tags "CI" { | ||
|
|
||
| BeforeAll { | ||
| $customObject = [pscustomobject]@{"Name" = "John Doe"; "Age" = 42; "Friends" = ("Jack", "Jill")} | ||
| $newLine = "`r`n" | ||
| } | ||
|
|
||
| function normalizeLineEnds([string]$text) | ||
| { | ||
| $text -replace "`r`n?|`n", "`r`n" | ||
| } | ||
|
|
||
| It "Test ConvertTo-Html with no parameters" { | ||
| $returnObject = $customObject | ConvertTo-Html | ||
| $returnObject -is [System.Array] | Should Be $true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test isn't really needed, right? isn't the test on line 30 enough?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the test is appropriate; however, it would be easier to diagnose if Type.FullName is compared instead of a soft-cast.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this case, you can use 'Should BeOfType`. See the list of Pester assertions here. And I'll be honest - I'm surprised it's an array - I would have expected a single string, so from that point of view, it might be worth a test to at least make it obvious if someone were to implement my expected behavior. |
||
| $returnString = $returnObject -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>HTML TABLE</title> | ||
| </head><body> | ||
| <table> | ||
| <colgroup><col/><col/><col/></colgroup> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i sure wish we could replicate less code - create variables and reuse them? |
||
| <tr><th>Name</th><th>Age</th><th>Friends</th></tr> | ||
| <tr><td>John Doe</td><td>42</td><td>System.Object[]</td></tr> | ||
| </table> | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
|
|
||
| It "Test ConvertTo-Html Fragment parameter" { | ||
| $returnString = ($customObject | ConvertTo-Html -Fragment) -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <table> | ||
| <colgroup><col/><col/><col/></colgroup> | ||
| <tr><th>Name</th><th>Age</th><th>Friends</th></tr> | ||
| <tr><td>John Doe</td><td>42</td><td>System.Object[]</td></tr> | ||
| </table> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
|
|
||
| It "Test ConvertTo-Html as List" { | ||
| $returnString = ($customObject | ConvertTo-Html -As List) -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>HTML TABLE</title> | ||
| </head><body> | ||
| <table> | ||
| <tr><td>Name:</td><td>John Doe</td></tr> | ||
| <tr><td>Age:</td><td>42</td></tr> | ||
| <tr><td>Friends:</td><td>System.Object[]</td></tr> | ||
| </table> | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
|
|
||
| It "Test ConvertTo-Html specified properties" { | ||
| $returnString = ($customObject | ConvertTo-Html -Property Name, Friends -As List) -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>HTML TABLE</title> | ||
| </head><body> | ||
| <table> | ||
| <tr><td>Name:</td><td>John Doe</td></tr> | ||
| <tr><td>Friends:</td><td>System.Object[]</td></tr> | ||
| </table> | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
|
|
||
| It "Test ConvertTo-Html using page parameters" { | ||
| $returnString = ($customObject | ConvertTo-Html -Title "Custom Object" -Body "Body Text" -CssUri "page.css" -As List) -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>Custom Object</title> | ||
| <link rel="stylesheet" type="text/css" href="page.css" /> | ||
| </head><body> | ||
| Body Text | ||
| <table> | ||
| <tr><td>Name:</td><td>John Doe</td></tr> | ||
| <tr><td>Age:</td><td>42</td></tr> | ||
| <tr><td>Friends:</td><td>System.Object[]</td></tr> | ||
| </table> | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
|
|
||
| It "Test ConvertTo-Html pre and post" { | ||
| $returnString = ($customObject | ConvertTo-Html -PreContent "Before the object" -PostContent "After the object") -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>HTML TABLE</title> | ||
| </head><body> | ||
| Before the object | ||
| <table> | ||
| <colgroup><col/><col/><col/></colgroup> | ||
| <tr><th>Name</th><th>Age</th><th>Friends</th></tr> | ||
| <tr><td>John Doe</td><td>42</td><td>System.Object[]</td></tr> | ||
| </table> | ||
| After the object | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
| It "Test ConvertTo-Html header with default single property" { | ||
| $returnString = ($customObject | Select-Object Name | ConvertTo-Html) -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>HTML TABLE</title> | ||
| </head><body> | ||
| <table> | ||
| <colgroup><col/></colgroup> | ||
| <tr><th>Name</th></tr> | ||
| <tr><td>John Doe</td></tr> | ||
| </table> | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
| It "Test ConvertTo-Html header with matched single property" { | ||
| $returnString = ($customObject | ConvertTo-Html -Property Name*) -join $newLine | ||
| $expectedValue = normalizeLineEnds @" | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <title>HTML TABLE</title> | ||
| </head><body> | ||
| <table> | ||
| <colgroup><col/></colgroup> | ||
| <tr><th>Name</th></tr> | ||
| <tr><td>John Doe</td></tr> | ||
| </table> | ||
| </body></html> | ||
| "@ | ||
| $returnString | Should Be $expectedValue | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be better, or could the line endings be removed entirely? Is that part of what you're looking to validate?