Skip to content

Commit

Permalink
fix(clipboard): review PR
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteves60 authored and dpellier committed Aug 3, 2023
1 parent 32468dc commit 7f0c918
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/libraries/core/src/utils/clipboard/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { writeOnClipboard } from './write-on-clipboard';
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export function writeOnClipboard(textToWrite: string): Promise<void> {
console.log('test', textToWrite);
return navigator.clipboard.writeText(textToWrite);
try {
return navigator.clipboard.writeText(textToWrite);
} catch (error) {
console.error(error);
return Promise.resolve();
}
}
1 change: 1 addition & 0 deletions packages/libraries/core/src/utils/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './string/public-api';
export * from './time/public-api';
export * from './case/public-api';
export * from './computed/public-api';
export * from './clipboard/public-api';
6 changes: 3 additions & 3 deletions packages/stencil/components/clipboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ovhcloud/ods-stencil-clipboard",
"version": "14.0.1",
"version": "14.1.1",
"private": true,
"description": "Clipboard component",
"author": "OVH SAS",
Expand Down Expand Up @@ -35,10 +35,10 @@
"test:e2e:ci:screenshot:update": "stencil test --config stencil.config.ts --e2e --ci --screenshot --update-screenshot --passWithNoTests"
},
"dependencies": {
"@ovhcloud/ods-stencil-component": "^14.0.1"
"@ovhcloud/ods-stencil-component": "^14.1.1"
},
"devDependencies": {
"@ovhcloud/ods-stencil-component-dev": "^14.0.1"
"@ovhcloud/ods-stencil-component-dev": "^14.1.1"
},
"publishConfig": {
"registry": ""
Expand Down
4 changes: 2 additions & 2 deletions packages/stencil/components/clipboard/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ovhcloud/ods-stencil-clipboard-react",
"version": "14.0.1",
"version": "14.1.1",
"private": true,
"description": "React specific wrapper for ods",
"keywords": [],
Expand All @@ -20,7 +20,7 @@
"dist/"
],
"dependencies": {
"@ovhcloud/ods-stencil-clipboard": "^14.0.1",
"@ovhcloud/ods-stencil-clipboard": "^14.1.1",
"tslib": "*"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,32 @@ describe('e2e:osds-clipboard', () => {
let el: E2EElement;
let input: E2EElement;

async function mockClipboard(page: E2EPage): Promise<void> {
await page.evaluate(() => {
let clipboardText = null;
const clipboard = {
writeText: text => new Promise(resolve => resolve(clipboardText = text)),
readText: () => new Promise(resolve => resolve(clipboardText)),
};
(window["navigator"] as any)["clipboard"] = clipboard;
Object.defineProperty(navigator, 'clipboard', { value: clipboard });
});
}

async function setup({ attributes }: { attributes: Partial<OdsClipboardAttributes> }) {
const minimalAttributes: OdsClipboardAttributes = OdsCreateAttributes(attributes, odsClipboardDefaultAttributes);
const stringAttributes = OdsComponentAttributes2StringAttributes<OdsClipboardAttributes>(minimalAttributes, odsClipboardDefaultAttributes);

page = await newE2EPage();
const origin = await page.evaluate(() => window.origin);
await page.setContent(`<osds-clipboard ${OdsStringAttributes2Str(stringAttributes)}></osds-clipboard>`);

const origin = await page.evaluate(() => window.origin);
const browserContext = page.browserContext();
await browserContext.overridePermissions(origin, ['clipboard-write', 'clipboard-read']);
await page.setContent(`<osds-clipboard ${OdsStringAttributes2Str(stringAttributes)}></osds-clipboard>`);

await page.evaluate(() => document.body.style.setProperty('margin', '0px'));

await mockClipboard(page);

el = await page.find('osds-clipboard');
input = await page.find('osds-clipboard >>> osds-input');
await page.waitForChanges();
Expand All @@ -43,14 +57,14 @@ describe('e2e:osds-clipboard', () => {
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 } });
// await page.evaluate(() => navigator.clipboard.writeText(''));
it('should not copy the input value because of disabled', async () => {
const value = 'text to copy';
await setup({ attributes: { value, disabled: true } });
await page.evaluate(() => navigator.clipboard.writeText(''));

// await input.click();
await input.click();

// expect(await page.evaluate(() => navigator.clipboard.readText())).toBe('');
// });
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe('');
});

});
4 changes: 2 additions & 2 deletions packages/stencil/components/clipboard/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ovhcloud/ods-stencil-clipboard-vue",
"version": "14.0.1",
"version": "14.1.1",
"private": true,
"description": "Vue specific wrapper for ods",
"keywords": [],
Expand All @@ -20,7 +20,7 @@
"dist/"
],
"dependencies": {
"@ovhcloud/ods-stencil-clipboard": "^14.0.1"
"@ovhcloud/ods-stencil-clipboard": "^14.1.1"
},
"peerDependencies": {
"vue": ">=3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cursor: text;
}

:host osds-icon {
:host(:not([disabled])) osds-icon {
cursor: default;
}

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6111,7 +6111,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@ovhcloud/ods-stencil-clipboard-react@workspace:packages/stencil/components/clipboard/react"
dependencies:
"@ovhcloud/ods-stencil-clipboard": ^14.0.1
"@ovhcloud/ods-stencil-clipboard": ^14.1.1
"@types/react": 17.0.37
"@types/react-dom": 17.0.11
react: 16.14.0
Expand All @@ -6129,7 +6129,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@ovhcloud/ods-stencil-clipboard-vue@workspace:packages/stencil/components/clipboard/vue"
dependencies:
"@ovhcloud/ods-stencil-clipboard": ^14.0.1
"@ovhcloud/ods-stencil-clipboard": ^14.1.1
rimraf: ^3.0.2
typescript: 4.7.4
vue: ^3.2.41
Expand All @@ -6138,12 +6138,12 @@ __metadata:
languageName: unknown
linkType: soft

"@ovhcloud/ods-stencil-clipboard@^14.0.1, @ovhcloud/ods-stencil-clipboard@workspace:packages/stencil/components/clipboard":
"@ovhcloud/ods-stencil-clipboard@^14.1.1, @ovhcloud/ods-stencil-clipboard@workspace:packages/stencil/components/clipboard":
version: 0.0.0-use.local
resolution: "@ovhcloud/ods-stencil-clipboard@workspace:packages/stencil/components/clipboard"
dependencies:
"@ovhcloud/ods-stencil-component": ^14.0.1
"@ovhcloud/ods-stencil-component-dev": ^14.0.1
"@ovhcloud/ods-stencil-component": ^14.1.1
"@ovhcloud/ods-stencil-component-dev": ^14.1.1
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 7f0c918

Please sign in to comment.