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
This commit is contained in:
1 parent
b5d33948dc
commit
9204c63b17
6 files changed
+15
-137
No files matched your search
@@ -7,6 +7,7 @@ import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { click, render } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
import sinon from 'sinon';
|
||||
|
||||
module('Integration | Component | rose/code-editor/toolbar', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
@@ -43,6 +44,9 @@ module('Integration | Component | rose/code-editor/toolbar', function (hooks) {
|
||||
});
|
||||
|
||||
test('it calls onCopy callback', async function (assert) {
|
||||
// `writeText` could fail if the document is not in focus which is common during test runs
|
||||
sinon.stub(window.navigator.clipboard, 'writeText').resolves();
|
||||
|
||||
const onCopy = () => {
|
||||
this.set('called', true);
|
||||
};
|
||||
@@ -53,8 +57,9 @@ module('Integration | Component | rose/code-editor/toolbar', function (hooks) {
|
||||
assert.dom(toolbarSelector).isVisible();
|
||||
assert.dom(copyButtonSelector).isVisible();
|
||||
assert.dom(menuDividerSelector).doesNotExist();
|
||||
|
||||
await click(copyButtonSelector);
|
||||
assert.true(this.called);
|
||||
|
||||
sinon.restore();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user