Skip to content

Commit a33659f

Browse files
authored
chore: move attachments link to step body (microsoft#34196)
1 parent 19c935c commit a33659f

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

packages/html-reporter/src/links.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
color: var(--color-scale-orange-6);
6161
border: 1px solid var(--color-scale-orange-4);
6262
}
63+
.label-color-gray {
64+
background-color: var(--color-scale-gray-0);
65+
color: var(--color-scale-gray-6);
66+
border: 1px solid var(--color-scale-gray-4);
67+
}
6368
}
6469

6570
@media(prefers-color-scheme: dark) {
@@ -93,6 +98,11 @@
9398
color: var(--color-scale-orange-2);
9499
border: 1px solid var(--color-scale-orange-4);
95100
}
101+
.label-color-gray {
102+
background-color: var(--color-scale-gray-9);
103+
color: var(--color-scale-gray-2);
104+
border: 1px solid var(--color-scale-gray-4);
105+
}
96106
}
97107

98108
.attachment-body {

packages/html-reporter/src/testResultView.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const TestResultView: React.FC<{
134134
</div>)}
135135
</AutoChip></Anchor>}
136136

137-
{!!otherAttachments.size && <AutoChip header='Attachments' revealOnAnchorId={otherAttachmentAnchors}>
137+
{!!otherAttachments.size && <AutoChip header='Attachments' revealOnAnchorId={otherAttachmentAnchors} dataTestId='attachments'>
138138
{[...otherAttachments].map((a, i) =>
139139
<Anchor key={`attachment-link-${i}`} id={`attachment-${result.attachments.indexOf(a)}`}>
140140
<AttachmentLink attachment={a} result={result} openInNewTab={a.contentType.startsWith('text/html')} />
@@ -176,15 +176,27 @@ const StepTreeItem: React.FC<{
176176
}> = ({ test, step, result, depth }) => {
177177
return <TreeItem title={<span aria-label={step.title}>
178178
<span style={{ float: 'right' }}>{msToString(step.duration)}</span>
179-
{step.attachments.length > 0 && <a style={{ float: 'right' }} title='link to attachment' href={testResultHref({ test, result, anchor: `attachment-${step.attachments[0]}` })} onClick={evt => { evt.stopPropagation(); }}>{icons.attachment()}</a>}
180179
{statusIcon(step.error || step.duration === -1 ? 'failed' : 'passed')}
181180
<span>{step.title}</span>
182181
{step.count > 1 && <><span className='test-result-counter'>{step.count}</span></>}
183182
{step.location && <span className='test-result-path'>{step.location.file}:{step.location.line}</span>}
184183
</span>} loadChildren={step.steps.length + (step.snippet ? 1 : 0) ? () => {
185-
const children = step.steps.map((s, i) => <StepTreeItem key={i} step={s} depth={depth + 1} result={result} test={test} />);
186-
if (step.snippet)
187-
children.unshift(<TestErrorView testId='test-snippet' key='line' error={step.snippet}/>);
188-
return children;
184+
const snippet = step.snippet ? [<TestErrorView testId='test-snippet' key='line' error={step.snippet}/>] : [];
185+
const steps = step.steps.map((s, i) => <StepTreeItem key={i} step={s} depth={depth + 1} result={result} test={test} />);
186+
const attachments = step.attachments.map(attachmentIndex => (
187+
<a key={'' + attachmentIndex}
188+
href={testResultHref({ test, result, anchor: `attachment-${attachmentIndex}` })}
189+
style={{ paddingLeft: depth * 22 + 4, textDecoration: 'none' }}
190+
>
191+
<span
192+
style={{ margin: '8px 0 0 8px', padding: '2px 10px', cursor: 'pointer' }}
193+
className='label label-color-gray'
194+
title={`see "${result.attachments[attachmentIndex].name}"`}
195+
>
196+
{icons.attachment()}{result.attachments[attachmentIndex].name}
197+
</span>
198+
</a>
199+
));
200+
return snippet.concat(steps, attachments);
189201
} : undefined} depth={depth}/>;
190202
};

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,10 @@ for (const useIntermediateMergeReport of [true, false] as const) {
932932
await showReport();
933933
await page.getByRole('link', { name: 'passing' }).click();
934934

935-
const attachment = page.getByText('foo-2', { exact: true });
935+
const attachment = page.getByTestId('attachments').getByText('foo-2', { exact: true });
936936
await expect(attachment).not.toBeInViewport();
937-
await page.getByLabel('attach "foo-2"').getByTitle('link to attachment').click();
937+
await page.getByLabel('attach "foo-2"').click();
938+
await page.getByTitle('see "foo-2"').click();
938939
await expect(attachment).toBeInViewport();
939940

940941
await page.reload();
@@ -961,9 +962,10 @@ for (const useIntermediateMergeReport of [true, false] as const) {
961962
await showReport();
962963
await page.getByRole('link', { name: 'passing' }).click();
963964

964-
const attachment = page.getByText('attachment', { exact: true });
965+
const attachment = page.getByTestId('attachments').getByText('attachment', { exact: true });
965966
await expect(attachment).not.toBeInViewport();
966-
await page.getByLabel('step').getByTitle('link to attachment').click();
967+
await page.getByLabel('step').click();
968+
await page.getByTitle('see "attachment"').click();
967969
await expect(attachment).toBeInViewport();
968970
});
969971

0 commit comments

Comments
 (0)