Skip to content

Commit 68e25f1

Browse files
committed
chore: review notes + tweaks
* nicer shortening of long test names/reasons * show tooltip for long text
1 parent 6221a6b commit 68e25f1

File tree

3 files changed

+88
-40
lines changed

3 files changed

+88
-40
lines changed

e2e-report/app/page.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Table from '@/components/table'
44
import ComponentSwitcher from '@/components/switcher'
55
import StatsRow from '@/components/stats'
66
import testData from '@/utils/data'
7-
import { CopyIcon } from '@/components/icons'
87
import CopyBadgeButton from '@/components/copy-badge'
98
import { badgeSettings } from '@/utils/consts'
109

@@ -13,7 +12,7 @@ export default function Home() {
1312
// and another showing only suites with failed tests (and the failed cases in them)
1413
const tableComponents = {
1514
'All suites': <Table suites={testData.nonEmptySuites} />,
16-
'Failed tests only': <Table suites={testData.suitesWithIssues} />,
15+
'Failed tests only': <Table suites={testData.suitesWithFailures} />,
1716
}
1817

1918
return (

e2e-report/components/table.js

+84-35
Original file line numberDiff line numberDiff line change
@@ -65,51 +65,100 @@ function TestSuiteRow({ suite, idx }) {
6565
{suite.testCases
6666
.filter((t) => t.status != 'passed')
6767
.map((t) => {
68-
return <IssueRow key={suite.name + t.name} test={t} />
68+
return <TestCaseRow key={suite.name + t.name} test={t} />
6969
})}
7070
</>
7171
)
7272
}
7373

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+
)
77154
}
78155

79156
return (
80157
<tr>
81158
<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 />}
113162
</div>
114163
</td>
115164
</tr>

e2e-report/utils/data.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ nonEmptySuites.forEach((suite) => {
1414
suite.failedUnknown = suite.failed - suite.failedKnown
1515
})
1616

17-
const suitesWithIssues = nonEmptySuites.filter((suite) => suite.failed > 0)
18-
suitesWithIssues.forEach((suite) => {
17+
const suitesWithFailures = nonEmptySuites.filter((suite) => suite.failed > 0)
18+
suitesWithFailures.forEach((suite) => {
1919
suite.testCases = suite.testCases.filter((t) => t.status === 'failed')
2020
})
2121

@@ -34,7 +34,7 @@ const testData = {
3434
nextVersion: fileData.nextVersion,
3535
testDate: fileData.testDate,
3636
nonEmptySuites,
37-
suitesWithIssues,
37+
suitesWithFailures,
3838
knownFailuresCount,
3939
unknownFailuresCount,
4040
}

0 commit comments

Comments
 (0)