Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy annotation text in HTML report #30749

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/html-reporter/src/copyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export const CopyToClipboard: React.FunctionComponent<{
});
}, [value]);
const iconElement = icon === 'check' ? icons.check() : icon === 'cross' ? icons.cross() : icons.copy();
return <button className='copy-icon' onClick={handleCopy}>{iconElement}</button>;
return <button className='copy-icon' onClick={handleCopy} aria-label="copy to clipboard">{iconElement}</button>;
};
10 changes: 10 additions & 0 deletions packages/html-reporter/src/testCaseView.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@
display: flex;
flex-direction: row;
flex-wrap: wrap;
}

.annotation-copy-button{
padding-left: 3px;
display: none;
}

.test-case-annotation:hover .annotation-copy-button{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like you would need this dance for every copy button application. Would it be possible to do something like this to encapsulate these styles:

<CopyToClipboardContainer description={description}>
  <span className='annotation-copy-button'/>
</CopyToClipboardContainer>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not every copy button , just for this annotation copy button . We want to display the copy button only when we hover over the text . Could you please help me with how your approach would help in this use case ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CopyToClipboardContainer container would position the copy button after its children and make it visible upon hover.

padding-left: 3px;
display: inline;
}
8 changes: 7 additions & 1 deletion packages/html-reporter/src/testCaseView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ const testCase: TestCase = {

test('should render test case', async ({ mount }) => {
const component = await mount(<TestCaseView projectNames={['chromium', 'webkit']} test={testCase} run={0} anchor=''></TestCaseView>);
await expect(component.getByText('Annotation text', { exact: false }).first()).toBeVisible();
const firstAnnotationElement = component.getByText('Annotation text', { exact: false }).first();
await expect(firstAnnotationElement).toBeVisible();
await expect(component.getByRole('button', { name: 'copy to clipboard' }).first()).not.toBeVisible();
await expect(component.getByRole('button', { name: 'copy to clipboard' }).nth(1)).not.toBeVisible();
await firstAnnotationElement.hover();
await expect(component.getByRole('button', { name: 'copy to clipboard' }).first()).toBeVisible();
await expect(component.getByRole('button', { name: 'copy to clipboard' }).nth(1)).not.toBeVisible();
await component.getByText('Annotations').click();
await expect(component.getByText('Annotation text')).not.toBeVisible();
await expect(component.getByText('Outer step')).toBeVisible();
Expand Down
6 changes: 4 additions & 2 deletions packages/html-reporter/src/testCaseView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import './testCaseView.css';
import { TestResultView } from './testResultView';
import { hashStringToInt } from './labelUtils';
import { msToString } from './uiUtils';
import { CopyToClipboard } from './copyToClipboard';

export const TestCaseView: React.FC<{
projectNames: string[],
Expand Down Expand Up @@ -68,15 +69,16 @@ function renderAnnotationDescription(description: string) {
try {
if (['http:', 'https:'].includes(new URL(description).protocol))
return <a href={description} target='_blank' rel='noopener noreferrer'>{description}</a>;
} catch {}
} catch { }
return description;
}

function TestCaseAnnotationView({ annotation: { type, description } }: { annotation: TestCaseAnnotation }) {
return (
<div className='test-case-annotation'>
<span style={{ fontWeight: 'bold' }}>{type}</span>
<span style={{ fontWeight: 'bold', display: 'inline-block', marginBlock: '3px' }}>{type}</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display: 'inline-block' - what else would this span be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default span will be inline . I needed to add some margin to solve following problem

without-display-property.mp4
with-display-property.mp4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping it would go away with the container approach.

{description && <span>: {renderAnnotationDescription(description)}</span>}
<span className='annotation-copy-button'>{description && <CopyToClipboard value={description} />}</span>
</div>
);
}
Expand Down
Loading