Skip to content

Commit

Permalink
fix(clipboard): typo + add test keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteves60 authored and dpellier committed Aug 3, 2023
1 parent 201c1e1 commit db341cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('e2e:osds-clipboard', () => {

async function mockClipboard(page: E2EPage): Promise<void> {
await page.evaluate(() => {
let clipboardText = null;
let clipboardText = '';
const clipboard = {
writeText: text => new Promise(resolve => resolve(clipboardText = text)),
readText: () => new Promise(resolve => resolve(clipboardText)),
Expand Down Expand Up @@ -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 } });
Expand All @@ -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('');
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class OsdsClipboard implements OdsClipboard<OdsStencilMethods<OdsClipboar
this.controller.handlerClick(this.value);
}

handlernKeydown(event: KeyboardEvent): void {
handlerKeydown(event: KeyboardEvent): void {
switch (event.code) {
case 'Space':
case 'Enter':
Expand All @@ -62,7 +62,7 @@ export class OsdsClipboard implements OdsClipboard<OdsStencilMethods<OdsClipboar
type={ OdsInputType.text }
value={ this.value }
onClick={ () => this.handlerClick() }
onKeydown={ (event: KeyboardEvent) => this.handlernKeydown(event) }
onKeydown={ (event: KeyboardEvent) => this.handlerKeydown(event) }
>
</osds-input>

Expand Down

0 comments on commit db341cd

Please sign in to comment.