github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/copy-button-test.js (about)

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