Skip to content

Commit 9b85188

Browse files
committed
chore: use detail/summary for html reporter attachments
1 parent 8e46278 commit 9b85188

File tree

2 files changed

+58
-28
lines changed

2 files changed

+58
-28
lines changed

packages/html-reporter/src/links.tsx

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import type { TestAttachment, TestCase, TestCaseSummary, TestResult, TestResultSummary } from './types';
1818
import * as React from 'react';
1919
import * as icons from './icons';
20-
import { TreeItem } from './treeItem';
2120
import { CopyToClipboard } from './copyToClipboard';
2221
import './links.css';
2322
import { linkifyText } from '@web/renderUtils';
@@ -78,30 +77,61 @@ export const AttachmentLink: React.FunctionComponent<{
7877
openInNewTab?: boolean,
7978
}> = ({ attachment, result, href, linkName, openInNewTab }) => {
8079
const [flash, triggerFlash] = useFlash();
80+
const [expanded, setExpanded] = React.useState(false);
8181
useAnchor('attachment-' + result.attachments.indexOf(attachment), triggerFlash);
82-
return <TreeItem title={<span>
83-
{attachment.contentType === kMissingContentType ? icons.warning() : icons.attachment()}
84-
{attachment.path && (
85-
openInNewTab
86-
? <a href={href || attachment.path} target='_blank' rel='noreferrer'>{linkName || attachment.name}</a>
87-
: <a href={href || attachment.path} download={downloadFileNameForAttachment(attachment)}>{linkName || attachment.name}</a>
88-
)}
89-
{!attachment.path && (
90-
openInNewTab
91-
? (
92-
<a
93-
href={URL.createObjectURL(new Blob([attachment.body!], { type: attachment.contentType }))}
94-
target='_blank' rel='noreferrer'
95-
onClick={e => e.stopPropagation() /* dont expand the tree item */}
96-
>
97-
{attachment.name}
98-
</a>
99-
)
100-
: <span>{linkifyText(attachment.name)}</span>
101-
)}
102-
</span>} loadChildren={attachment.body ? () => {
103-
return [<div key={1} className='attachment-body'><CopyToClipboard value={attachment.body!}/>{linkifyText(attachment.body!)}</div>];
104-
} : undefined} depth={0} style={{ lineHeight: '32px' }} flash={flash}></TreeItem>;
82+
83+
const summaryContent = (
84+
<span>
85+
{attachment.contentType === kMissingContentType ? icons.warning() : icons.attachment()}
86+
{attachment.path && (
87+
openInNewTab
88+
? <a href={href || attachment.path} target='_blank' rel='noreferrer'>{linkName || attachment.name}</a>
89+
: <a href={href || attachment.path} download={downloadFileNameForAttachment(attachment)}>{linkName || attachment.name}</a>
90+
)}
91+
{!attachment.path && (
92+
openInNewTab
93+
? (
94+
<a
95+
href={URL.createObjectURL(new Blob([attachment.body!], { type: attachment.contentType }))}
96+
target='_blank' rel='noreferrer'
97+
onClick={e => e.stopPropagation() /* dont expand the details */}
98+
>
99+
{attachment.name}
100+
</a>
101+
)
102+
: <span>{linkifyText(attachment.name)}</span>
103+
)}
104+
</span>
105+
);
106+
107+
if (!attachment.body) {
108+
return (
109+
<div
110+
style={{ lineHeight: '32px', whiteSpace: 'nowrap', paddingLeft: 4 }}
111+
className={clsx(flash && 'flash')}
112+
>
113+
<span style={{ visibility: 'hidden' }}>{icons.rightArrow()}</span>
114+
{summaryContent}
115+
</div>
116+
);
117+
}
118+
119+
return (
120+
<details
121+
style={{ lineHeight: '32px' }}
122+
className={clsx(flash && 'flash')}
123+
onToggle={e => setExpanded(e.currentTarget.open)}
124+
>
125+
<summary style={{ cursor: 'pointer', listStyle: 'none', whiteSpace: 'nowrap', paddingLeft: 4 }}>
126+
{expanded ? icons.downArrow() : icons.rightArrow()}
127+
{summaryContent}
128+
</summary>
129+
<div className='attachment-body'>
130+
<CopyToClipboard value={attachment.body!}/>
131+
{linkifyText(attachment.body!)}
132+
</div>
133+
</details>
134+
);
105135
};
106136

107137
export const TraceLink: React.FC<{ test: TestCaseSummary, trailingSeparator?: boolean, dim?: boolean }> = ({ test, trailingSeparator, dim }) => {

tests/playwright-test/reporter-html.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ for (const useIntermediateMergeReport of [true, false] as const) {
513513

514514
await showReport();
515515
await page.getByRole('link', { name: 'fails' }).click();
516-
await page.locator('text=stdout').click();
517-
await expect(page.locator('.attachment-body')).toHaveText('First line\nSecond line');
518-
await page.locator('text=stderr').click();
516+
await page.getByText('stdout').click();
517+
await expect(page.locator('.attachment-body').nth(0)).toHaveText('First line\nSecond line');
518+
await page.getByText('stderr').click();
519519
await expect(page.locator('.attachment-body').nth(1)).toHaveText('Third line');
520520
});
521521

@@ -2960,7 +2960,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
29602960

29612961
await showReport();
29622962
await page.getByText('my test').click();
2963-
await expect(page.locator('.tree-item', { hasText: 'stdout' })).toHaveCount(1);
2963+
await expect(page.getByTestId('attachments').getByText('stdout')).toHaveCount(1);
29642964
});
29652965

29662966
test('should include diff in AI prompt', async ({ runInlineTest, writeFiles, showReport, page }) => {

0 commit comments

Comments
 (0)