tweak: properly apply label, fix tests
This commit is contained in:
parent
e27aa15e12
commit
612cd17365
|
|
@ -28,9 +28,10 @@ type Attachment = AfterActionTraceEventAttachment & { traceUrl: string };
|
|||
|
||||
type TextAttachmentProps = {
|
||||
attachment: Attachment;
|
||||
label?: string;
|
||||
};
|
||||
|
||||
const TextAttachment: React.FunctionComponent<TextAttachmentProps> = ({ attachment }) => {
|
||||
const TextAttachment: React.FunctionComponent<TextAttachmentProps> = ({ attachment, label }) => {
|
||||
const [text, setText] = React.useState<string | null>(null);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
|
@ -43,9 +44,13 @@ const TextAttachment: React.FunctionComponent<TextAttachmentProps> = ({ attachme
|
|||
isMounted = false;
|
||||
};
|
||||
}, [attachment]);
|
||||
return text ?
|
||||
<CodeMirrorWrapper text={text} readOnly wrapLines={false}></CodeMirrorWrapper> :
|
||||
<div><i>Loading...</i></div>;
|
||||
return <div aria-label={label}>
|
||||
{
|
||||
text ?
|
||||
<CodeMirrorWrapper text={text} readOnly wrapLines={false}></CodeMirrorWrapper> :
|
||||
<div><i>Loading...</i></div>
|
||||
}
|
||||
</div>;
|
||||
};
|
||||
|
||||
export const AttachmentsTab: React.FunctionComponent<{
|
||||
|
|
@ -111,7 +116,7 @@ export const AttachmentsTab: React.FunctionComponent<{
|
|||
<div className='attachment-item' key={`attachment-${i}`}>
|
||||
<a href={attachmentURL(a) + '&download'}>{a.name}</a>
|
||||
{ isTextualMimeType(a.contentType) ?
|
||||
<TextAttachment attachment={a} /> :
|
||||
<TextAttachment attachment={a} label={a.name}/> :
|
||||
<div><i>no preview available</i></div>
|
||||
}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -36,18 +36,17 @@ test('should contain text attachment', async ({ runUITest }) => {
|
|||
for (const { name, content, displayedAsText } of [
|
||||
{ name: 'note', content: 'attach test', displayedAsText: false },
|
||||
{ name: '🎭', content: 'hi tester!', displayedAsText: true },
|
||||
{ name: 'escaped', content: '## Header\\n\\n> TODO: some todo\\n- _Foo_\\n- **Bar**', displayedAsText: true },
|
||||
{ name: 'escaped', content: '## Header\n\n> TODO: some todo\n- _Foo_\n- **Bar**', displayedAsText: true },
|
||||
]) {
|
||||
await page.getByText(`attach "${name}"`, { exact: true }).click();
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
if (displayedAsText)
|
||||
await expect(page.getByLabel(name)).toHaveText(content);
|
||||
await expect(page.getByLabel(name)).toContainText(content.split('\n')?.[0]);
|
||||
await page.getByRole('link', { name: name }).click();
|
||||
const download = await downloadPromise;
|
||||
expect(download.suggestedFilename()).toBe(name);
|
||||
expect((await readAllFromStream(await download.createReadStream())).toString()).toContain(content);
|
||||
}
|
||||
await page.pause();
|
||||
});
|
||||
|
||||
test('should contain binary attachment', async ({ runUITest }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue