mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: center image diff (#8947)
This commit is contained in:
parent
131239569d
commit
fc972fcadd
@ -209,4 +209,6 @@ video, img {
|
|||||||
box-shadow: var(--box-shadow-thick);
|
box-shadow: var(--box-shadow-thick);
|
||||||
width: 80%;
|
width: 80%;
|
||||||
margin: 20px auto;
|
margin: 20px auto;
|
||||||
|
min-width: 80%;
|
||||||
|
min-height: 300px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,28 +163,53 @@ const TestResultView: React.FC<{
|
|||||||
result: TestResult,
|
result: TestResult,
|
||||||
}> = ({ result }) => {
|
}> = ({ result }) => {
|
||||||
|
|
||||||
const { screenshots, videos, attachmentsMap } = React.useMemo(() => {
|
const { screenshots, videos, otherAttachments, attachmentsMap } = React.useMemo(() => {
|
||||||
const attachmentsMap = new Map<string, TestAttachment>();
|
const attachmentsMap = new Map<string, TestAttachment>();
|
||||||
const attachments = result?.attachments || [];
|
const attachments = result?.attachments || [];
|
||||||
|
const otherAttachments: TestAttachment[] = [];
|
||||||
const screenshots = attachments.filter(a => a.name === 'screenshot');
|
const screenshots = attachments.filter(a => a.name === 'screenshot');
|
||||||
const videos = attachments.filter(a => a.name === 'video');
|
const videos = attachments.filter(a => a.name === 'video');
|
||||||
for (const a of attachments)
|
const knownNames = new Set(['screenshot', 'image', 'expected', 'actual', 'diff', 'video']);
|
||||||
|
for (const a of attachments) {
|
||||||
attachmentsMap.set(a.name, a);
|
attachmentsMap.set(a.name, a);
|
||||||
return { attachmentsMap, screenshots, videos };
|
if (!knownNames.has(a.name))
|
||||||
|
otherAttachments.push(a);
|
||||||
|
}
|
||||||
|
return { attachmentsMap, screenshots, videos, otherAttachments };
|
||||||
}, [ result ]);
|
}, [ result ]);
|
||||||
|
|
||||||
|
const expected = attachmentsMap.get('expected');
|
||||||
|
const actual = attachmentsMap.get('actual');
|
||||||
|
const diff = attachmentsMap.get('diff');
|
||||||
return <div className='test-result'>
|
return <div className='test-result'>
|
||||||
{result.error && <ErrorMessage key={-1} error={result.error}></ErrorMessage>}
|
{result.error && <ErrorMessage key={-1} error={result.error}></ErrorMessage>}
|
||||||
{result.steps.map((step, i) => <StepTreeItem key={i} step={step} depth={0}></StepTreeItem>)}
|
{result.steps.map((step, i) => <StepTreeItem key={i} step={step} depth={0}></StepTreeItem>)}
|
||||||
{attachmentsMap.has('expected') && attachmentsMap.has('actual') && <ImageDiff actual={attachmentsMap.get('actual')!} expected={attachmentsMap.get('expected')!} diff={attachmentsMap.get('diff')}></ImageDiff>}
|
|
||||||
{!!screenshots && <div className='test-overview-title'>Screenshots</div>}
|
{expected && actual && <div className='vbox'>
|
||||||
{screenshots.map((a, i) => <img key={`screenshot-${i}`} src={a.path} />)}
|
<ImageDiff actual={actual} expected={expected} diff={diff}></ImageDiff>
|
||||||
|
<AttachmentLink key={`expected`} attachment={expected}></AttachmentLink>
|
||||||
|
<AttachmentLink key={`actual`} attachment={actual}></AttachmentLink>
|
||||||
|
{diff && <AttachmentLink key={`diff`} attachment={diff}></AttachmentLink>}
|
||||||
|
</div>}
|
||||||
|
|
||||||
|
{!!screenshots.length && <div className='test-overview-title'>Screenshots</div>}
|
||||||
|
{screenshots.map((a, i) => {
|
||||||
|
return <div className='vbox'>
|
||||||
|
<img key={`screenshot-${i}`} src={a.path} />
|
||||||
|
<AttachmentLink key={`screenshot-link-${i}`} attachment={a}></AttachmentLink>
|
||||||
|
</div>;
|
||||||
|
})}
|
||||||
|
|
||||||
{!!videos.length && <div className='test-overview-title'>Videos</div>}
|
{!!videos.length && <div className='test-overview-title'>Videos</div>}
|
||||||
{videos.map((a, i) => <video key={`video-${i}`} controls>
|
{videos.map((a, i) => <div className='vbox'>
|
||||||
<source src={a.path} type={a.contentType}/>
|
<video key={`video-${i}`} controls>
|
||||||
</video>)}
|
<source src={a.path} type={a.contentType}/>
|
||||||
{!!result.attachments && <div className='test-overview-title'>Attachments</div>}
|
</video>
|
||||||
{result.attachments.map((a, i) => <AttachmentLink key={`attachment-${i}`} attachment={a}></AttachmentLink>)}
|
<AttachmentLink key={`video-link-${i}`} attachment={a}></AttachmentLink>
|
||||||
|
</div>)}
|
||||||
|
|
||||||
|
{!!otherAttachments && <div className='test-overview-title'>Attachments</div>}
|
||||||
|
{otherAttachments.map((a, i) => <AttachmentLink key={`attachment-${i}`} attachment={a}></AttachmentLink>)}
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -238,18 +263,18 @@ export const ImageDiff: React.FunctionComponent<{
|
|||||||
tabs.push({
|
tabs.push({
|
||||||
id: 'actual',
|
id: 'actual',
|
||||||
title: 'Actual',
|
title: 'Actual',
|
||||||
render: () => <div className='image-preview'><img src={actual.path}/></div>
|
render: () => <img src={actual.path}/>
|
||||||
});
|
});
|
||||||
tabs.push({
|
tabs.push({
|
||||||
id: 'expected',
|
id: 'expected',
|
||||||
title: 'Expected',
|
title: 'Expected',
|
||||||
render: () => <div className='image-preview'><img src={expected.path}/></div>
|
render: () => <img src={expected.path}/>
|
||||||
});
|
});
|
||||||
if (diff) {
|
if (diff) {
|
||||||
tabs.push({
|
tabs.push({
|
||||||
id: 'diff',
|
id: 'diff',
|
||||||
title: 'Diff',
|
title: 'Diff',
|
||||||
render: () => <div className='image-preview'><img src={diff.path}/></div>,
|
render: () => <img src={diff.path}/>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return <div className='vbox test-image-mismatch'>
|
return <div className='vbox test-image-mismatch'>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user