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';
|
|
|
|
|
|
|
|
import { triggerCopyError, triggerCopySuccess } from 'ember-cli-clipboard/test-support';
|
|
|
|
|
|
|
|
module('Integration | Component | copy-button', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|