open-nomad/ui/tests/integration/components/copy-button-test.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { click, render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
import sinon from 'sinon';
2021-12-28 16:08:12 +00:00
import {
triggerCopyError,
triggerCopySuccess,
} from 'ember-cli-clipboard/test-support';
2021-12-28 14:45:20 +00:00
module('Integration | Component | copy-button', function (hooks) {
setupRenderingTest(hooks);
2021-12-28 14:45:20 +00:00
test('it shows the copy icon by default', async function (assert) {
assert.expect(2);
await render(hbs`<CopyButton @class="copy-button" />`);
assert.dom('.copy-button .icon-is-copy-action').exists();
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('it shows the success icon on success and resets afterward', async function (assert) {
assert.expect(4);
const clock = sinon.useFakeTimers({ shouldAdvanceTime: true });
await render(hbs`<CopyButton @class="copy-button" />`);
await click('.copy-button button');
await triggerCopySuccess('.copy-button button');
assert.dom('.copy-button .icon-is-copy-success').exists();
await componentA11yAudit(this.element, assert);
clock.runAll();
assert.dom('.copy-button .icon-is-copy-success').doesNotExist();
assert.dom('.copy-button .icon-is-copy-action').exists();
clock.restore();
});
2021-12-28 14:45:20 +00:00
test('it shows the error icon on error', async function (assert) {
assert.expect(2);
await render(hbs`<CopyButton @class="copy-button" />`);
await click('.copy-button button');
await triggerCopyError('.copy-button button');
assert.dom('.copy-button .icon-is-alert-triangle').exists();
await componentA11yAudit(this.element, assert);
});
});