[ACS-4051] Copy to clipboard button is now accessible through the keyboard enter earlier which was only accessible through mouse click (#8119)

* 880196 CSV issue addressed

* unit test cases for clipboard directive
This commit is contained in:
jatin2008 2023-01-13 22:48:01 +05:30 committed by GitHub
parent db38ccda7a
commit 067d4e9369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -64,6 +64,14 @@ describe('ClipboardDirective', () => {
expect(clipboardService.copyToClipboard).toHaveBeenCalled();
});
it('should notify copy target value on mouse enter event', () => {
spyOn(clipboardService, 'copyToClipboard');
fixture.nativeElement.querySelector('input').value = 'some value';
window.dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'}));
expect(clipboardService.copyToClipboard).toHaveBeenCalled();
});
});
describe('CopyClipboardDirective', () => {
@ -128,6 +136,15 @@ describe('CopyClipboardDirective', () => {
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy');
}));
it('should copy the content of element on mouse enter', fakeAsync(() => {
fixture.detectChanges();
spyOn(navigator.clipboard, 'writeText');
window.dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'}));
tick();
fixture.detectChanges();
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy');
}));
it('should not copy the content of element when click it', fakeAsync(() => {
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
fixture.detectChanges();

View File

@ -46,6 +46,12 @@ export class ClipboardDirective {
event.stopPropagation();
this.copyToClipboard();
}
@HostListener('window:keydown.enter', ['$event'])
handleKeyDown(event: KeyboardEvent){
event.preventDefault();
event.stopPropagation();
this.copyToClipboard();
}
@HostListener('mouseenter')
showTooltip() {