1
+ Describe ' Render-StatisticsRow' {
2
+ BeforeAll {
3
+ . (Resolve-Path " $PSScriptRoot \..\..\..\src\templates\elements\statistics.ps1" ).Path
4
+ . (Resolve-Path " $PSScriptRoot \..\..\..\src\utilities\string.ps1" ).Path
5
+ . (Resolve-Path " $PSScriptRoot \..\..\..\src\assets.ps1" ).Path
6
+ }
7
+
8
+ It ' Should render statistics row with data. Directory depth 3' {
9
+ $template = @'
10
+ <!--page.location-->
11
+ <!--item.name-->
12
+ <!--classes.count-->
13
+ <!--sourcefiles.count-->
14
+ <!--counter.instructions-->
15
+ <!--counter.branches-->
16
+ <!--counter.lines-->
17
+ <!--counter.methods-->
18
+ <!--counter.classes-->
19
+ <!--counter.complexity-->
20
+ something
21
+ '@
22
+ $template = $template.Replace (" `r`n " , " `n " )
23
+ $expected = @'
24
+ packages/directory\sample.html
25
+ directory\sample
26
+ 2
27
+ 4
28
+ 1 - 66 - 67 - 98.51%
29
+
30
+ 1 - 53 - 54 - 98.15%
31
+ 0 - 5 - 5 - 100.00%
32
+ 0 - 3 - 3 - 100.00%
33
+
34
+ something
35
+ '@
36
+ $expected = $expected.Replace (" `r`n " , " `n " )
37
+ $object = [PSCustomObject ]@ {
38
+ " @name" = " directory\sample" ;
39
+ " class" = [PSCustomObject []]@ (
40
+ [PSCustomObject ]@ {
41
+ " something" = " lorem ipsum" ;
42
+ },
43
+ [PSCustomObject ]@ {
44
+ " something_else" = " lorem ipsum dolor" ;
45
+ }
46
+ );
47
+ " sourcefile" = [PSCustomObject []]@ (
48
+ [PSCustomObject ]@ {
49
+ " something" = " lorem ipsum" ;
50
+ },
51
+ [PSCustomObject ]@ {
52
+ " something_else" = " lorem ipsum dolor" ;
53
+ },
54
+ [PSCustomObject ]@ {
55
+ " something" = " lorem ipsum" ;
56
+ },
57
+ [PSCustomObject ]@ {
58
+ " something_else" = " lorem ipsum dolor" ;
59
+ }
60
+ );
61
+ " counter" = [PSCustomObject []]@ (
62
+ [PSCustomObject ]@ {
63
+ " @type" = " INSTRUCTION" ;
64
+ " @missed" = " 1" ;
65
+ " @covered" = " 66" ;
66
+ },
67
+ [PSCustomObject ]@ {
68
+ " @type" = " LINE" ;
69
+ " @missed" = " 1" ;
70
+ " @covered" = " 53" ;
71
+ },
72
+ [PSCustomObject ]@ {
73
+ " @type" = " METHOD" ;
74
+ " @missed" = " 0" ;
75
+ " @covered" = " 5" ;
76
+ },
77
+ [PSCustomObject ]@ {
78
+ " @type" = " CLASS" ;
79
+ " @missed" = " 0" ;
80
+ " @covered" = " 3" ;
81
+ }
82
+ );
83
+ }
84
+ $directoryDepth = 3
85
+
86
+ $result = Render- StatisticsRow - template $template - object $object - directoryDepth $directoryDepth
87
+ $result | Should - Be $expected
88
+ }
89
+ }
90
+
91
+ Describe ' Render-StatisticsCard' {
92
+ BeforeAll {
93
+ . (Resolve-Path " $PSScriptRoot \..\..\..\src\templates\elements\statistics.ps1" ).Path
94
+ . (Resolve-Path " $PSScriptRoot \..\..\..\src\utilities\string.ps1" ).Path
95
+ . (Resolve-Path " $PSScriptRoot \..\..\..\src\assets.ps1" ).Path
96
+ }
97
+
98
+ It ' Should render card with two rows' {
99
+ $cardTemplate = @'
100
+ <!--page.theme-->
101
+ <!--statistics rows-->
102
+ <!--statistics card title-->
103
+ '@
104
+ $Global :jacocoxml2htmlConfig = [PSCustomObject ]@ {' theme' = ' dark' ;}
105
+ $cardTemplate = $cardTemplate.Replace (" `r`n " , " `n " )
106
+ $rowTemplate = @'
107
+ sample row template
108
+ '@
109
+ $rowTemplate = $rowTemplate.Replace (" `r`n " , " `n " )
110
+ $objects = [PSCustomObject []]@ (
111
+ [PSCustomObject ]@ {
112
+ " @name" = " directory\sample.ps1" ;
113
+ " class" = [PSCustomObject []]@ (
114
+ [PSCustomObject ]@ {
115
+ " something" = " lorem ipsum" ;
116
+ },
117
+ [PSCustomObject ]@ {
118
+ " something_else" = " lorem ipsum dolor" ;
119
+ }
120
+ );
121
+ " sourcefile" = [PSCustomObject []]@ (
122
+ [PSCustomObject ]@ {
123
+ " something" = " lorem ipsum" ;
124
+ },
125
+ [PSCustomObject ]@ {
126
+ " something_else" = " lorem ipsum dolor" ;
127
+ },
128
+ [PSCustomObject ]@ {
129
+ " something" = " lorem ipsum" ;
130
+ },
131
+ [PSCustomObject ]@ {
132
+ " something_else" = " lorem ipsum dolor" ;
133
+ }
134
+ );
135
+ " counter" = [PSCustomObject []]@ (
136
+ [PSCustomObject ]@ {
137
+ " @type" = " INSTRUCTION" ;
138
+ " @missed" = " 1" ;
139
+ " @covered" = " 66" ;
140
+ },
141
+ [PSCustomObject ]@ {
142
+ " @type" = " LINE" ;
143
+ " @missed" = " 1" ;
144
+ " @covered" = " 53" ;
145
+ },
146
+ [PSCustomObject ]@ {
147
+ " @type" = " METHOD" ;
148
+ " @missed" = " 0" ;
149
+ " @covered" = " 5" ;
150
+ },
151
+ [PSCustomObject ]@ {
152
+ " @type" = " CLASS" ;
153
+ " @missed" = " 0" ;
154
+ " @covered" = " 3" ;
155
+ }
156
+ );
157
+ },
158
+ [PSCustomObject ]@ {
159
+ " @name" = " directory\another_sample.ps1" ;
160
+ " class" = [PSCustomObject []]@ (
161
+ [PSCustomObject ]@ {
162
+ " something" = " lorem ipsum" ;
163
+ },
164
+ [PSCustomObject ]@ {
165
+ " something_else" = " lorem ipsum dolor" ;
166
+ }
167
+ );
168
+ " sourcefile" = [PSCustomObject []]@ (
169
+ [PSCustomObject ]@ {
170
+ " something" = " lorem ipsum" ;
171
+ },
172
+ [PSCustomObject ]@ {
173
+ " something_else" = " lorem ipsum dolor" ;
174
+ },
175
+ [PSCustomObject ]@ {
176
+ " something" = " lorem ipsum" ;
177
+ },
178
+ [PSCustomObject ]@ {
179
+ " something_else" = " lorem ipsum dolor" ;
180
+ }
181
+ );
182
+ " counter" = [PSCustomObject []]@ (
183
+ [PSCustomObject ]@ {
184
+ " @type" = " INSTRUCTION" ;
185
+ " @missed" = " 15" ;
186
+ " @covered" = " 66" ;
187
+ },
188
+ [PSCustomObject ]@ {
189
+ " @type" = " LINE" ;
190
+ " @missed" = " 12" ;
191
+ " @covered" = " 53" ;
192
+ },
193
+ [PSCustomObject ]@ {
194
+ " @type" = " METHOD" ;
195
+ " @missed" = " 3" ;
196
+ " @covered" = " 5" ;
197
+ },
198
+ [PSCustomObject ]@ {
199
+ " @type" = " CLASS" ;
200
+ " @missed" = " 0" ;
201
+ " @covered" = " 3" ;
202
+ }
203
+ );
204
+ }
205
+ )
206
+ $cardTitle = ' lorem ipsum'
207
+ $directoryDepth = 2
208
+ $expected = @'
209
+ dark
210
+ sample row template
211
+ sample row template
212
+ lorem ipsum
213
+ '@
214
+ $expected = $expected.Replace (" `r`n " , " `n " )
215
+
216
+ $result = Render- StatisticsCard `
217
+ - cardTemplate $cardTemplate `
218
+ - rowTemplate $rowTemplate `
219
+ - objects $objects `
220
+ - cardTitle $cardTitle `
221
+ - directoryDepth $directoryDepth
222
+ $result | Should - Be $expected
223
+ }
224
+ }
0 commit comments