Files
threshold-ui/addons/core/tests/integration/components/pending-confirmations-test.js
T

72 lines
2.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-10-14 09:33:44 -04:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, findAll, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
2020-11-16 15:08:59 -05:00
module('Integration | Component | pending-confirmations', function (hooks) {
2020-10-14 09:33:44 -04:00
setupRenderingTest(hooks);
2020-11-16 15:08:59 -05:00
test('it renders pending confirmations', async function (assert) {
2020-10-14 09:33:44 -04:00
assert.expect(2);
const service = this.owner.lookup('service:confirm');
service.enabled = true;
await render(hbs`
<PendingConfirmations as |confirmations|>
<div class="pending">Pending</div>
</PendingConfirmations>
`);
assert.strictEqual(
findAll('.pending').length,
0,
'No pending confirmations'
);
2020-10-14 09:33:44 -04:00
service.confirm();
await render(hbs`
<PendingConfirmations as |confirmations|>
<div class="pending">Pending</div>
</PendingConfirmations>
`);
assert.strictEqual(
findAll('.pending').length,
1,
'One pending confirmations'
);
2020-10-14 09:33:44 -04:00
});
2020-11-16 15:08:59 -05:00
test('it exposes a confirm action that confirms the confirmation', async function (assert) {
2020-10-14 09:33:44 -04:00
assert.expect(3);
const service = this.owner.lookup('service:confirm');
service.enabled = true;
const confirmation = service.confirm();
confirmation.then(() => assert.ok(true, 'confirmation.then was called'));
await render(hbs`
<PendingConfirmations as |confirmations confirm|>
<button {{on "click" confirm}}>Confirm</button>
</PendingConfirmations>
`);
assert.notOk(confirmation.done, 'Confirmation is not done');
await click('button');
assert.ok(confirmation.done, 'Confirmation is done');
});
2020-11-16 15:08:59 -05:00
test('it exposes a dismiss action that dismisses the confirmation', async function (assert) {
2020-10-14 09:33:44 -04:00
assert.expect(3);
const service = this.owner.lookup('service:confirm');
service.enabled = true;
const confirmation = service.confirm();
confirmation.catch(() => assert.ok(true, 'confirmation.catch was called'));
await render(hbs`
<PendingConfirmations as |confirmations confirm dismiss|>
<button {{on "click" dismiss}}>Dismiss</button>
</PendingConfirmations>
`);
assert.notOk(confirmation.done, 'Confirmation is not done');
await click('button');
assert.ok(confirmation.done, 'Confirmation is done');
});
});