Skip to content

Commit

Permalink
feat: resolve suggestion into PR
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpereznext authored and josex2r committed Dec 21, 2021
1 parent 998b8ca commit 0f66af4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,6 @@ export default class Controller extends Controller {
### Other useful things
If you need to wait until modal is removed from DOM:
```javascript
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class Controller extends Controller {
// Inject the service
@service modal;

@action
async doSomething() {
await this.modal.open('foo', { bar: 'bar' });

this.modal.one('close', ({ name }) => {
if (name === 'foo') {
// Do something...
}
});
}
```
You can close all modals by using the `close` method.
```javascript
Expand Down
40 changes: 22 additions & 18 deletions tests/integration/services/modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import RSVP from 'rsvp';
import { waitUntil } from '@ember/test-helpers';
import ModalComponent from 'ember-modal-service/components/modal';
import { render } from '@ember/test-helpers';
import cases from 'qunit-parameterize';

let service, scheduler;
const ANIMATION_DELAY = 300;
Expand Down Expand Up @@ -230,10 +231,10 @@ module('Integration | Service | modal', (hooks) => {
assert.equal($element.length, 0, 'Modal is removed from DOM');
});

test('it triggers events when a modal is open/closed', async(assert) => {
assert.expect(6);
test('it triggers event when a modal is open', async(assert) => {
assert.expect(2);

let $element;
const done = assert.async();

service.one('open', (modal) => {
assert.ok(1, 'modal is open');
Expand All @@ -242,32 +243,35 @@ module('Integration | Service | modal', (hooks) => {
'foo',
'modal exists as first argument'
);

done();
});

run(async() => {
const foo = await service.open('foo');

assert.equal(foo, 'foo');
await service.open('foo');
});
});

await waitForScheduler();

$element = find('[data-id="modalFoo"][data-modal-show="true"]');
cases([
{ title: 'resolve' },
{ title: 'reject' }
]).test('it fulfills promise modal is removed from DOM ', async({ title }, assert) => {
assert.expect(1);

assert.equal($element.length, 1, 'Modal is displayed');
run(async() => {
try {
await service.open('foo');
} catch {
// Noop
}
});

await waitForTimeout(ANIMATION_DELAY);

run(service.get('content.0'), 'resolve', 'foo');

$element = find('[data-id="modalFoo"]:not([data-modal-show="true"])');

assert.equal($element.length, 1, 'Modal is hidden');
run(service.get('content.0'), title, 'foo');

await waitForTimeout(ANIMATION_DELAY);

$element = find('[data-id="modalFoo"]');

assert.equal($element.length, 0, 'Modal is removed from DOM');
assert.dom('[data-id="modalFoo"]').doesNotExist();
});
});

0 comments on commit 0f66af4

Please sign in to comment.