feat: 🎸 apply confirmation modal to deletes
This commit is contained in:
9 files changed
+314
-30
No files matched your search
@@ -4,6 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import { resolve, reject } from 'rsvp';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
@@ -146,22 +147,22 @@ module('Acceptance | projects', function (hooks) {
|
||||
assert.expect(2);
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
window.confirm = sinon.fake.returns(true);
|
||||
confirmService.confirm = sinon.fake.returns(resolve());
|
||||
await visit(existingProjectURL);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.equal(getProjectScopesCount(), initialProjectScopesCount - 1);
|
||||
assert.ok(window.confirm.calledOnce);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
|
||||
test('cannot delete project with confirmation denial', async function (assert) {
|
||||
assert.expect(2);
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
window.confirm = sinon.fake.returns(false);
|
||||
confirmService.confirm = sinon.fake.returns(reject());
|
||||
await visit(existingProjectURL);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.equal(getProjectScopesCount(), initialProjectScopesCount);
|
||||
assert.ok(window.confirm.calledOnce);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
|
||||
test('saving an existing project with invalid fields displays error messages', async function (assert) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render, findAll, click } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
|
||||
module('Integration | Component | pending-confirmations', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders pending confirmations', async function(assert) {
|
||||
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.equal(findAll('.pending').length, 0, 'No pending confirmations');
|
||||
service.confirm();
|
||||
await render(hbs`
|
||||
<PendingConfirmations as |confirmations|>
|
||||
<div class="pending">Pending</div>
|
||||
</PendingConfirmations>
|
||||
`);
|
||||
assert.equal(findAll('.pending').length, 1, 'One pending confirmations');
|
||||
});
|
||||
|
||||
test('it exposes a confirm action that confirms the confirmation', async function(assert) {
|
||||
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');
|
||||
});
|
||||
|
||||
test('it exposes a dismiss action that dismisses the confirmation', async function(assert) {
|
||||
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');
|
||||
});
|
||||
});
|
||||
@@ -4,9 +4,68 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Service | confirm', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let service = this.owner.lookup('service:confirm');
|
||||
assert.ok(service);
|
||||
test('`confirm()` emits promise-like instances', function(assert) {
|
||||
assert.expect(3);
|
||||
const service = this.owner.lookup('service:confirm');
|
||||
service.enabled = true;
|
||||
const confirmation = service.confirm();
|
||||
assert.ok(confirmation.then, 'confirmation has a then method');
|
||||
assert.ok(confirmation.catch, 'confirmation has a catch method');
|
||||
assert.ok(confirmation.finally, 'confirmation has a finally method');
|
||||
});
|
||||
|
||||
test('`pending` is an array of pending confirmations', function(assert) {
|
||||
assert.expect(3);
|
||||
const service = this.owner.lookup('service:confirm');
|
||||
service.enabled = true;
|
||||
assert.equal(service.pending.length, 0, 'No pending confirmations yet');
|
||||
const confirmation = service.confirm();
|
||||
assert.equal(service.pending.length, 1, 'One pending confirmation created');
|
||||
confirmation.confirm();
|
||||
assert.equal(service.pending.length, 0, 'Confirmation was confirmed');
|
||||
});
|
||||
|
||||
test('confirmations may be confirmed or dismissed', function(assert) {
|
||||
assert.expect(4);
|
||||
const service = this.owner.lookup('service:confirm');
|
||||
service.enabled = true;
|
||||
let confirmation = service.confirm();
|
||||
assert.notOk(confirmation.done, 'Confirmation is pending');
|
||||
confirmation.confirm();
|
||||
assert.ok(confirmation.done, 'Confirmation is done via confirm');
|
||||
confirmation = service.confirm();
|
||||
assert.notOk(confirmation.done, 'Confirmation is pending');
|
||||
confirmation.dismiss();
|
||||
assert.ok(confirmation.done, 'Confirmation is done via dismiss');
|
||||
});
|
||||
|
||||
test('confirmations resolve on confirm', function(assert) {
|
||||
assert.expect(1);
|
||||
const service = this.owner.lookup('service:confirm');
|
||||
service.enabled = true;
|
||||
const confirmation = service.confirm();
|
||||
confirmation.then(() => assert.ok(true, 'Confirmation confirmed'));
|
||||
confirmation.confirm();
|
||||
});
|
||||
|
||||
test('confirmations reject on dismiss', function(assert) {
|
||||
assert.expect(1);
|
||||
const service = this.owner.lookup('service:confirm');
|
||||
service.enabled = true;
|
||||
const confirmation = service.confirm();
|
||||
confirmation.catch(() => assert.ok(true, 'Confirmation dismissed'));
|
||||
confirmation.dismiss();
|
||||
});
|
||||
|
||||
test('confirmations have a finally method', function(assert) {
|
||||
assert.expect(2);
|
||||
const service = this.owner.lookup('service:confirm');
|
||||
service.enabled = true;
|
||||
let confirmation = service.confirm();
|
||||
confirmation.finally(() => assert.ok(true, 'Confirmation finally called'));
|
||||
confirmation.confirm();
|
||||
confirmation = service.confirm();
|
||||
confirmation.finally(() => assert.ok(true, 'Confirmation finally called'));
|
||||
confirmation.dismiss();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user