@@ -65,51 +65,100 @@ function TestSuiteRow({ suite, idx }) {
65
65
{ suite . testCases
66
66
. filter ( ( t ) => t . status != 'passed' )
67
67
. map ( ( t ) => {
68
- return < IssueRow key = { suite . name + t . name } test = { t } />
68
+ return < TestCaseRow key = { suite . name + t . name } test = { t } />
69
69
} ) }
70
70
</ >
71
71
)
72
72
}
73
73
74
- function IssueRow ( { test } ) {
75
- function shorten ( text ) {
76
- return text ?. length > 100 ? text . slice ( 0 , 45 ) + '[.....]' + text . slice ( - 45 ) : text
74
+ const maxLength = 100
75
+
76
+ // Simple utility not meant to cover all types of texts/lengths/cases
77
+ function shorten ( text ) {
78
+ if ( ! text || text . length <= maxLength ) return text
79
+
80
+ // Slice text in two at the first whitespace after the middle of the text
81
+ const ellipsis = ' [....]'
82
+ const midIdx = ( maxLength - ellipsis . length ) / 2
83
+ const sliceInx = text . indexOf ( ' ' , midIdx )
84
+ const beforeSlice = text . slice ( 0 , sliceInx ) + ellipsis
85
+ let afterSlice = text . slice ( sliceInx )
86
+
87
+ // As long the full text is too long, trim more full words
88
+ while ( beforeSlice . length + afterSlice . length > maxLength ) {
89
+ afterSlice = afterSlice . replace ( / [ ^ \s ] + \s + / , '' )
90
+ }
91
+ return beforeSlice + afterSlice
92
+ }
93
+
94
+ function TestCaseRow ( { test } ) {
95
+ const fullName = test . name + ( test . retries > 0 ? ` (${ test . retries } retries)` : '' )
96
+ const displayName = shorten ( fullName )
97
+ const nameHasTooltip = displayName != fullName
98
+
99
+ const displayReason = shorten ( test . reason )
100
+ const reasonHasTooltip = displayReason != test . reason
101
+
102
+ function StatusBadge ( ) {
103
+ let badgeClasses = 'badge rounded '
104
+ let label = ''
105
+
106
+ if ( test . status == 'failed' ) {
107
+ label = 'Failed'
108
+ badgeClasses += test . reason ? 'badge-warning' : 'badge-error text-white'
109
+ } else {
110
+ label = 'Skipped'
111
+ badgeClasses += 'badge-accent'
112
+ }
113
+
114
+ return < div className = { badgeClasses } > { label } </ div >
115
+ }
116
+
117
+ function NameLine ( ) {
118
+ return (
119
+ < div className = "flex gap-2 items-center py-1" >
120
+ < StatusBadge />
121
+ < div
122
+ className = { 'opacity-90 text-sm md:text-base' + ( nameHasTooltip ? ' tooltip' : '' ) }
123
+ data-tip = { nameHasTooltip ? fullName : undefined }
124
+ >
125
+ < span className = "font-bold" > Test:</ span > { displayName }
126
+ </ div >
127
+ </ div >
128
+ )
129
+ }
130
+
131
+ function ReasonLine ( ) {
132
+ return (
133
+ < div
134
+ className = {
135
+ 'flex justify-start text-neutral font-bold opacity-90' +
136
+ ( reasonHasTooltip ? ' tooltip' : '' )
137
+ }
138
+ data-tip = { reasonHasTooltip ? test . reason : undefined }
139
+ >
140
+ { test . link ? (
141
+ < Link
142
+ href = { test . link }
143
+ target = "_blank"
144
+ className = "flex gap-1 items-center text-sm md:text-base"
145
+ >
146
+ < GithubIcon className = "w-4" />
147
+ < span > { displayReason } </ span >
148
+ </ Link >
149
+ ) : (
150
+ < span > { displayReason } </ span >
151
+ ) }
152
+ </ div >
153
+ )
77
154
}
78
155
79
156
return (
80
157
< tr >
81
158
< td colSpan = { 5 } className = "border bg-base-200/[.4] md:pl-6" >
82
- < div key = { test . name } className = "flex flex-col gap-1 text-neutral text-left" >
83
- < div className = "flex gap-2 items-center py-1" >
84
- { test . status == 'failed' ? (
85
- ! ! test . reason ? (
86
- < div className = "badge badge-warning rounded" > Failed</ div >
87
- ) : (
88
- < div className = "badge badge-error rounded text-white" > Failed</ div >
89
- )
90
- ) : (
91
- < div className = "badge badge-accent rounded" > Skipped</ div >
92
- ) }
93
- < span className = "opacity-90 text-sm md:text-base" >
94
- < span className = "font-bold" > Test:</ span > { shorten ( test . name ) }
95
- </ span >
96
- </ div >
97
- { ! ! test . reason && (
98
- < div className = "flex justify-start text-neutral font-bold opacity-90" >
99
- { test . link ? (
100
- < Link
101
- href = { test . link }
102
- target = "_blank"
103
- className = "flex gap-1 items-center text-sm md:text-base"
104
- >
105
- < GithubIcon className = "w-4" />
106
- < span > { shorten ( test . reason ) } </ span >
107
- </ Link >
108
- ) : (
109
- < span > { shorten ( test . reason ) } </ span >
110
- ) }
111
- </ div >
112
- ) }
159
+ < div className = "flex flex-col gap-1 text-neutral text-left" >
160
+ < NameLine />
161
+ { ! ! test . reason && < ReasonLine /> }
113
162
</ div >
114
163
</ td >
115
164
</ tr >
0 commit comments