Skip to content

Commit 9204c63

Browse files
authored
Remove ember-cli-clipboard (#3098)
* chore: πŸ€– replace CopyButton usage with Hds::Copy::Button * chore: πŸ€– remove ember-cli-clipboard * test: πŸ’ fix test by stubbing writeText The hds copy button uses the browser clipboard api. The writeText api can fail if the window is not active. This does not happen in practice because the window has to be active to be clicked by the user. But in tests with synthetic triggers this can fail. Stubbing the writeText method is also how hds tests their component: https://github.com/hashicorp/design-system/blob/990981b5741f9a6bf28d100c330b7865ba74e506/showcase/tests/integration/components/hds/copy/button/index-test.gts#L20
1 parent b5d3394 commit 9204c63

File tree

6 files changed

+15
-137
lines changed

6 files changed

+15
-137
lines changed

β€Žaddons/rose/addon/components/rose/code-editor/toolbar/index.hbsβ€Ž

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
data-test-code-editor-toolbar-menu-divider
2222
></div>
2323
{{/if}}
24-
<CopyButton
25-
@text={{@copyText}}
24+
<Hds::Copy::Button
25+
@text='Copy code'
26+
@textToCopy={{@copyText}}
2627
@onSuccess={{this.copied}}
27-
class='rose-code-editor-toolbar__copy-button'
2828
data-test-code-editor-toolbar-copy-button
29-
>
30-
<Hds::Icon @name={{this.copyIconType}} @isInline={{true}} />
31-
Copy code
32-
</CopyButton>
29+
/>
3330
</div>
3431
</div>

β€Žaddons/rose/addon/components/rose/code-editor/toolbar/index.jsβ€Ž

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,11 @@
44
*/
55

66
import Component from '@glimmer/component';
7-
import { tracked } from '@glimmer/tracking';
87
import { action } from '@ember/object';
9-
import { later } from '@ember/runloop';
10-
11-
export const COPY_ICON_TYPE = 'clipboard-copy';
12-
export const COPIED_ICON_TYPE = 'clipboard-checked';
138

149
export default class RoseCodeEditorToolbarComponent extends Component {
15-
@tracked copyIconType = COPY_ICON_TYPE;
16-
1710
@action
1811
copied() {
19-
let { onCopy } = this.args;
20-
let originalIconType = this.copyIconType;
21-
22-
this.copyIconType = COPIED_ICON_TYPE;
23-
24-
if (onCopy) {
25-
onCopy();
26-
}
27-
// eslint-disable-next-line ember/no-runloop
28-
later(() => (this.copyIconType = originalIconType), 1000);
12+
this.args.onCopy?.();
2913
}
3014
}

β€Žaddons/rose/app/styles/rose/components/code-editor/_index.scssβ€Ž

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,4 @@
6767
height: sizing.rems(xl);
6868
}
6969
}
70-
71-
&__copy-button {
72-
border: none;
73-
background-color: inherit;
74-
cursor: pointer;
75-
color: var(--ui-gray-starker-2);
76-
margin-right: sizing.rems(xs);
77-
margin-left: sizing.rems(s);
78-
height: sizing.rems(xl);
79-
white-space: nowrap;
80-
81-
.hds-icon {
82-
vertical-align: top;
83-
}
84-
}
8570
}

β€Žaddons/rose/package.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"codemirror": "5.65.7",
3838
"ember-auto-import": "^2.10.0",
3939
"ember-cli-babel": "^8.2.0",
40-
"ember-cli-clipboard": "^1.2.1",
4140
"ember-cli-htmlbars": "^6.3.0",
4241
"ember-cli-sass": "^11.0.1",
4342
"ember-focus-trap": "^1.0.1",
@@ -87,6 +86,7 @@
8786
"prettier": "^3.3.3",
8887
"qunit": "^2.22.0",
8988
"qunit-dom": "^3.2.1",
89+
"sinon": "^19.0.2",
9090
"stylelint": "^15.11.0",
9191
"stylelint-config-prettier-scss": "^0.0.1",
9292
"stylelint-config-standard-scss": "^11.0.0",

β€Žaddons/rose/tests/integration/components/rose/code-editor/toolbar-test.jsβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { module, test } from 'qunit';
77
import { setupRenderingTest } from 'ember-qunit';
88
import { click, render } from '@ember/test-helpers';
99
import { hbs } from 'ember-cli-htmlbars';
10+
import sinon from 'sinon';
1011

1112
module('Integration | Component | rose/code-editor/toolbar', function (hooks) {
1213
setupRenderingTest(hooks);
@@ -43,6 +44,9 @@ module('Integration | Component | rose/code-editor/toolbar', function (hooks) {
4344
});
4445

4546
test('it calls onCopy callback', async function (assert) {
47+
// `writeText` could fail if the document is not in focus which is common during test runs
48+
sinon.stub(window.navigator.clipboard, 'writeText').resolves();
49+
4650
const onCopy = () => {
4751
this.set('called', true);
4852
};
@@ -53,8 +57,9 @@ module('Integration | Component | rose/code-editor/toolbar', function (hooks) {
5357
assert.dom(toolbarSelector).isVisible();
5458
assert.dom(copyButtonSelector).isVisible();
5559
assert.dom(menuDividerSelector).doesNotExist();
56-
5760
await click(copyButtonSelector);
5861
assert.true(this.called);
62+
63+
sinon.restore();
5964
});
6065
});

β€Žpnpm-lock.yamlβ€Ž

Lines changed: 3 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)