diff --git a/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.e2e.ts b/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.e2e.ts index cda08b58bb..a272dc1133 100644 --- a/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.e2e.ts +++ b/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.e2e.ts @@ -9,7 +9,7 @@ describe('e2e:osds-clipboard', () => { async function mockClipboard(page: E2EPage): Promise { await page.evaluate(() => { - let clipboardText = null; + let clipboardText = ''; const clipboard = { writeText: text => new Promise(resolve => resolve(clipboardText = text)), readText: () => new Promise(resolve => resolve(clipboardText)), @@ -57,6 +57,17 @@ describe('e2e:osds-clipboard', () => { expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(value); }); + it('should copy the input value with keyboard', async () => { + const value = 'text to copy'; + + await setup({ attributes: { value } }); + + await page.keyboard.press('Tab'); + await page.keyboard.press('Enter'); + + expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(value); + }); + it('should not copy the input value because of disabled', async () => { const value = 'text to copy'; await setup({ attributes: { value, disabled: true } }); @@ -67,4 +78,15 @@ describe('e2e:osds-clipboard', () => { expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(''); }); + it('should noy copy the input value with keyboard', async () => { + const value = 'text to copy'; + + await setup({ attributes: { value, disabled: true } }); + + await page.keyboard.press('Tab'); + await page.keyboard.press('Enter'); + + expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(''); + }); + }); diff --git a/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.tsx b/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.tsx index 7faf39f6ca..d081bf9bc8 100644 --- a/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.tsx +++ b/packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.tsx @@ -39,7 +39,7 @@ export class OsdsClipboard implements OdsClipboard this.handlerClick() } - onKeydown={ (event: KeyboardEvent) => this.handlernKeydown(event) } + onKeydown={ (event: KeyboardEvent) => this.handlerKeydown(event) } >