Skip to content

Commit

Permalink
Write test cases for copy annotation text feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman Kumar committed Apr 1, 2024
1 parent 66a5b45 commit 86c5555
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/html-reporter/src/copyToClipboard.tsx
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>;
};
4 changes: 2 additions & 2 deletions packages/html-reporter/src/testCaseView.css
Expand Up @@ -75,12 +75,12 @@
flex-wrap: wrap;
}

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

.test-case-annotation:hover #annotation-copy-button{
.test-case-annotation:hover .annotation-copy-button{
padding-left: 3px;
display: inline;
}
8 changes: 7 additions & 1 deletion packages/html-reporter/src/testCaseView.spec.tsx
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
2 changes: 1 addition & 1 deletion packages/html-reporter/src/testCaseView.tsx
Expand Up @@ -78,7 +78,7 @@ function TestCaseAnnotationView({ annotation: { type, description } }: { annotat
<div className='test-case-annotation'>
<span style={{ fontWeight: 'bold', display: 'inline-block', marginBlock: '3px' }}>{type}</span>
{description && <span>: {renderAnnotationDescription(description)}</span>}
<span id='annotation-copy-button'>{description && <CopyToClipboard value={description} />}</span>
<span className='annotation-copy-button'>{description && <CopyToClipboard value={description} />}</span>
</div>
);
}
Expand Down

0 comments on commit 86c5555

Please sign in to comment.