github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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 { triggerCopyError, triggerCopySuccess } from 'ember-cli-clipboard/test-support';
    10  
    11  module('Integration | Component | copy-button', function(hooks) {
    12    setupRenderingTest(hooks);
    13  
    14    test('it shows the copy icon by default', async function(assert) {
    15      await render(hbs`<CopyButton @class="copy-button" />`);
    16  
    17      assert.dom('.copy-button .icon-is-copy-action').exists();
    18      await componentA11yAudit(this.element, assert);
    19    });
    20  
    21    test('it shows the success icon on success and resets afterward', async function(assert) {
    22      const clock = sinon.useFakeTimers({ shouldAdvanceTime: true });
    23  
    24      await render(hbs`<CopyButton @class="copy-button" />`);
    25  
    26      await click('.copy-button button');
    27      await triggerCopySuccess('.copy-button button');
    28  
    29      assert.dom('.copy-button .icon-is-copy-success').exists();
    30      await componentA11yAudit(this.element, assert);
    31  
    32      clock.runAll();
    33  
    34      assert.dom('.copy-button .icon-is-copy-success').doesNotExist();
    35      assert.dom('.copy-button .icon-is-copy-action').exists();
    36  
    37      clock.restore();
    38    });
    39  
    40    test('it shows the error icon on error', async function(assert) {
    41      await render(hbs`<CopyButton @class="copy-button" />`);
    42  
    43      await click('.copy-button button');
    44      await triggerCopyError('.copy-button button');
    45  
    46      assert.dom('.copy-button .icon-is-alert-triangle').exists();
    47      await componentA11yAudit(this.element, assert);
    48    });
    49  });