-
Notifications
You must be signed in to change notification settings - Fork 0
/
!Visual Tests.ps1
288 lines (235 loc) · 9.37 KB
/
!Visual Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
Import-Module $PSScriptRoot -Force
#$Global:2e128b9186234521b3ab5ce70cc83360_ForceLoadPowerShellCmdlets = $true
$someVariable = "abcdefg"
Get-HtmlFragment {
h1 "Semi-Fancy Get-HtmlText Usage"
p "Paragraph"
p "Paragraph"
h2 "Header 2"
p "Paragraph"
p "Paragraph"
h3 "Header 3"
p "Paragraph"
p "Paragraph"
h4 "Header 4"
p "Paragraph"
p "Paragraph"
$header3 = "Header Three"
h3 $header3
p "Here's a sample paragraph" (br) "And a line break"
p "Here's a sample paragraph with some" (strong strong) "text"
p "Some" (em (strong "strong and emphasized")) "text"
p "And making use of `$someVariable: $someVariable"
p "Making use of some $(span -style 'color:red;' "red") text"
pre -HtmlEncode "Pre-formatted text<>`r`nLine2`r`nLine3"
p {
"A sample link:"
a -href 'test.html' 'Test'
}
ol {
li "Item 1"
li "Item 2"
}
ul {
li "Item A"
ol {
li "Item A1"
li "Item A2"
}
li "Item B"
}
hr
h2 "Summary and Details"
details @(
summary (strong "Summary")
p "Details"
)
hr
h2 Indicators
ul {
li (Get-HtmlIndicatorText "Sample 1" -ColorName Green)
li (Get-HtmlIndicatorText "Sample 2" -ColorName Red -BorderOnly)
li (Get-HtmlIndicatorText "Sample 3" -ColorIndex 0 -Width 200px)
li (Get-HtmlIndicatorText "Hover Over Me" -ColorRGB 0,0,0 -Title 'Title Usage')
}
hr
h2 Table
h3 Normal
Get-Service | Select-Object Name, Status, DisplayName -First 10 | ConvertTo-HtmlTable
h3 Narrow
Get-Service | Select-Object Name, Status, DisplayName -First 10 -Skip 10 | ConvertTo-HtmlTable -Narrow
h3 Custom Class
"<style>table.HtmlReportingTable.Wide td { padding: 30px 10px 30px 10px; }</style>"
Get-Service | Select-Object Name, Status, DisplayName -First 10 -Skip 20 | ConvertTo-HtmlTable -Narrow -Class Wide
h3 Rowspan from Number
"
Rowspan,Value
1,A
2,B
2,C
1,D
".Trim() -replace '\A ' | ConvertFrom-Csv | ConvertTo-HtmlTable -CellRowspanScripts @{Value='Rowspan'}
h2 No Content
@() | ConvertTo-HtmlTable -NoContentHtml (p (em "No Content"))
hr
h2 "Convert PS Code to HTML"
div {
p {
Convert-PSCodeToHtml -PsCode "Get-ChildItem C:\ | Out-GridView -Title `$var1"
}
}
h2 ConvertTo-HtmlStrongText
$modes = 'SameLine', 'MultiLine', 'MultiLineIndent', 'MultiLineHorizontal', 'MultiLineIndentHorizontal'
$i = 0
foreach ($mode in $modes)
{
h3 $mode
Get-Service |
Select-Object -First 1 -Skip $i -Property Name, DisplayName, Status |
ConvertTo-HtmlStrongText -Mode $mode
$i += 1
}
hr
h2 ConvertTo-HtmlColorBlocks
Get-Service | Select-Object -First 5 Name, DisplayName, Status, StartType |
ConvertTo-HtmlColorBlocks -TocProperty Name -OutputScript { $_ | ConvertTo-HtmlStrongText }
Get-Service | Select-Object -First 5 Name, DisplayName, Status, StartType |
ConvertTo-HtmlColorBlocks -TocProperty Name -OutputScript { p $_.Name } -NarrowToc
hr
h2 Assorted HTML Table Tests
Get-ChildItem C:\Windows |
Select-Object Name, LastWriteTime |
ConvertTo-HtmlTable -NoWrapProperty * -RightAlignProperty Name -Narrow -RowClassScript {
if ($_.Name -match 'boot') { 'red' }
} -RowStyleScript {
if ($_.Name -match 'Branding') { 'font-family: monospace' }
} -CellClassScripts @{
PSParentPath = {
if ($_.Name -eq 'Assembly') { 'blue' }
}
} -CellStyleScripts @{
PSParentPath = { if ($_.Name -eq 'CSC') { 'font-family: monospace' } }
} -CellColspanScripts @{
PSPath = { if ($_.Name -eq 'addins') { 3 } }
} -CellRowspanScripts @{
PSParentPath = { if ($_.Name -eq 'debug') { 3 } }
}
h2 "HTML Table Insert Lines"
[pscustomobject]@{A=1;B=2;C=3;D=4} |
ConvertTo-HtmlTable -InsertSolidLine B -InsertDashedLine C -InsertDottedLine D
h2 "Hourly Heatmap (One Set)"
0..(14*24-1) |
ForEach-Object {
[pscustomobject]@{Timestamp=[DateTime]::Today.AddHours($_); Value = Get-Random -Minimum 0 -Maximum 100}
} |
ConvertTo-HtmlHourlyHeatmap -TimestampProperty Timestamp -ValueProperty Value -Columns 4 -IndicatorSize 20 -IndicatorPadding 2 -HeatmapColors @(
Define-HtmlHeatmapColor -ColorName Green -Mode AtLeast -Value 50
Define-HtmlHeatmapColor -ColorName Orange -Mode AtLeast -Value 25
Define-HtmlHeatmapColor -ColorName Red
)
h2 "Hourly Heatmap (Multiple Sets)"
'A', 'B', 'C' |
ForEach-Object {
$set = $_
0..(14*24-1) |
ForEach-Object {
[pscustomobject]@{Set = "Set $set"; Timestamp=[DateTime]::Today.AddHours($_); Value = Get-Random -Minimum 0 -Maximum 100}
}
} |
ConvertTo-HtmlHourlyHeatmap -SetProperty Set -TimestampProperty Timestamp -ValueProperty Value -Columns 4 -IndicatorSize 20 -IndicatorPadding 2 -HeatmapColors @(
Define-HtmlHeatmapColor -ColorName Green -Mode AtLeast -Value 50
Define-HtmlHeatmapColor -ColorName Orange -Mode AtLeast -Value 25
Define-HtmlHeatmapColor -ColorName Red
)
h2 "Monthly Heatmap (One Set)"
0..(31*4) |
ForEach-Object {
[pscustomobject]@{Set = "Set $set"; Timestamp=[DateTime]::Today.AddDays($_); Value = Get-Random -Minimum 0 -Maximum 100}
} |
ConvertTo-HtmlMonthlyHeatmap -TimestampProperty Timestamp -ValueProperty Value -IndicatorSize 20 -IndicatorPadding 2 -HeatmapColors @(
Define-HtmlHeatmapColor -ColorName Green -Mode AtLeast -Value 50
Define-HtmlHeatmapColor -ColorName Orange -Mode AtLeast -Value 25
Define-HtmlHeatmapColor -ColorName Red
)
h2 "Monthly Heatmap (Multiple Sets)"
'A', 'B', 'C' |
ForEach-Object {
$set = $_
0..(31*4) |
ForEach-Object {
[pscustomobject]@{Set = "Set $set"; Timestamp=[DateTime]::Today.AddDays($_); Value = Get-Random -Minimum 0 -Maximum 100}
}
} |
ConvertTo-HtmlMonthlyHeatmap -SetProperty Set -TimestampProperty Timestamp -ValueProperty Value -IndicatorSize 20 -IndicatorPadding 2 -HeatmapColors @(
Define-HtmlHeatmapColor -ColorName Green -Mode AtLeast -Value 50
Define-HtmlHeatmapColor -ColorName Orange -Mode AtLeast -Value 25
Define-HtmlHeatmapColor -ColorName Red
)
h2 "Monthly Schedule"
$i = 0
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' -split '' |
ForEach-Object {
$days = Get-Random -Minimum 1 -Maximum 10
if ($i -eq 0)
{
[pscustomobject]@{Label="Gray Fill No Link"; Date=[DateTime]::Today; Days=2; LabelFill="rgb(100,100,100)"}
}
[pscustomobject]@{Label="Set $_ ($days Days)"; Date=[DateTime]::Today.AddDays($i); Days=$days; Href="/$_/"}
$i += 2
} |
ConvertTo-HtmlMonthlySchedule -DefaultCellFill "rgb(200,200,200);" -DayOfWeekCellFill @{'Sunday'='rgb(150,150,150);'}
h3 "Overflow tests"
@(
[pscustomobject]@{Date=[DateTime]"2022-06-26"; Days=2; Label="Entirely Before"}
[pscustomobject]@{Date=[DateTime]"2022-06-26"; Days=14; Label="Continuing Before"}
[pscustomobject]@{Date=[DateTime]"2022-07-28"; Days=14; Label="Continuing After"}
[pscustomobject]@{Date=[DateTime]"2022-08-01"; Days=13; Label="Entirely After"}
[pscustomobject]@{Date=[DateTime]"2022-07-14"; Days=5; Label="Entirely Within"}
[pscustomobject]@{Date=[DateTime]"2022-06-27"; Days=45; Label="Before and After"}
) |
ConvertTo-HtmlMonthlySchedule -StartDate "2022-07-01" -EndDate "2022-07-31"
h2 "Form Test"
form @(
div @(
label -for check1 "Unchecked Checkbox"
input -type checkbox -id check1
)
div @(
label -for check2 "Checked Checkbox"
input -type checkbox -id check2 -checked $true
)
div @(
label -for select1 "Single Select"
Get-HtmlSelect -Id select1 -Values A, B, C -SelectedValues B
)
div @(
label -for select2 "Multi Select"
Get-HtmlSelect -Id select2 -Values Option1, Option2, Option3 -SelectedValues Option1, Option3 -Multiple -Size 0
)
div @(
label -for text1 "Basic Text"
input -type text -id text1
)
div @(
label -for text2 "Preset Text"
input -type text -id text2 -value "Preset Value"
)
div @(
Get-HtmlDataList -Id list1 -Values Value1, Value2, Value3, Option4, Option5
label -for text3 "Datalist Text"
input -type text -id text3 -list list1
)
div @(
label -for textarea1 "Text Area"
textarea "Preset Text" -id textarea1 -rows 5
)
)
} |
Out-HtmlFile -AddTimestamp
return
& {
"<h1>Header 1</h1>"
"<p>Alternatively just write HTML like this...</p>"
Get-ChildItem C:\ | Select-Object Name, LastWriteTime, Length -First 10 | ConvertTo-HtmlTable
} |
Out-HtmlFile ~\Desktop\Test.html -Open