2019-07-15 17:14:32 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { click, render } from '@ember/test-helpers';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2019-07-15 17:14:32 +00:00
|
|
|
|
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
import {
|
|
|
|
triggerCopyError,
|
|
|
|
triggerCopySuccess,
|
|
|
|
} from 'ember-cli-clipboard/test-support';
|
2019-07-15 17:14:32 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | copy-button', function (hooks) {
|
2019-07-15 17:14:32 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it shows the copy icon by default', async function (assert) {
|
2020-07-09 17:30:11 +00:00
|
|
|
await render(hbs`<CopyButton @class="copy-button" />`);
|
2019-07-15 17:14:32 +00:00
|
|
|
|
|
|
|
assert.dom('.copy-button .icon-is-copy-action').exists();
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2019-07-15 17:14:32 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it shows the success icon on success and resets afterward', async function (assert) {
|
2020-08-25 15:56:02 +00:00
|
|
|
const clock = sinon.useFakeTimers({ shouldAdvanceTime: true });
|
2019-07-15 17:14:32 +00:00
|
|
|
|
2020-07-09 17:30:11 +00:00
|
|
|
await render(hbs`<CopyButton @class="copy-button" />`);
|
2019-07-15 17:14:32 +00:00
|
|
|
|
|
|
|
await click('.copy-button button');
|
|
|
|
await triggerCopySuccess('.copy-button button');
|
|
|
|
|
|
|
|
assert.dom('.copy-button .icon-is-copy-success').exists();
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2019-07-15 17:14:32 +00:00
|
|
|
|
|
|
|
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) {
|
2020-07-09 17:30:11 +00:00
|
|
|
await render(hbs`<CopyButton @class="copy-button" />`);
|
2019-07-15 17:14:32 +00:00
|
|
|
|
|
|
|
await click('.copy-button button');
|
|
|
|
await triggerCopyError('.copy-button button');
|
|
|
|
|
|
|
|
assert.dom('.copy-button .icon-is-alert-triangle').exists();
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2019-07-15 17:14:32 +00:00
|
|
|
});
|
|
|
|
});
|