2019-08-27 22:50:53 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render, click } from '@ember/test-helpers';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | Confirm', function (hooks) {
|
2019-08-27 22:50:53 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2019-08-27 22:50:53 +00:00
|
|
|
this.set('id', 'foo');
|
|
|
|
this.set('title', 'Are you sure?');
|
|
|
|
this.set('message', 'You will not be able to recover this item later.');
|
|
|
|
this.set('triggerText', 'Click me!');
|
|
|
|
this.set('onConfirm', sinon.spy());
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders', async function (assert) {
|
2019-08-27 22:50:53 +00:00
|
|
|
await render(hbs`
|
|
|
|
<Confirm as |c|>
|
|
|
|
<c.Message
|
|
|
|
@id={{id}}
|
|
|
|
@title={{title}}
|
|
|
|
@triggerText={{triggerText}}
|
|
|
|
@message={{message}}
|
|
|
|
@onConfirm={{onConfirm}}
|
|
|
|
/>
|
|
|
|
</Confirm>
|
|
|
|
`);
|
|
|
|
|
|
|
|
assert.dom('.confirm-wrapper').exists();
|
|
|
|
assert.dom('.confirm').containsText(this.triggerText);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('does not show the confirmation message until it is triggered', async function (assert) {
|
2019-08-27 22:50:53 +00:00
|
|
|
await render(hbs`
|
|
|
|
<Confirm as |c|>
|
|
|
|
<c.Message
|
|
|
|
@id={{id}}
|
|
|
|
@title={{title}}
|
|
|
|
@triggerText={{triggerText}}
|
|
|
|
@message={{message}}
|
|
|
|
@onConfirm={{onConfirm}}
|
|
|
|
/>
|
|
|
|
</Confirm>
|
|
|
|
`);
|
|
|
|
assert.dom('.confirm-overlay').doesNotContainText(this.message);
|
|
|
|
|
|
|
|
await click('[data-test-confirm-action-trigger]');
|
|
|
|
|
|
|
|
assert.dom('.confirm-overlay').containsText(this.title);
|
|
|
|
assert.dom('.confirm-overlay').containsText(this.message);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it calls onConfirm when the confirm button is clicked', async function (assert) {
|
2019-08-27 22:50:53 +00:00
|
|
|
await render(hbs`
|
|
|
|
<Confirm as |c|>
|
|
|
|
<c.Message
|
|
|
|
@id={{id}}
|
|
|
|
@title={{title}}
|
|
|
|
@triggerText={{triggerText}}
|
|
|
|
@message={{message}}
|
|
|
|
@onConfirm={{onConfirm}}
|
|
|
|
/>
|
|
|
|
</Confirm>
|
|
|
|
`);
|
|
|
|
await click('[data-test-confirm-action-trigger]');
|
|
|
|
await click('[data-test-confirm-button=true]');
|
|
|
|
|
|
|
|
assert.ok(this.onConfirm.calledOnce);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it shows only the active triggers message', async function (assert) {
|
2019-08-27 22:50:53 +00:00
|
|
|
await render(hbs`
|
|
|
|
<Confirm as |c|>
|
|
|
|
<c.Message
|
|
|
|
@id={{id}}
|
|
|
|
@title={{title}}
|
|
|
|
@triggerText={{triggerText}}
|
|
|
|
@message={{message}}
|
|
|
|
@onConfirm={{onConfirm}}
|
|
|
|
/>
|
|
|
|
<c.Message
|
|
|
|
@id='bar'
|
|
|
|
@title='Wow'
|
|
|
|
@message='Bazinga!'
|
|
|
|
@onConfirm={{onConfirm}}
|
|
|
|
/>
|
|
|
|
</Confirm>
|
|
|
|
`);
|
|
|
|
|
|
|
|
await click(`[data-test-confirm-action-trigger=${this.id}]`);
|
|
|
|
assert.dom('.confirm-overlay').containsText(this.title);
|
|
|
|
assert.dom('.confirm-overlay').containsText(this.message);
|
|
|
|
|
|
|
|
await click('[data-test-confirm-cancel-button]');
|
|
|
|
|
|
|
|
await click("[data-test-confirm-action-trigger='bar']");
|
|
|
|
assert.dom('.confirm-overlay').containsText('Wow');
|
|
|
|
assert.dom('.confirm-overlay').containsText('Bazinga!');
|
|
|
|
});
|
|
|
|
});
|