github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/copy-button-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupRenderingTest } from 'ember-qunit'; 3 import { click, render } from '@ember/test-helpers'; 4 import hbs from 'htmlbars-inline-precompile'; 5 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 6 7 import sinon from 'sinon'; 8 9 import { 10 triggerCopyError, 11 triggerCopySuccess, 12 } from 'ember-cli-clipboard/test-support'; 13 14 module('Integration | Component | copy-button', function (hooks) { 15 setupRenderingTest(hooks); 16 17 test('it shows the copy icon by default', async function (assert) { 18 assert.expect(2); 19 20 await render(hbs`<CopyButton @class="copy-button" />`); 21 22 assert.dom('.copy-button .icon-is-copy-action').exists(); 23 await componentA11yAudit(this.element, assert); 24 }); 25 26 test('it shows the success icon on success and resets afterward', async function (assert) { 27 assert.expect(4); 28 29 const clock = sinon.useFakeTimers({ shouldAdvanceTime: true }); 30 31 await render(hbs`<CopyButton @class="copy-button" />`); 32 33 await click('.copy-button button'); 34 await triggerCopySuccess('.copy-button button'); 35 36 assert.dom('.copy-button .icon-is-copy-success').exists(); 37 await componentA11yAudit(this.element, assert); 38 39 clock.runAll(); 40 41 assert.dom('.copy-button .icon-is-copy-success').doesNotExist(); 42 assert.dom('.copy-button .icon-is-copy-action').exists(); 43 44 clock.restore(); 45 }); 46 47 test('it shows the error icon on error', async function (assert) { 48 assert.expect(2); 49 50 await render(hbs`<CopyButton @class="copy-button" />`); 51 52 await click('.copy-button button'); 53 await triggerCopyError('.copy-button button'); 54 55 assert.dom('.copy-button .icon-is-alert-triangle').exists(); 56 await componentA11yAudit(this.element, assert); 57 }); 58 });